mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 23:13:19 +00:00
npiet: add package tests
This commit is contained in:
parent
909bf79413
commit
15fe3c9320
@ -7,6 +7,7 @@
|
||||
groff,
|
||||
libpng,
|
||||
tk,
|
||||
callPackage,
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation (finalAttrs: {
|
||||
@ -38,6 +39,19 @@ stdenv.mkDerivation (finalAttrs: {
|
||||
|
||||
strictDeps = true;
|
||||
|
||||
passthru.tests =
|
||||
let
|
||||
all-tests = callPackage ./tests { };
|
||||
in
|
||||
{
|
||||
inherit (all-tests)
|
||||
hello
|
||||
prime
|
||||
no-prime
|
||||
brainfuck
|
||||
;
|
||||
};
|
||||
|
||||
meta = {
|
||||
description = "Interpreter for piet programs. Also includes npietedit and npiet-foogol";
|
||||
longDescription = ''
|
||||
|
41
pkgs/by-name/np/npiet/tests/default.nix
Normal file
41
pkgs/by-name/np/npiet/tests/default.nix
Normal file
@ -0,0 +1,41 @@
|
||||
{ fetchurl, callPackage }:
|
||||
let
|
||||
# More examples can be found at https://www.dangermouse.net/esoteric/piet/samples.html
|
||||
hello-program = fetchurl {
|
||||
url = "https://www.dangermouse.net/esoteric/piet/hw6.png";
|
||||
hash = "sha256-E8OMu0b/oU8lDF3X4o5WMnnD1IKNT2YF+qe4MXLuczI=";
|
||||
};
|
||||
prime-tester-program = fetchurl {
|
||||
url = "https://www.bertnase.de/npiet/nprime.gif";
|
||||
hash = "sha256-4eaJweV/n73byoWZWCXiMLkfSEhMPf5itVwz48AK/FA=";
|
||||
};
|
||||
brainfuck-interpreter-program = fetchurl {
|
||||
url = "https://www.dangermouse.net/esoteric/piet/piet_bfi.gif";
|
||||
hash = "sha256-LIfOG0KFpr4nxAtLLeIsPQl+8Ujyvfz/YnEm/HRoVjY=";
|
||||
};
|
||||
in
|
||||
{
|
||||
hello = callPackage ./run-test.nix {
|
||||
testName = "hello";
|
||||
programPath = hello-program;
|
||||
expectedOutput = "Hello, world!";
|
||||
};
|
||||
prime = callPackage ./run-test.nix {
|
||||
testName = "prime";
|
||||
programPath = prime-tester-program;
|
||||
programInput = "2069";
|
||||
expectedOutput = "Y";
|
||||
};
|
||||
no-prime = callPackage ./run-test.nix {
|
||||
testName = "no-prime";
|
||||
programPath = prime-tester-program;
|
||||
programInput = "2070";
|
||||
expectedOutput = "N";
|
||||
};
|
||||
brainfuck = callPackage ./run-test.nix {
|
||||
testName = "brainfuck";
|
||||
programPath = brainfuck-interpreter-program;
|
||||
programInput = ",+>,+>,+>,+.<.<.<.|sdhO";
|
||||
expectedOutput = "Piet";
|
||||
};
|
||||
}
|
19
pkgs/by-name/np/npiet/tests/run-test.nix
Normal file
19
pkgs/by-name/np/npiet/tests/run-test.nix
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
runCommand,
|
||||
lib,
|
||||
npiet,
|
||||
|
||||
testName,
|
||||
programPath,
|
||||
programInput ? "",
|
||||
expectedOutput,
|
||||
}:
|
||||
runCommand "npiet-test-${testName}" { } ''
|
||||
actual_output="$(echo '${programInput}' | '${lib.getExe npiet}' -q -w -e 100000 '${programPath}')"
|
||||
if [ "$actual_output" != '${expectedOutput}' ]; then
|
||||
echo "npiet failed to run the program correctly. The output should be ${expectedOutput} but is $actual_output."
|
||||
exit 1
|
||||
fi
|
||||
echo "The program successfully output $actual_output"
|
||||
touch "$out"
|
||||
''
|
Loading…
Reference in New Issue
Block a user