⭐️ A friendly language for building type-safe, scalable systems!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: use shell script for tests

authored by

Lunarmagpie and committed by
Louis Pilfold
e8fa1268 ef58f1f5

+45 -40
+1 -1
test/running_modules/gleam.toml
··· 1 - name = "running_modules" 1 + name = "module" 2 2 version = "0.1.0" 3 3 description = "A Gleam project" 4 4
+41 -39
test/running_modules/run_tests
··· 1 - #!/usr/bin/env python 2 - 3 - from __future__ import annotations 4 - 5 - import subprocess 6 - 7 - 8 - targets = [ 9 - ["--target", "erlang"], 10 - ["--target", "javascript", "--runtime", "node"], 11 - ["--target", "javascript", "--runtime", "deno"], 12 - ] 1 + #/usr/bin/env sh 13 2 14 - 15 - def main(): 16 - any_failed = not all([ 17 - test_command_output( 18 - ["cargo", "run", "--", "run", "-m", "running_modules"], 19 - expected="top level module", 20 - ), 21 - test_command_output( 22 - ["cargo", "run", "--", "run", "-m", "running_modules/sub_module"], 23 - expected="sub module", 24 - ), 25 - ]) 26 - raise SystemExit(any_failed) 3 + should_succeed() { 4 + echo Running: "$@" 5 + eval "$@" 6 + if [ $? -ne 0 ] 7 + then 8 + echo ERROR: Command should have succeeded 9 + exit 1 10 + else 11 + echo Test Passed 12 + fi 13 + } 14 + should_fail() { 15 + echo Running: "$@" 16 + eval "$@" 17 + if [ $? -eq 0 ] 18 + then 19 + echo ERROR: Command should have failed 20 + exit 1 21 + else 22 + echo Test Passed 23 + fi 24 + } 27 25 26 + # No module 27 + should_succeed cargo run -- run --target erlang 28 + should_succeed cargo run -- run --target javascript --runtime nodejs 29 + should_succeed cargo run -- run --target javascript --runtime deno 28 30 29 - def test_command_output(args: list[str], *, expected: str) -> bool: 30 - for target in targets: 31 - args_copy = args.copy() 32 - args_copy.extend(target) 33 - print("Testing command ", args_copy, "...", sep="") 34 - output = subprocess.run(args_copy, capture_output=True) 31 + # Module from same package 32 + should_succeed cargo run -- run --module module --target erlang 33 + should_succeed cargo run -- run --module module --target javascript --runtime nodejs 34 + should_succeed cargo run -- run --module module --target javascript --runtime deno 35 35 36 - if expected not in output.stdout.decode("utf-8"): 37 - print("Failed when running command", args) 38 - print("with stdout:", output.stdout.decode("utf-8")) 39 - return False 36 + # Nested module from same package 37 + should_succeed cargo run -- run --module module/sub_module --target erlang 38 + should_succeed cargo run -- run --module module/sub_module --target javascript --runtime nodejs 39 + should_succeed cargo run -- run --module module/sub_module --target javascript --runtime deno 40 40 41 - print("Passed") 42 - return True 41 + # Unknown module 42 + should_fail cargo run -- run --module doesnt_exist 43 43 44 + # No main function 45 + should_fail cargo run -- run --module module/no_main_function 44 46 45 - if __name__ == "__main__": 46 - main() 47 + # Main function with wrong arity 48 + should_fail cargo run -- run --module module/wrong_arity
test/running_modules/src/module/no_main_function.gleam

This is a binary file and will not be displayed.

+3
test/running_modules/src/module/wrong_arity.gleam
··· 1 + pub fn main(arg: Int) -> Nil { 2 + Nil 3 + }
test/running_modules/src/running_modules.gleam test/running_modules/src/module.gleam
test/running_modules/src/running_modules/sub_module.gleam test/running_modules/src/module/sub_module.gleam