Skip to content

Commit 1121ddf

Browse files
committed
Expand libexpr tests
The test failure is suspicious!
1 parent 088c184 commit 1121ddf

5 files changed

Lines changed: 59 additions & 45 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Derive([("dev","/nix/store/qa4x1j13bs80hnambfs4jymzs1d9qph2-hello-dev","",""),("out","/nix/store/yb2qjkr036x3p7c78bfwc911ll4qxznv-hello","","")],[],[],"my-system","/bin/bash",["-c","echo hello > $out"],[("__json","{\"builder\":\"/bin/bash\",\"name\":\"hello\",\"outputs\":[\"out\",\"dev\"],\"system\":\"my-system\"}"),("dev","/nix/store/qa4x1j13bs80hnambfs4jymzs1d9qph2-hello-dev"),("out","/nix/store/yb2qjkr036x3p7c78bfwc911ll4qxznv-hello")])
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
derivation {
2+
name = "hello";
3+
system = "my-system";
4+
builder = "/bin/bash";
5+
args = [ "-c" "echo hello > $out" ];
6+
outputs = [ "out" "dev" ];
7+
__structuredAttrs = true;
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Derive([("bin","/nix/store/7vm54kg0cgpqgsxjfw237s8a0mx6hs10-hello-again-bin","",""),("dev","/nix/store/j296xiyy4d869fswncni5m2x3qgkxahl-hello-again-dev","",""),("out","/nix/store/apjy8vlc7kc9wfrswvk2dsply969xg0p-hello-again","","")],[("/nix/store/4xm4wccqsvagz9gjksn24s7rip2fdy7v-foo.drv",["out"]),("/nix/store/plsq5jbr5nhgqwcgb2qxw7jchc09dnl8-bar.drv",["out"])],[],"my-system","/bin/bash",["-c","echo hello > $out"],[("__json","{\"__darwinAllowLocalNetworking\":true,\"__impureHostDeps\":[\"/usr/bin/ditto\"],\"__noChroot\":true,\"__sandboxProfile\":\"sandcastle\",\"allowSubstitutes\":false,\"builder\":\"/bin/bash\",\"impureEnvVars\":[\"UNICORN\"],\"name\":\"hello-again\",\"outputChecks\":{\"bin\":{\"disallowedReferences\":[\"/nix/store/7rhsm8i393hm1wcsmph782awg1hi2f7x-bar\"],\"disallowedRequisites\":[\"/nix/store/7rhsm8i393hm1wcsmph782awg1hi2f7x-bar\"]},\"dev\":{\"maxClosureSize\":5909,\"maxSize\":789},\"out\":{\"allowedReferences\":[\"/nix/store/3c08bzb71z4wiag719ipjxr277653ynp-foo\"],\"allowedRequisites\":[\"/nix/store/3c08bzb71z4wiag719ipjxr277653ynp-foo\"]}},\"outputs\":[\"out\",\"bin\",\"dev\"],\"preferLocalBuild\":true,\"requiredSystemFeatures\":[\"rainbow\",\"uid-range\"],\"system\":\"my-system\"}"),("bin","/nix/store/7vm54kg0cgpqgsxjfw237s8a0mx6hs10-hello-again-bin"),("dev","/nix/store/j296xiyy4d869fswncni5m2x3qgkxahl-hello-again-dev"),("out","/nix/store/apjy8vlc7kc9wfrswvk2dsply969xg0p-hello-again")])

tests/unit/libexpr/data/derivation/advanced-attributes-structured-attrs.nix

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,28 @@ derivation {
1818
name = "hello-again";
1919
builder = "/bin/bash";
2020
args = [ "-c" "echo hello > $out" ];
21-
outputs = [ "out" "dev" ];
21+
__sandboxProfile = "sandcastle";
22+
__noChroot = true;
23+
__impureHostDeps = ["/usr/bin/ditto"];
24+
impureEnvVars = ["UNICORN"];
25+
__darwinAllowLocalNetworking = true;
26+
outputs = [ "out" "bin" "dev" ];
27+
__structuredAttrs = true;
2228
outputChecks = {
2329
out = {
24-
allowedReferences = [];
30+
allowedReferences = [foo];
31+
allowedRequisites = [foo];
32+
};
33+
bin = {
34+
disallowedReferences = [bar];
35+
disallowedRequisites = [bar];
36+
};
37+
dev = {
38+
maxSize = 789;
39+
maxClosureSize = 5909;
2540
};
2641
};
27-
# TODO add some others
42+
requiredSystemFeatures = ["rainbow" "uid-range"];
43+
preferLocalBuild = true;
44+
allowSubstitutes = false;
2845
}

tests/unit/libexpr/derivation.cc

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,34 @@ class DerivationTest : public CharacterizationTest, public LibExprTest
1717
}
1818
};
1919

20-
// TODO: Move this to macro
21-
TEST_F(DerivationTest, Derivation_advancedAttributes)
22-
{
23-
writeTest(
24-
"advanced-attributes.drv",
25-
[&]() -> std::string {
26-
Value v = eval(readFile(goldenMaster("advanced-attributes.nix")));
27-
Symbol s = state.symbols.create("drvPath");
28-
auto attr = v.attrs()->get(s);
29-
state.forceValueDeep(*attr->value);
30-
31-
auto path = std::string_view(attr->value->c_str());
32-
auto storePath = store->parseStorePath(path);
33-
34-
// TODO: Could probably also just use store->getFSAccessor()->...
35-
auto drv = store->readDerivation(storePath);
36-
return drv.unparse(*store, false);
37-
},
38-
[](const auto & file) { return readFile(file); },
39-
[](const auto & file, const auto & got) { return writeFile(file, got); });
40-
};
41-
42-
TEST_F(DerivationTest, Derivation_advancedAttributes_defaults)
43-
{
44-
writeTest(
45-
"advanced-attributes-defaults.drv",
46-
[&]() -> std::string {
47-
Value v = eval(readFile(goldenMaster("advanced-attributes-defaults.nix")));
48-
Symbol s = state.symbols.create("drvPath");
49-
auto attr = v.attrs()->get(s);
50-
state.forceValueDeep(*attr->value);
20+
#define EXPR_DRV_TEST(NAME, STEM) \
21+
TEST_F(DerivationTest, Derivation_##NAME) \
22+
{ \
23+
writeTest( \
24+
STEM ".drv", \
25+
[&]() -> Derivation { \
26+
Value v = eval(readFile(goldenMaster(STEM ".nix"))); \
27+
Symbol s = state.symbols.create("drvPath"); \
28+
auto attr = v.attrs() -> get(s); \
29+
state.forceValueDeep(*attr->value); \
30+
NixStringContext context; \
31+
auto storePath = state.coerceToStorePath(attr->pos, *attr->value, context, ""); \
32+
\
33+
return store->readDerivation(storePath); \
34+
}, \
35+
[&](const auto & file) { \
36+
auto s = readFile(file); \
37+
return parseDerivation(*store, std::move(s), STEM); \
38+
}, \
39+
[&](const auto & file, const auto & got) { \
40+
auto s = got.unparse(*store, false); \
41+
return writeFile(file, std::move(s)); \
42+
}); \
43+
}
5144

52-
auto path = std::string_view(attr->value->c_str());
53-
auto storePath = store->parseStorePath(path);
45+
EXPR_DRV_TEST(advancedAttributes, "advanced-attributes");
46+
EXPR_DRV_TEST(advancedAttributes_defaults, "advanced-attributes-defaults");
47+
EXPR_DRV_TEST(advancedAttributes_structuredAttrs, "advanced-attributes-structured-attrs");
48+
EXPR_DRV_TEST(advancedAttributes_structuredAttrs_defaults, "advanced-attributes-structured-attrs-defaults");
5449

55-
// TODO: Could probably also just use store->getFSAccessor()->...
56-
auto drv = store->readDerivation(storePath);
57-
return drv.unparse(*store, false);
58-
},
59-
[](const auto & file) { return readFile(file); },
60-
[](const auto & file, const auto & got) { return writeFile(file, got); });
61-
};
62-
63-
};
50+
}

0 commit comments

Comments
 (0)