Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npiet: add tests, cleanup #333766

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions pkgs/by-name/np/npiet/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
lib,
stdenv,
fetchurl,
gd,
giflib,
groff,
libpng,
tk,
callPackage,
}:

stdenv.mkDerivation (finalAttrs: {
pname = "npiet";
version = "1.3f";

src = fetchurl {
url = "https://www.bertnase.de/npiet/npiet-${finalAttrs.version}.tar.gz";
hash = "sha256-Le2FYGKr1zWZ6F4edozmvGC6LbItx9aptidj3KBLhVo=";
};

buildInputs = [
gd
giflib
libpng
];

nativeBuildInputs = [ groff ];

postPatch = ''
# malloc.h is not needed because stdlib.h is already included.
# On macOS, malloc.h does not even exist, resulting in an error.
substituteInPlace npiet-foogol.c \
--replace-fail '#include <malloc.h>' ""

substituteInPlace npietedit \
--replace-fail 'exec wish' 'exec ${tk}/bin/wish'
'';

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 = ''
npiet is an interpreter for the piet programming language.
Instead of text, piet programs are pictures. Commands are determined based on changes in color.
'';
homepage = "https://www.bertnase.de/npiet/";
changelog = "https://www.bertnase.de/npiet/ChangeLog";
license = lib.licenses.gpl2Only;
platforms = lib.platforms.unix;
mainProgram = "npiet";
maintainers = with lib.maintainers; [ Luflosi ];
};
})
41 changes: 41 additions & 0 deletions pkgs/by-name/np/npiet/tests/default.nix
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions pkgs/by-name/np/npiet/tests/run-test.nix
Original file line number Diff line number Diff line change
@@ -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"
''
45 changes: 0 additions & 45 deletions pkgs/development/interpreters/npiet/default.nix

This file was deleted.

2 changes: 0 additions & 2 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10833,8 +10833,6 @@ with pkgs;

npapi_sdk = callPackage ../development/libraries/npapi-sdk { };

npiet = callPackage ../development/interpreters/npiet { };

npth = callPackage ../development/libraries/npth { };

nmap-formatter = callPackage ../tools/security/nmap-formatter { };
Expand Down