writeCBin: Add meta.mainProgram
... and add tests.
This commit is contained in:
parent
86af7da8c4
commit
d1dc8384ca
@ -242,7 +242,11 @@ rec {
|
||||
|
||||
|
||||
*/
|
||||
writeScriptBin = name: text: writeTextFile {inherit name text; executable = true; destination = "/bin/${name}";};
|
||||
writeScriptBin = name: text: writeTextFile {
|
||||
inherit name text;
|
||||
executable = true;
|
||||
destination = "/bin/${name}";
|
||||
};
|
||||
|
||||
/*
|
||||
Similar to writeScript. Writes a Shell script and checks its syntax.
|
||||
@ -374,6 +378,9 @@ rec {
|
||||
# Pointless to do this on a remote machine.
|
||||
preferLocalBuild = true;
|
||||
allowSubstitutes = false;
|
||||
meta = {
|
||||
mainProgram = name;
|
||||
};
|
||||
}
|
||||
''
|
||||
n=$out/bin/$name
|
||||
|
43
pkgs/build-support/trivial-builders/test/writeCBin.nix
Normal file
43
pkgs/build-support/trivial-builders/test/writeCBin.nix
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
Run with:
|
||||
|
||||
cd nixpkgs
|
||||
nix-build -A tests.trivial-builders.writeCBin
|
||||
*/
|
||||
|
||||
{ lib, writeCBin, runCommand }:
|
||||
let
|
||||
output = "hello";
|
||||
pkg = writeCBin "test-script" ''
|
||||
#include <stdio.h>
|
||||
int main () {
|
||||
printf("hello\n");
|
||||
return 0;
|
||||
}
|
||||
'';
|
||||
in
|
||||
assert pkg.meta.mainProgram == "test-script";
|
||||
runCommand "test-writeCBin" { } ''
|
||||
|
||||
echo Testing with getExe...
|
||||
|
||||
target=${lib.getExe pkg}
|
||||
expected=${lib.escapeShellArg output}
|
||||
got=$("$target")
|
||||
if [[ "$got" != "$expected" ]]; then
|
||||
echo "wrong output: expected $expected, got $got"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo Testing with makeBinPath...
|
||||
|
||||
PATH="${lib.makeBinPath [ pkg ]}:$PATH"
|
||||
got=$(test-script)
|
||||
if [[ "$got" != "$expected" ]]; then
|
||||
echo "wrong output: expected $expected, got $got"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
touch $out
|
||||
''
|
||||
|
39
pkgs/build-support/trivial-builders/test/writeScriptBin.nix
Normal file
39
pkgs/build-support/trivial-builders/test/writeScriptBin.nix
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
Run with:
|
||||
|
||||
cd nixpkgs
|
||||
nix-build -A tests.trivial-builders.writeShellScriptBin
|
||||
*/
|
||||
|
||||
{ lib, writeScriptBin, runCommand }:
|
||||
let
|
||||
output = "hello";
|
||||
pkg = writeScriptBin "test-script" ''
|
||||
echo ${lib.escapeShellArg output}
|
||||
'';
|
||||
in
|
||||
assert pkg.meta.mainProgram == "test-script";
|
||||
runCommand "test-writeScriptBin" { } ''
|
||||
|
||||
echo Testing with getExe...
|
||||
|
||||
target=${lib.getExe pkg}
|
||||
expected=${lib.escapeShellArg output}
|
||||
got=$("$target")
|
||||
if [[ "$got" != "$expected" ]]; then
|
||||
echo "wrong output: expected $expected, got $got"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo Testing with makeBinPath...
|
||||
|
||||
PATH="${lib.makeBinPath [ pkg ]}:$PATH"
|
||||
got=$(test-script)
|
||||
if [[ "$got" != "$expected" ]]; then
|
||||
echo "wrong output: expected $expected, got $got"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
touch $out
|
||||
''
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
Run with:
|
||||
|
||||
cd nixpkgs
|
||||
nix-build -A tests.trivial-builders.writeShellScriptBin
|
||||
*/
|
||||
|
||||
{ lib, writeShellScriptBin, runCommand }:
|
||||
let
|
||||
output = "hello";
|
||||
pkg = writeShellScriptBin "test-script" ''
|
||||
echo ${lib.escapeShellArg output}
|
||||
'';
|
||||
in
|
||||
assert pkg.meta.mainProgram == "test-script";
|
||||
runCommand "test-writeShellScriptBin" { } ''
|
||||
|
||||
echo Testing with getExe...
|
||||
|
||||
target=${lib.getExe pkg}
|
||||
expected=${lib.escapeShellArg output}
|
||||
got=$("$target")
|
||||
if [[ "$got" != "$expected" ]]; then
|
||||
echo "wrong output: expected $expected, got $got"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo Testing with makeBinPath...
|
||||
|
||||
PATH="${lib.makeBinPath [ pkg ]}:$PATH"
|
||||
got=$(test-script)
|
||||
if [[ "$got" != "$expected" ]]; then
|
||||
echo "wrong output: expected $expected, got $got"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
touch $out
|
||||
''
|
||||
|
@ -67,9 +67,12 @@ with pkgs;
|
||||
cuda = callPackage ./cuda { };
|
||||
|
||||
trivial-builders = recurseIntoAttrs {
|
||||
writeCBin = callPackage ../build-support/trivial-builders/test/writeCBin.nix {};
|
||||
writeScriptBin = callPackage ../build-support/trivial-builders/test/writeScriptBin.nix {};
|
||||
writeStringReferencesToFile = callPackage ../build-support/trivial-builders/test/writeStringReferencesToFile.nix {};
|
||||
writeTextFile = callPackage ../build-support/trivial-builders/test/write-text-file.nix {};
|
||||
writeShellScript = callPackage ../build-support/trivial-builders/test/write-shell-script.nix {};
|
||||
writeShellScriptBin = callPackage ../build-support/trivial-builders/test/writeShellScriptBin.nix {};
|
||||
references = callPackage ../build-support/trivial-builders/test/references.nix {};
|
||||
overriding = callPackage ../build-support/trivial-builders/test-overriding.nix {};
|
||||
concat = callPackage ../build-support/trivial-builders/test/concat-test.nix {};
|
||||
|
Loading…
Reference in New Issue
Block a user