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