about summary refs log tree commit diff
path: root/pkgs/applications/emulators/craftos-pc
diff options
context:
space:
mode:
authorTomo <68489118+tomodachi94@users.noreply.github.com>2023-05-16 06:39:35 +0000
committerTomo <68489118+Tomodachi94@users.noreply.github.com>2023-06-26 17:33:32 -0700
commit9cdeb84cd97c7a61b679d7f01ad59ab4442b37f6 (patch)
treef2e145ed44c943a3f29c1f268a7e2582ea94442f /pkgs/applications/emulators/craftos-pc
parent4bc5836dc203a01ce134c02720c1b6c4082c1cea (diff)
craftos-pc: add basic tests
This ensures that most obvious breakages will be caught before they are
shipped.
Diffstat (limited to 'pkgs/applications/emulators/craftos-pc')
-rw-r--r--pkgs/applications/emulators/craftos-pc/default.nix6
-rw-r--r--pkgs/applications/emulators/craftos-pc/test-eval-hello-world/default.nix18
-rw-r--r--pkgs/applications/emulators/craftos-pc/test-eval-hello-world/init.lua3
-rw-r--r--pkgs/applications/emulators/craftos-pc/test-eval-periphemu/default.nix19
-rw-r--r--pkgs/applications/emulators/craftos-pc/test-eval-periphemu/init.lua18
5 files changed, 64 insertions, 0 deletions
diff --git a/pkgs/applications/emulators/craftos-pc/default.nix b/pkgs/applications/emulators/craftos-pc/default.nix
index 8dcac1443293c..67950e0ed8a4d 100644
--- a/pkgs/applications/emulators/craftos-pc/default.nix
+++ b/pkgs/applications/emulators/craftos-pc/default.nix
@@ -1,6 +1,7 @@
 { lib
 , stdenv
 , fetchFromGitHub
+, callPackage
 , patchelf
 , unzip
 , poco
@@ -59,6 +60,11 @@ stdenv.mkDerivation rec {
     cp -R ${craftos2-rom}/* $out/share/craftos
   '';
 
+  passthru.tests = {
+    eval-hello-world = callPackage ./test-eval-hello-world { };
+    eval-periphemu = callPackage ./test-eval-periphemu { };
+  };
+
   meta = with lib; {
     description = "An implementation of the CraftOS-PC API written in C++ using SDL";
     homepage = "https://www.craftos-pc.cc";
diff --git a/pkgs/applications/emulators/craftos-pc/test-eval-hello-world/default.nix b/pkgs/applications/emulators/craftos-pc/test-eval-hello-world/default.nix
new file mode 100644
index 0000000000000..b2d887428a0e9
--- /dev/null
+++ b/pkgs/applications/emulators/craftos-pc/test-eval-hello-world/default.nix
@@ -0,0 +1,18 @@
+{ stdenv
+, craftos-pc
+, grep
+}:
+
+stdenv.mkDerivation {
+  name = "craftos-pc-test-eval-hello-world";
+  meta.timeout = 60;
+  nativeBuildInputs = [ craftos-pc grep ];
+  buildCommand = ''
+    export HOME=$(pwd)
+    mkdir $HOME/.local $HOME/.config
+    export XDG_CONFIG_DIR=$HOME/.config
+    export XDG_DATA_DIR=$HOME/.local
+    craftos --headless --script ${./init.lua} | grep "Hello Nixpkgs!" > /dev/null
+    touch $out
+  '';
+}
diff --git a/pkgs/applications/emulators/craftos-pc/test-eval-hello-world/init.lua b/pkgs/applications/emulators/craftos-pc/test-eval-hello-world/init.lua
new file mode 100644
index 0000000000000..5279b1a78c670
--- /dev/null
+++ b/pkgs/applications/emulators/craftos-pc/test-eval-hello-world/init.lua
@@ -0,0 +1,3 @@
+print("Hello Nixpkgs!")
+
+shell.run("shutdown")
diff --git a/pkgs/applications/emulators/craftos-pc/test-eval-periphemu/default.nix b/pkgs/applications/emulators/craftos-pc/test-eval-periphemu/default.nix
new file mode 100644
index 0000000000000..ad5cf97401a00
--- /dev/null
+++ b/pkgs/applications/emulators/craftos-pc/test-eval-periphemu/default.nix
@@ -0,0 +1,19 @@
+{ stdenv
+, craftos-pc
+, grep
+}:
+stdenv.mkDerivation {
+  name = "craftos-pc-test-eval-periphemu";
+  meta.timeout = 60;
+  nativeBuildInputs = [ craftos-pc grep ];
+  buildCommand = ''
+    export HOME=$(pwd)
+    mkdir $HOME/.local $HOME/.config
+    export XDG_CONFIG_DIR=$HOME/.config
+    export XDG_DATA_DIR=$HOME/.local
+    if craftos --headless --script ${./init.lua} | grep -q "FAIL"; then
+        exit 1
+    fi
+    touch $out
+  '';
+}
diff --git a/pkgs/applications/emulators/craftos-pc/test-eval-periphemu/init.lua b/pkgs/applications/emulators/craftos-pc/test-eval-periphemu/init.lua
new file mode 100644
index 0000000000000..1d6ec8b6d8425
--- /dev/null
+++ b/pkgs/applications/emulators/craftos-pc/test-eval-periphemu/init.lua
@@ -0,0 +1,18 @@
+local function assert(cond1, cond2)
+    if not cond1 == cond2 then print("FAIL") end
+end
+
+local function driveTests()
+    periphemu.create("left", "drive")
+    local p = peripheral.wrap("left")
+
+    assert(p.isDiskPresent(), false)
+    p.insertDisk(649)
+    assert(p.isDiskPresent(), true)
+    assert(p.getDiskID(), 649)
+    assert(p.getDiskLabel(), nil)
+end
+
+driveTests()
+
+shell.run("shutdown")