+1
test/assert/.gitignore
+1
test/assert/.gitignore
···
1
+
build
+4
test/assert/Makefile
+4
test/assert/Makefile
+6
test/assert/gleam.toml
+6
test/assert/gleam.toml
+9
test/assert/manifest.toml
+9
test/assert/manifest.toml
···
1
+
# This file was generated by Gleam
2
+
# You typically do not need to edit this file
3
+
4
+
packages = [
5
+
{ name = "gleam_stdlib", version = "0.58.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "091F2D2C4A3A4E2047986C47E2C2C9D728A4E068ABB31FDA17B0D347E6248467" },
6
+
]
7
+
8
+
[requirements]
9
+
gleam_stdlib = { version = ">= 0.58.0 and < 2.0.0" }
+54
test/assert/run_tests.sh
+54
test/assert/run_tests.sh
···
1
+
#/usr/bin/env sh
2
+
3
+
set -eu
4
+
5
+
should_succeed() {
6
+
echo
7
+
echo Running: "$@"
8
+
9
+
EXIT_CODE=0
10
+
cargo run -- $@ > /dev/null 2>&1 || EXIT_CODE=$?
11
+
if [ $EXIT_CODE -ne 0 ]
12
+
then
13
+
echo ERROR: Command should have succeeded
14
+
exit 1
15
+
else
16
+
echo Test Passed '(command run successfully)'
17
+
fi
18
+
}
19
+
20
+
should_fail() {
21
+
echo
22
+
echo Running: "$@"
23
+
24
+
EXIT_CODE=0
25
+
cargo run -- $@ > /dev/null 2>&1 || EXIT_CODE=$?
26
+
27
+
if [ $EXIT_CODE -eq 0 ]
28
+
then
29
+
echo ERROR: Command should have failed
30
+
exit 1
31
+
else
32
+
echo Test Passed '(command errored as expected)'
33
+
fi
34
+
}
35
+
36
+
all_targets() {
37
+
$@ --target erlang
38
+
$@ --target javascript --runtime nodejs
39
+
$@ --target javascript --runtime deno
40
+
$@ --target javascript --runtime bun
41
+
}
42
+
43
+
# Ensure the project builds correctly
44
+
should_succeed build --target erlang
45
+
should_succeed build --target javascript
46
+
47
+
all_targets should_succeed run --module passing
48
+
49
+
# Since a single failing `assert` will exit immediately, we must test each
50
+
# failing case individually as separate modules.
51
+
all_targets should_fail run --module failing1
52
+
all_targets should_fail run --module failing2
53
+
all_targets should_fail run --module failing3
54
+
all_targets should_fail run --module failing4
+5
test/assert/src/failing2.gleam
+5
test/assert/src/failing2.gleam
+6
test/assert/src/failing3.gleam
+6
test/assert/src/failing3.gleam
+5
test/assert/src/failing4.gleam
+5
test/assert/src/failing4.gleam
+25
test/assert/src/passing.gleam
+25
test/assert/src/passing.gleam
···
1
+
import gleam/bool
2
+
import gleam/int
3
+
import gleam/result
4
+
5
+
/// All these assertions should succeed
6
+
pub fn main() {
7
+
let x = True
8
+
assert x
9
+
assert case x && False {
10
+
True -> False
11
+
False -> True
12
+
}
13
+
14
+
assert result.is_ok(Ok(10))
15
+
assert result.is_error(Error("Hello"))
16
+
17
+
assert int.add(5, 6) == 11
18
+
assert int.add(1, 4) < 9
19
+
assert int.add(8, 12) >= 20
20
+
assert bool.negate(False) && result.is_ok(Ok(42))
21
+
assert int.is_even(3) || int.is_even(4)
22
+
23
+
// This should short-circuit so we don't panic here
24
+
assert True || panic
25
+
}