From 909bf7941353ee5bf95e24736a3db806369406c4 Mon Sep 17 00:00:00 2001 From: Luflosi Date: Sat, 10 Aug 2024 12:52:10 +0200 Subject: [PATCH 1/2] npiet: cleanup - Move to pkgs/by-name - Format - Use `finalAttrs` instead of `rec` for passing the `version` to `fetchurl` - Use `hash` instead of `sha256` for `fetchurl` - Use `--replace-fail` instead of `--replace` for `substituteInPlace` - Add `strictDeps = true` - Use `lib` directly in `meta` instead of using `with lib;` - Add `meta.changelog` - Add `meta.mainProgram` --- .../np/npiet/package.nix} | 47 +++++++++++-------- pkgs/top-level/all-packages.nix | 2 - 2 files changed, 28 insertions(+), 21 deletions(-) rename pkgs/{development/interpreters/npiet/default.nix => by-name/np/npiet/package.nix} (51%) diff --git a/pkgs/development/interpreters/npiet/default.nix b/pkgs/by-name/np/npiet/package.nix similarity index 51% rename from pkgs/development/interpreters/npiet/default.nix rename to pkgs/by-name/np/npiet/package.nix index bcd546c514c0..c6fe0aa19403 100644 --- a/pkgs/development/interpreters/npiet/default.nix +++ b/pkgs/by-name/np/npiet/package.nix @@ -1,23 +1,28 @@ -{ lib -, stdenv -, fetchurl -, gd -, giflib -, groff -, libpng -, tk +{ + lib, + stdenv, + fetchurl, + gd, + giflib, + groff, + libpng, + tk, }: -stdenv.mkDerivation rec { +stdenv.mkDerivation (finalAttrs: { pname = "npiet"; version = "1.3f"; src = fetchurl { - url = "https://www.bertnase.de/npiet/npiet-${version}.tar.gz"; - sha256 = "sha256-Le2FYGKr1zWZ6F4edozmvGC6LbItx9aptidj3KBLhVo="; + url = "https://www.bertnase.de/npiet/npiet-${finalAttrs.version}.tar.gz"; + hash = "sha256-Le2FYGKr1zWZ6F4edozmvGC6LbItx9aptidj3KBLhVo="; }; - buildInputs = [ gd giflib libpng ]; + buildInputs = [ + gd + giflib + libpng + ]; nativeBuildInputs = [ groff ]; @@ -25,21 +30,25 @@ stdenv.mkDerivation rec { # 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 '#include ' "" + --replace-fail '#include ' "" substituteInPlace npietedit \ - --replace 'exec wish' 'exec ${tk}/bin/wish' + --replace-fail 'exec wish' 'exec ${tk}/bin/wish' ''; - meta = with lib; { + strictDeps = true; + + 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/"; - license = licenses.gpl2Only; - platforms = platforms.unix; - maintainers = with maintainers; [ Luflosi ]; + changelog = "https://www.bertnase.de/npiet/ChangeLog"; + license = lib.licenses.gpl2Only; + platforms = lib.platforms.unix; + mainProgram = "npiet"; + maintainers = with lib.maintainers; [ Luflosi ]; }; -} +}) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 5abbc65131f9..52af67c91587 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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 { }; From 15fe3c9320be5e596abc58cb91903b201dc85bda Mon Sep 17 00:00:00 2001 From: Luflosi Date: Sat, 10 Aug 2024 13:01:36 +0200 Subject: [PATCH 2/2] npiet: add package tests --- pkgs/by-name/np/npiet/package.nix | 14 ++++++++ pkgs/by-name/np/npiet/tests/default.nix | 41 ++++++++++++++++++++++++ pkgs/by-name/np/npiet/tests/run-test.nix | 19 +++++++++++ 3 files changed, 74 insertions(+) create mode 100644 pkgs/by-name/np/npiet/tests/default.nix create mode 100644 pkgs/by-name/np/npiet/tests/run-test.nix diff --git a/pkgs/by-name/np/npiet/package.nix b/pkgs/by-name/np/npiet/package.nix index c6fe0aa19403..cbc1592129e4 100644 --- a/pkgs/by-name/np/npiet/package.nix +++ b/pkgs/by-name/np/npiet/package.nix @@ -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 = '' diff --git a/pkgs/by-name/np/npiet/tests/default.nix b/pkgs/by-name/np/npiet/tests/default.nix new file mode 100644 index 000000000000..92e3780bac6d --- /dev/null +++ b/pkgs/by-name/np/npiet/tests/default.nix @@ -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"; + }; +} diff --git a/pkgs/by-name/np/npiet/tests/run-test.nix b/pkgs/by-name/np/npiet/tests/run-test.nix new file mode 100644 index 000000000000..19c625e1f7e9 --- /dev/null +++ b/pkgs/by-name/np/npiet/tests/run-test.nix @@ -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" +''