fix(3p/nix): Fix parseDrvPathWithOutputs

At some point the behavior of this function got changed as part of our
cleanup - this fixes it to behave the way the rest of the codebase
expects (and how it is documented in the header) and covers it with a
few tests.

Change-Id: Id4c91232968e73489cd866fb4a2a84bcf20d875e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1629
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
Griffin Smith 2020-08-03 19:09:20 -04:00 committed by glittershark
parent 661353f200
commit 31b9578ad0
2 changed files with 33 additions and 3 deletions

View file

@ -103,4 +103,34 @@ RC_GTEST_FIXTURE_PROP(DerivationsTest, UnparseParseRoundTrip,
AssertDerivationsEqual(drv, parsed);
}
class ParseDrvPathWithOutputsTest : public DerivationsTest {};
TEST(ParseDrvPathWithOutputsTest, ParseDrvPathWithOutputs) {
auto input = "/nix/store/my51f75kp056md84gq2v08pd140pcz57-test.drv!out";
auto result = nix::parseDrvPathWithOutputs(input);
ASSERT_EQ(result.first,
"/nix/store/my51f75kp056md84gq2v08pd140pcz57-test.drv");
ASSERT_EQ(result.second, nix::PathSet{"out"});
}
TEST(ParseDrvPathWithOutputsTest, ParseDrvPathWithMultipleOutputs) {
auto input = "/nix/store/my51f75kp056md84gq2v08pd140pcz57-test.drv!out,dev";
auto result = nix::parseDrvPathWithOutputs(input);
nix::PathSet expected = {"out", "dev"};
ASSERT_EQ(result.first,
"/nix/store/my51f75kp056md84gq2v08pd140pcz57-test.drv");
ASSERT_EQ(result.second, expected);
}
TEST(ParseDrvPathWithOutputsTest, ParseDrvPathWithNoOutputs) {
auto input = "/nix/store/my51f75kp056md84gq2v08pd140pcz57-test";
auto result = nix::parseDrvPathWithOutputs(input);
ASSERT_EQ(result.first, "/nix/store/my51f75kp056md84gq2v08pd140pcz57-test");
ASSERT_EQ(result.second, nix::PathSet());
}
} // namespace nix