nix-helpers: da7f7e7fd03f0a1fdcb188e3a572119100bc144b

     1: { fail, replace, runCommand }:
     2: 
     3: with builtins;
     4: with {
     5:   test = { args, name, pre, post }:
     6:     runCommand "replace-test-${name}" { buildInputs = [ replace fail ]; } ''
     7:       ${pre}replace ${concatStringsSep " " args}${post}
     8:       mkdir "$out"
     9:     '';
    10: }; {
    11:   die-odd-args = test {
    12:     name = "die-old-args";
    13:     args = [ "old1" "new1" "unpaired" ];
    14:     pre = "echo 'hello' | ";
    15:     post = " && fail 'Should have died on odd args'";
    16:   };
    17:   replace-single-inplace = test {
    18:     name = "single-stdin";
    19:     args = [ "old" "new" "--" "f" ];
    20:     pre = ''
    21:       echo "embolden" > f
    22: 
    23:     '';
    24:     post = ''
    25: 
    26:       X=$(cat f)
    27:       [[ "x$X" = "xembnewen" ]] || fail "Didn't replace, got:$X"
    28:     '';
    29:   };
    30:   replace-two-stdin = test {
    31:     name = "two-stdin";
    32:     args = [ "foo" "bar" "baz" "quux" ];
    33:     pre = ''
    34:       X=$(echo -e 'fools are barred
    35:       from bazinga' | '';
    36:     post = ''
    37:       )
    38:       Y=$(echo -e 'barls are barred\nfrom quuxinga')
    39:       [[ "x$X" = "x$Y" ]] || fail "No match:\n$X\n\n$Y"
    40:     '';
    41:   };
    42: }

Generated by git2html.