Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at litex 68 lines 1.6 kB view raw
1{ deno, runCommand, lib, testers }: 2let 3 testDenoRun = 4 name: 5 { args ? "" 6 , dir ? ./. + "/${name}" 7 , file ? "index.ts" 8 , expected ? "" 9 , expectFailure ? false 10 }: 11 let 12 command = "deno run ${args} ${dir}/${file}"; 13 in 14 runCommand "deno-test-${name}" { nativeBuildInputs = [ deno ]; meta.timeout = 60; } '' 15 HOME=$(mktemp -d) 16 if output=$(${command} 2>&1); then 17 if [[ $output =~ '${expected}' ]]; then 18 echo "Test '${name}' passed" 19 touch $out 20 else 21 echo -n ${lib.escapeShellArg command} >&2 22 echo " output did not match what was expected." >&2 23 echo "The expected was:" >&2 24 echo '${expected}' >&2 25 echo "The output was:" >&2 26 echo "$output" >&2 27 exit 1 28 fi 29 else 30 if [[ "${toString expectFailure}" == "1" ]]; then 31 echo "Test '${name}' failed as expected" 32 touch $out 33 exit 0 34 fi 35 echo -n ${lib.escapeShellArg command} >&2 36 echo " returned a non-zero exit code." >&2 37 echo "$output" >&2 38 exit 1 39 fi 40 ''; 41in 42(lib.mapAttrs testDenoRun { 43 basic = { 44 dir = ./.; 45 file = "basic.ts"; 46 expected = "2"; 47 }; 48 import-json = { 49 expected = "hello from JSON"; 50 }; 51 import-ts = { 52 expected = "hello from ts"; 53 }; 54 read-file = { 55 args = "--allow-read"; 56 expected = "hello from a file"; 57 }; 58 fail-read-file = { 59 expectFailure = true; 60 dir = ./read-file; 61 }; 62}) // 63{ 64 version = testers.testVersion { 65 package = deno; 66 command = "deno --version"; 67 }; 68}