2017-03-18 22:41:02 +03:00
|
|
|
# to run these tests:
|
2017-04-25 03:12:43 +03:00
|
|
|
# nix-instantiate --eval --strict nixpkgs/lib/tests/misc.nix
|
2017-03-18 22:41:02 +03:00
|
|
|
# if the resulting list is empty, all tests passed
|
2017-04-25 03:12:43 +03:00
|
|
|
with import ../default.nix;
|
2009-03-07 02:21:17 +03:00
|
|
|
|
2020-01-28 01:03:38 +03:00
|
|
|
let
|
|
|
|
|
|
|
|
testSanitizeDerivationName = { name, expected }:
|
|
|
|
let
|
|
|
|
drv = derivation {
|
|
|
|
name = strings.sanitizeDerivationName name;
|
|
|
|
builder = "x";
|
|
|
|
system = "x";
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
# Evaluate the derivation so an invalid name would be caught
|
|
|
|
expr = builtins.seq drv.drvPath drv.name;
|
|
|
|
inherit expected;
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
2009-03-31 17:03:50 +04:00
|
|
|
runTests {
|
2009-03-07 02:21:17 +03:00
|
|
|
|
2017-04-12 01:43:52 +03:00
|
|
|
|
|
|
|
# TRIVIAL
|
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testId = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = id 1;
|
|
|
|
expected = 1;
|
|
|
|
};
|
2015-11-24 12:00:44 +03:00
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testConst = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = const 2 3;
|
|
|
|
expected = 2;
|
|
|
|
};
|
2012-05-13 23:10:57 +04:00
|
|
|
|
2019-10-18 18:57:33 +03:00
|
|
|
testPipe = {
|
|
|
|
expr = pipe 2 [
|
|
|
|
(x: x + 2) # 2 + 2 = 4
|
|
|
|
(x: x * 2) # 4 * 2 = 8
|
|
|
|
];
|
|
|
|
expected = 8;
|
|
|
|
};
|
|
|
|
|
|
|
|
testPipeEmpty = {
|
|
|
|
expr = pipe 2 [];
|
|
|
|
expected = 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
testPipeStrings = {
|
|
|
|
expr = pipe [ 3 4 ] [
|
|
|
|
(map toString)
|
|
|
|
(map (s: s + "\n"))
|
|
|
|
concatStrings
|
|
|
|
];
|
|
|
|
expected = ''
|
|
|
|
3
|
|
|
|
4
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2012-05-13 23:10:57 +04:00
|
|
|
/*
|
2009-11-23 00:28:41 +03:00
|
|
|
testOr = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = or true false;
|
|
|
|
expected = true;
|
|
|
|
};
|
2012-05-13 23:10:57 +04:00
|
|
|
*/
|
2015-11-24 12:00:44 +03:00
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testAnd = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = and true false;
|
|
|
|
expected = false;
|
|
|
|
};
|
2015-11-24 12:00:44 +03:00
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testFix = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = fix (x: {a = if x ? a then "a" else "b";});
|
|
|
|
expected = {a = "a";};
|
|
|
|
};
|
|
|
|
|
2017-04-12 01:43:52 +03:00
|
|
|
testComposeExtensions = {
|
|
|
|
expr = let obj = makeExtensible (self: { foo = self.bar; });
|
|
|
|
f = self: super: { bar = false; baz = true; };
|
|
|
|
g = self: super: { bar = super.baz or false; };
|
|
|
|
f_o_g = composeExtensions f g;
|
|
|
|
composed = obj.extend f_o_g;
|
|
|
|
in composed.foo;
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
2018-06-10 22:25:48 +03:00
|
|
|
testBitAnd = {
|
|
|
|
expr = (bitAnd 3 10);
|
|
|
|
expected = 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
testBitOr = {
|
|
|
|
expr = (bitOr 3 10);
|
|
|
|
expected = 11;
|
|
|
|
};
|
|
|
|
|
|
|
|
testBitXor = {
|
|
|
|
expr = (bitXor 3 10);
|
|
|
|
expected = 9;
|
|
|
|
};
|
|
|
|
|
2020-07-20 14:14:19 +03:00
|
|
|
testToHexString = {
|
|
|
|
expr = toHexString 250;
|
2020-04-20 13:00:23 +03:00
|
|
|
expected = "FA";
|
|
|
|
};
|
|
|
|
|
2020-07-20 14:14:19 +03:00
|
|
|
testToBaseDigits = {
|
|
|
|
expr = toBaseDigits 2 6;
|
2020-04-20 13:00:23 +03:00
|
|
|
expected = [ 1 1 0 ];
|
|
|
|
};
|
|
|
|
|
2017-04-12 01:43:52 +03:00
|
|
|
# STRINGS
|
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testConcatMapStrings = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = concatMapStrings (x: x + ";") ["a" "b" "c"];
|
|
|
|
expected = "a;b;c;";
|
|
|
|
};
|
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testConcatStringsSep = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = concatStringsSep "," ["a" "b" "c"];
|
|
|
|
expected = "a,b,c";
|
|
|
|
};
|
|
|
|
|
2017-04-12 01:43:52 +03:00
|
|
|
testSplitStringsSimple = {
|
|
|
|
expr = strings.splitString "." "a.b.c.d";
|
|
|
|
expected = [ "a" "b" "c" "d" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitStringsEmpty = {
|
|
|
|
expr = strings.splitString "." "a..b";
|
|
|
|
expected = [ "a" "" "b" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitStringsOne = {
|
|
|
|
expr = strings.splitString ":" "a.b";
|
|
|
|
expected = [ "a.b" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitStringsNone = {
|
|
|
|
expr = strings.splitString "." "";
|
|
|
|
expected = [ "" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitStringsFirstEmpty = {
|
|
|
|
expr = strings.splitString "/" "/a/b/c";
|
|
|
|
expected = [ "" "a" "b" "c" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitStringsLastEmpty = {
|
|
|
|
expr = strings.splitString ":" "2001:db8:0:0042::8a2e:370:";
|
|
|
|
expected = [ "2001" "db8" "0" "0042" "" "8a2e" "370" "" ];
|
|
|
|
};
|
2019-09-24 12:27:14 +03:00
|
|
|
|
|
|
|
testSplitVersionSingle = {
|
|
|
|
expr = versions.splitVersion "1";
|
|
|
|
expected = [ "1" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitVersionDouble = {
|
|
|
|
expr = versions.splitVersion "1.2";
|
|
|
|
expected = [ "1" "2" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitVersionTriple = {
|
|
|
|
expr = versions.splitVersion "1.2.3";
|
|
|
|
expected = [ "1" "2" "3" ];
|
|
|
|
};
|
2017-04-12 01:43:52 +03:00
|
|
|
|
2017-05-30 22:48:32 +03:00
|
|
|
testIsStorePath = {
|
|
|
|
expr =
|
|
|
|
let goodPath =
|
2017-06-10 00:30:10 +03:00
|
|
|
"${builtins.storeDir}/d945ibfx9x185xf04b890y4f9g3cbb63-python-2.7.11";
|
2017-05-30 22:48:32 +03:00
|
|
|
in {
|
|
|
|
storePath = isStorePath goodPath;
|
2020-02-10 18:20:41 +03:00
|
|
|
storePathDerivation = isStorePath (import ../.. { system = "x86_64-linux"; }).hello;
|
2017-05-30 22:48:32 +03:00
|
|
|
storePathAppendix = isStorePath
|
|
|
|
"${goodPath}/bin/python";
|
|
|
|
nonAbsolute = isStorePath (concatStrings (tail (stringToCharacters goodPath)));
|
2018-10-20 14:23:58 +03:00
|
|
|
asPath = isStorePath (/. + goodPath);
|
2017-05-30 22:48:32 +03:00
|
|
|
otherPath = isStorePath "/something/else";
|
|
|
|
otherVals = {
|
|
|
|
attrset = isStorePath {};
|
|
|
|
list = isStorePath [];
|
|
|
|
int = isStorePath 42;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
storePath = true;
|
2018-03-10 01:21:12 +03:00
|
|
|
storePathDerivation = true;
|
2017-05-30 22:48:32 +03:00
|
|
|
storePathAppendix = false;
|
|
|
|
nonAbsolute = false;
|
|
|
|
asPath = true;
|
|
|
|
otherPath = false;
|
|
|
|
otherVals = {
|
|
|
|
attrset = false;
|
|
|
|
list = false;
|
|
|
|
int = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-04-12 01:43:52 +03:00
|
|
|
# LISTS
|
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testFilter = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = filter (x: x != "a") ["a" "b" "c" "a"];
|
|
|
|
expected = ["b" "c"];
|
|
|
|
};
|
|
|
|
|
2017-03-18 22:41:02 +03:00
|
|
|
testFold =
|
|
|
|
let
|
|
|
|
f = op: fold: fold op 0 (range 0 100);
|
|
|
|
# fold with associative operator
|
|
|
|
assoc = f builtins.add;
|
|
|
|
# fold with non-associative operator
|
|
|
|
nonAssoc = f builtins.sub;
|
|
|
|
in {
|
|
|
|
expr = {
|
|
|
|
assocRight = assoc foldr;
|
|
|
|
# right fold with assoc operator is same as left fold
|
|
|
|
assocRightIsLeft = assoc foldr == assoc foldl;
|
|
|
|
nonAssocRight = nonAssoc foldr;
|
|
|
|
nonAssocLeft = nonAssoc foldl;
|
|
|
|
# with non-assoc operator the fold results are not the same
|
|
|
|
nonAssocRightIsNotLeft = nonAssoc foldl != nonAssoc foldr;
|
|
|
|
# fold is an alias for foldr
|
|
|
|
foldIsRight = nonAssoc fold == nonAssoc foldr;
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
assocRight = 5050;
|
|
|
|
assocRightIsLeft = true;
|
|
|
|
nonAssocRight = 50;
|
|
|
|
nonAssocLeft = (-5050);
|
|
|
|
nonAssocRightIsNotLeft = true;
|
|
|
|
foldIsRight = true;
|
|
|
|
};
|
|
|
|
};
|
2009-03-31 17:03:50 +04:00
|
|
|
|
2009-12-09 00:47:14 +03:00
|
|
|
testTake = testAllTrue [
|
|
|
|
([] == (take 0 [ 1 2 3 ]))
|
|
|
|
([1] == (take 1 [ 1 2 3 ]))
|
|
|
|
([ 1 2 ] == (take 2 [ 1 2 3 ]))
|
|
|
|
([ 1 2 3 ] == (take 3 [ 1 2 3 ]))
|
|
|
|
([ 1 2 3 ] == (take 4 [ 1 2 3 ]))
|
|
|
|
];
|
|
|
|
|
2012-08-28 16:40:24 +04:00
|
|
|
testFoldAttrs = {
|
|
|
|
expr = foldAttrs (n: a: [n] ++ a) [] [
|
|
|
|
{ a = 2; b = 7; }
|
|
|
|
{ a = 3; c = 8; }
|
|
|
|
];
|
|
|
|
expected = { a = [ 2 3 ]; b = [7]; c = [8];};
|
|
|
|
};
|
2009-12-09 00:47:14 +03:00
|
|
|
|
2012-11-20 16:54:38 +04:00
|
|
|
testSort = {
|
|
|
|
expr = sort builtins.lessThan [ 40 2 30 42 ];
|
|
|
|
expected = [2 30 40 42];
|
|
|
|
};
|
2015-11-24 12:00:44 +03:00
|
|
|
|
|
|
|
testToIntShouldConvertStringToInt = {
|
|
|
|
expr = toInt "27";
|
|
|
|
expected = 27;
|
|
|
|
};
|
|
|
|
|
|
|
|
testToIntShouldThrowErrorIfItCouldNotConvertToInt = {
|
|
|
|
expr = builtins.tryEval (toInt "\"foo\"");
|
|
|
|
expected = { success = false; value = false; };
|
|
|
|
};
|
|
|
|
|
2015-12-04 18:17:45 +03:00
|
|
|
testHasAttrByPathTrue = {
|
|
|
|
expr = hasAttrByPath ["a" "b"] { a = { b = "yey"; }; };
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testHasAttrByPathFalse = {
|
|
|
|
expr = hasAttrByPath ["a" "b"] { a = { c = "yey"; }; };
|
|
|
|
expected = false;
|
|
|
|
};
|
|
|
|
|
2016-11-06 03:51:13 +03:00
|
|
|
|
2018-08-15 01:13:32 +03:00
|
|
|
# ATTRSETS
|
|
|
|
|
|
|
|
# code from the example
|
|
|
|
testRecursiveUpdateUntil = {
|
|
|
|
expr = recursiveUpdateUntil (path: l: r: path == ["foo"]) {
|
|
|
|
# first attribute set
|
|
|
|
foo.bar = 1;
|
|
|
|
foo.baz = 2;
|
|
|
|
bar = 3;
|
|
|
|
} {
|
|
|
|
#second attribute set
|
|
|
|
foo.bar = 1;
|
|
|
|
foo.quz = 2;
|
|
|
|
baz = 4;
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
foo.bar = 1; # 'foo.*' from the second set
|
|
|
|
foo.quz = 2; #
|
|
|
|
bar = 3; # 'bar' from the first set
|
|
|
|
baz = 4; # 'baz' from the second set
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-09-17 23:40:08 +03:00
|
|
|
testOverrideExistingEmpty = {
|
|
|
|
expr = overrideExisting {} { a = 1; };
|
|
|
|
expected = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
testOverrideExistingDisjoint = {
|
|
|
|
expr = overrideExisting { b = 2; } { a = 1; };
|
|
|
|
expected = { b = 2; };
|
|
|
|
};
|
|
|
|
|
|
|
|
testOverrideExistingOverride = {
|
|
|
|
expr = overrideExisting { a = 3; b = 2; } { a = 1; };
|
|
|
|
expected = { a = 1; b = 2; };
|
|
|
|
};
|
2018-08-15 01:13:32 +03:00
|
|
|
|
2017-04-12 01:43:52 +03:00
|
|
|
# GENERATORS
|
|
|
|
# these tests assume attributes are converted to lists
|
|
|
|
# in alphabetical order
|
2016-11-06 03:51:13 +03:00
|
|
|
|
2016-12-07 01:19:34 +03:00
|
|
|
testMkKeyValueDefault = {
|
2017-11-09 17:58:14 +03:00
|
|
|
expr = generators.mkKeyValueDefault {} ":" "f:oo" "bar";
|
2016-12-05 00:11:24 +03:00
|
|
|
expected = ''f\:oo:bar'';
|
|
|
|
};
|
|
|
|
|
2018-03-26 18:31:05 +03:00
|
|
|
testMkValueString = {
|
|
|
|
expr = let
|
|
|
|
vals = {
|
|
|
|
int = 42;
|
|
|
|
string = ''fo"o'';
|
|
|
|
bool = true;
|
|
|
|
bool2 = false;
|
|
|
|
null = null;
|
|
|
|
# float = 42.23; # floats are strange
|
|
|
|
};
|
|
|
|
in mapAttrs
|
|
|
|
(const (generators.mkValueStringDefault {}))
|
|
|
|
vals;
|
|
|
|
expected = {
|
|
|
|
int = "42";
|
|
|
|
string = ''fo"o'';
|
|
|
|
bool = "true";
|
|
|
|
bool2 = "false";
|
|
|
|
null = "null";
|
|
|
|
# float = "42.23" true false [ "bar" ] ]'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-12-05 00:11:24 +03:00
|
|
|
testToKeyValue = {
|
|
|
|
expr = generators.toKeyValue {} {
|
|
|
|
key = "value";
|
|
|
|
"other=key" = "baz";
|
|
|
|
};
|
|
|
|
expected = ''
|
|
|
|
key=value
|
|
|
|
other\=key=baz
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-11-06 03:51:13 +03:00
|
|
|
testToINIEmpty = {
|
|
|
|
expr = generators.toINI {} {};
|
|
|
|
expected = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
testToINIEmptySection = {
|
|
|
|
expr = generators.toINI {} { foo = {}; bar = {}; };
|
|
|
|
expected = ''
|
|
|
|
[bar]
|
|
|
|
|
|
|
|
[foo]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-03-10 04:38:28 +03:00
|
|
|
testToINIDuplicateKeys = {
|
|
|
|
expr = generators.toINI { listsAsDuplicateKeys = true; } { foo.bar = true; baz.qux = [ 1 false ]; };
|
|
|
|
expected = ''
|
|
|
|
[baz]
|
|
|
|
qux=1
|
|
|
|
qux=false
|
|
|
|
|
|
|
|
[foo]
|
|
|
|
bar=true
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-11-06 03:51:13 +03:00
|
|
|
testToINIDefaultEscapes = {
|
|
|
|
expr = generators.toINI {} {
|
|
|
|
"no [ and ] allowed unescaped" = {
|
|
|
|
"and also no = in keys" = 42;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
expected = ''
|
|
|
|
[no \[ and \] allowed unescaped]
|
|
|
|
and also no \= in keys=42
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
testToINIDefaultFull = {
|
|
|
|
expr = generators.toINI {} {
|
|
|
|
"section 1" = {
|
|
|
|
attribute1 = 5;
|
|
|
|
x = "Me-se JarJar Binx";
|
2018-03-26 18:31:05 +03:00
|
|
|
# booleans are converted verbatim by default
|
|
|
|
boolean = false;
|
2016-11-06 03:51:13 +03:00
|
|
|
};
|
|
|
|
"foo[]" = {
|
|
|
|
"he\\h=he" = "this is okay";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
expected = ''
|
|
|
|
[foo\[\]]
|
|
|
|
he\h\=he=this is okay
|
|
|
|
|
|
|
|
[section 1]
|
|
|
|
attribute1=5
|
2018-03-26 18:31:05 +03:00
|
|
|
boolean=false
|
2016-11-06 03:51:13 +03:00
|
|
|
x=Me-se JarJar Binx
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-11-06 16:14:24 +03:00
|
|
|
/* right now only invocation check */
|
|
|
|
testToJSONSimple =
|
|
|
|
let val = {
|
|
|
|
foobar = [ "baz" 1 2 3 ];
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
expr = generators.toJSON {} val;
|
2017-04-19 22:41:28 +03:00
|
|
|
# trivial implementation
|
2016-11-06 16:14:24 +03:00
|
|
|
expected = builtins.toJSON val;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* right now only invocation check */
|
|
|
|
testToYAMLSimple =
|
|
|
|
let val = {
|
|
|
|
list = [ { one = 1; } { two = 2; } ];
|
|
|
|
all = 42;
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
expr = generators.toYAML {} val;
|
2017-04-19 22:41:28 +03:00
|
|
|
# trivial implementation
|
2016-11-06 16:14:24 +03:00
|
|
|
expected = builtins.toJSON val;
|
|
|
|
};
|
|
|
|
|
2017-06-06 23:41:22 +03:00
|
|
|
testToPretty = {
|
|
|
|
expr = mapAttrs (const (generators.toPretty {})) rec {
|
|
|
|
int = 42;
|
2018-10-13 20:55:00 +03:00
|
|
|
float = 0.1337;
|
2017-06-06 23:41:22 +03:00
|
|
|
bool = true;
|
2018-04-25 16:04:30 +03:00
|
|
|
string = ''fno"rd'';
|
2018-05-22 23:42:02 +03:00
|
|
|
path = /. + "/foo";
|
2017-06-06 23:41:22 +03:00
|
|
|
null_ = null;
|
|
|
|
function = x: x;
|
2017-06-12 08:07:59 +03:00
|
|
|
functionArgs = { arg ? 4, foo }: arg;
|
2017-06-06 23:41:22 +03:00
|
|
|
list = [ 3 4 function [ false ] ];
|
|
|
|
attrs = { foo = null; "foo bar" = "baz"; };
|
|
|
|
drv = derivation { name = "test"; system = builtins.currentSystem; };
|
|
|
|
};
|
|
|
|
expected = rec {
|
|
|
|
int = "42";
|
2018-10-13 20:55:00 +03:00
|
|
|
float = "~0.133700";
|
2017-06-06 23:41:22 +03:00
|
|
|
bool = "true";
|
2018-04-25 16:04:30 +03:00
|
|
|
string = ''"fno\"rd"'';
|
|
|
|
path = "/foo";
|
2017-06-06 23:41:22 +03:00
|
|
|
null_ = "null";
|
|
|
|
function = "<λ>";
|
2017-06-12 08:07:59 +03:00
|
|
|
functionArgs = "<λ:{(arg),foo}>";
|
2017-06-06 23:41:22 +03:00
|
|
|
list = "[ 3 4 ${function} [ false ] ]";
|
|
|
|
attrs = "{ \"foo\" = null; \"foo bar\" = \"baz\"; }";
|
2018-04-25 16:04:30 +03:00
|
|
|
drv = "<δ:test>";
|
2017-06-06 23:41:22 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testToPrettyAllowPrettyValues = {
|
|
|
|
expr = generators.toPretty { allowPrettyValues = true; }
|
|
|
|
{ __pretty = v: "«" + v + "»"; val = "foo"; };
|
|
|
|
expected = "«foo»";
|
|
|
|
};
|
|
|
|
|
2020-01-23 01:24:06 +03:00
|
|
|
|
|
|
|
# CLI
|
|
|
|
|
|
|
|
testToGNUCommandLine = {
|
2020-01-23 01:37:10 +03:00
|
|
|
expr = cli.toGNUCommandLine {} {
|
|
|
|
data = builtins.toJSON { id = 0; };
|
|
|
|
X = "PUT";
|
|
|
|
retry = 3;
|
|
|
|
retry-delay = null;
|
|
|
|
url = [ "https://example.com/foo" "https://example.com/bar" ];
|
|
|
|
silent = false;
|
|
|
|
verbose = true;
|
|
|
|
};
|
2020-01-23 01:24:06 +03:00
|
|
|
|
2020-01-23 01:37:10 +03:00
|
|
|
expected = [
|
|
|
|
"-X" "PUT"
|
|
|
|
"--data" "{\"id\":0}"
|
|
|
|
"--retry" "3"
|
|
|
|
"--url" "https://example.com/foo"
|
|
|
|
"--url" "https://example.com/bar"
|
|
|
|
"--verbose"
|
|
|
|
];
|
2020-01-23 01:24:06 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
testToGNUCommandLineShell = {
|
2020-01-23 01:37:10 +03:00
|
|
|
expr = cli.toGNUCommandLineShell {} {
|
|
|
|
data = builtins.toJSON { id = 0; };
|
|
|
|
X = "PUT";
|
|
|
|
retry = 3;
|
|
|
|
retry-delay = null;
|
|
|
|
url = [ "https://example.com/foo" "https://example.com/bar" ];
|
|
|
|
silent = false;
|
|
|
|
verbose = true;
|
|
|
|
};
|
2019-12-12 03:30:05 +03:00
|
|
|
|
2020-01-06 00:03:00 +03:00
|
|
|
expected = "'-X' 'PUT' '--data' '{\"id\":0}' '--retry' '3' '--url' 'https://example.com/foo' '--url' 'https://example.com/bar' '--verbose'";
|
2019-12-12 03:30:05 +03:00
|
|
|
};
|
2020-01-28 01:03:38 +03:00
|
|
|
|
|
|
|
testSanitizeDerivationNameLeadingDots = testSanitizeDerivationName {
|
|
|
|
name = "..foo";
|
|
|
|
expected = "foo";
|
|
|
|
};
|
|
|
|
|
|
|
|
testSanitizeDerivationNameAscii = testSanitizeDerivationName {
|
|
|
|
name = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
|
|
|
|
expected = "-+--.-0123456789-=-?-ABCDEFGHIJKLMNOPQRSTUVWXYZ-_-abcdefghijklmnopqrstuvwxyz-";
|
|
|
|
};
|
|
|
|
|
|
|
|
testSanitizeDerivationNameTooLong = testSanitizeDerivationName {
|
|
|
|
name = "This string is loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong";
|
|
|
|
expected = "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong";
|
|
|
|
};
|
|
|
|
|
|
|
|
testSanitizeDerivationNameTooLongWithInvalid = testSanitizeDerivationName {
|
|
|
|
name = "Hello there aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&&&&&&&";
|
|
|
|
expected = "there-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-";
|
|
|
|
};
|
|
|
|
|
|
|
|
testSanitizeDerivationNameEmpty = testSanitizeDerivationName {
|
|
|
|
name = "";
|
|
|
|
expected = "unknown";
|
|
|
|
};
|
2009-03-31 17:03:50 +04:00
|
|
|
}
|