diff --git a/pkgs/development/compilers/factor-lang/test/hello-world/default.nix b/pkgs/development/compilers/factor-lang/test/hello-world/default.nix new file mode 100644 index 000000000000..a84260381291 --- /dev/null +++ b/pkgs/development/compilers/factor-lang/test/hello-world/default.nix @@ -0,0 +1,56 @@ +# Builds hello-world Factor application using buildFactorApplication & verifies +# source-to-binary that the resulting app prints "Hello, $NAME" depending on +# `--name` flag. +{ + lib, + runCommandLocal, + buildFactorApplication, + buildFactorVocab, +}: + +let + fs = lib.fileset; + + factorFilter = + file: + lib.lists.any file.hasExt [ + "factor" + "txt" + ]; + + version = "0-test"; + + vocab = buildFactorVocab { + inherit version; + pname = "hello"; + src = fs.toSource { + root = ./extra; + fileset = fs.difference (fs.fileFilter factorFilter ./extra/hello) ./extra/hello/cli; + }; + vocabName = "hello"; + }; + + app = buildFactorApplication { + inherit version; + pname = "hello-cli"; + src = fs.toSource { + root = ./extra; + fileset = fs.fileFilter factorFilter ./extra/hello/cli; + }; + vocabName = "hello.cli"; + binName = "hello"; + extraVocabs = [ vocab ]; + }; +in +runCommandLocal "assert-factor-hello-world" + { + env.expected = "Hello, Nixpkgs"; + } + '' + output="$(${lib.getExe app} --name "Nixpkgs")" + if [ "$output" != "$expected" ]; then + echo "FAIL: expected “$expected”; got “$output”" >&2 + exit 1 + fi + touch "$out" + '' diff --git a/pkgs/development/compilers/factor-lang/test/hello-world/extra/hello/author.txt b/pkgs/development/compilers/factor-lang/test/hello-world/extra/hello/author.txt new file mode 100644 index 000000000000..95fc5a77b470 --- /dev/null +++ b/pkgs/development/compilers/factor-lang/test/hello-world/extra/hello/author.txt @@ -0,0 +1 @@ +toastal diff --git a/pkgs/development/compilers/factor-lang/test/hello-world/extra/hello/cli/author.txt b/pkgs/development/compilers/factor-lang/test/hello-world/extra/hello/cli/author.txt new file mode 100644 index 000000000000..95fc5a77b470 --- /dev/null +++ b/pkgs/development/compilers/factor-lang/test/hello-world/extra/hello/cli/author.txt @@ -0,0 +1 @@ +toastal diff --git a/pkgs/development/compilers/factor-lang/test/hello-world/extra/hello/cli/cli.factor b/pkgs/development/compilers/factor-lang/test/hello-world/extra/hello/cli/cli.factor new file mode 100644 index 000000000000..027ddd7bc9f0 --- /dev/null +++ b/pkgs/development/compilers/factor-lang/test/hello-world/extra/hello/cli/cli.factor @@ -0,0 +1,13 @@ +! SPDX-License-Identifier: 0BSD +USING: command-line combinators io kernel namespaces sequences hello ; + +IN: hello.cli + +: main ( -- ) + command-line get { + { [ dup empty? ] [ drop "world" ] } + { [ dup first "--name" = not ] [ drop "world" ] } + [ second ] + } cond greet ; + +MAIN: main diff --git a/pkgs/development/compilers/factor-lang/test/hello-world/extra/hello/hello.factor b/pkgs/development/compilers/factor-lang/test/hello-world/extra/hello/hello.factor new file mode 100644 index 000000000000..bf256300c641 --- /dev/null +++ b/pkgs/development/compilers/factor-lang/test/hello-world/extra/hello/hello.factor @@ -0,0 +1,7 @@ +! SPDX-License-Identifier: 0BSD +USING: io namespaces sequences ; + +IN: hello + +: greet ( name -- ) + "Hello, " prepend print ; diff --git a/pkgs/development/compilers/factor-lang/wrapper.nix b/pkgs/development/compilers/factor-lang/wrapper.nix index 5f8e4ff37020..80d3def2df04 100644 --- a/pkgs/development/compilers/factor-lang/wrapper.nix +++ b/pkgs/development/compilers/factor-lang/wrapper.nix @@ -2,6 +2,9 @@ lib, stdenv, makeWrapper, + runCommandLocal, + buildFactorApplication, + buildFactorVocab, buildEnv, copyDesktopItems, makeDesktopItem, @@ -220,6 +223,16 @@ stdenv.mkDerivation (finalAttrs: { extraVocabs vocabTree ; + tests = { + hello-world = import ./test/hello-world { + inherit + lib + runCommandLocal + buildFactorApplication + buildFactorVocab + ; + }; + }; }; meta = factor-unwrapped.meta // {