Skip to content

Commit 1026ed5

Browse files
committed
ci: add examples matrix
1 parent a655912 commit 1026ed5

File tree

2 files changed

+60
-31
lines changed

2 files changed

+60
-31
lines changed

.github/test.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
file="examples/$1.b"
6+
expected=$2
7+
input=${3:-}
8+
9+
if [ ! -f "$file" ]; then
10+
echo "error: file $file doesn't exist"
11+
exit 1
12+
fi
13+
14+
if [ -n "$input" ]; then
15+
output=$(echo -n "$input" | scala-cli run . -q -- "$(cat "$file")")
16+
else
17+
output=$(scala-cli run . -q -- "$(cat "$file")")
18+
fi
19+
20+
if [ "$output" = "$expected" ]; then
21+
echo "$file passed"
22+
else
23+
echo "$file failed"
24+
echo " expected: '$expected'"
25+
echo " got: '$output'"
26+
exit 1
27+
fi

.github/workflows/ci.yml

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,60 @@ on:
66
pull_request:
77

88
jobs:
9-
test:
10-
name: Test
9+
format:
10+
name: Code Formatting
1111
runs-on: ubuntu-latest
1212

1313
steps:
1414
- uses: actions/checkout@v4
1515
- uses: coursier/cache-action@v6
1616
- uses: VirtusLab/scala-cli-setup@main
17-
with:
18-
power: true
1917

20-
- name: Run tests
21-
run: scala-cli test .
18+
- name: Check formatting
19+
run: scala-cli format --check .
2220

23-
format:
24-
name: Format
21+
test:
22+
name: Unit Tests
2523
runs-on: ubuntu-latest
2624

2725
steps:
2826
- uses: actions/checkout@v4
2927
- uses: coursier/cache-action@v6
3028
- uses: VirtusLab/scala-cli-setup@main
31-
with:
32-
power: true
3329

34-
- name: Check formatting
35-
run: scala-cli format --check .
30+
- name: Run unit tests
31+
run: scala-cli test .
3632

37-
examples:
38-
name: Examples
33+
example:
34+
name: Integration Tests
3935
runs-on: ubuntu-latest
4036

4137
steps:
4238
- uses: actions/checkout@v4
4339
- uses: coursier/cache-action@v6
4440
- uses: VirtusLab/scala-cli-setup@main
45-
with:
46-
power: true
4741

48-
- name: Run Hello World
49-
run: |
50-
output=$(scala-cli run . -- "$(cat examples/helloworld.b)")
51-
test "$output" = "Hello World!"
52-
- name: Run Addition
53-
run: |
54-
output=$(scala-cli run . -- "$(cat examples/addition.b)")
55-
test "$output" = "7"
56-
- name: Run Bubble Sort
42+
- name: Run integration tests
5743
run: |
58-
output=$(echo -n "9c786a5412b" | scala-cli run . -- "$(cat examples/bubblesort.b)")
59-
test "$output" = "12345678abc"
60-
- name: Run ROT13
61-
run: |
62-
output=$(echo -n "Uryyb, Jbeyq!" | scala-cli run . -- "$(cat examples/rot13.b)")
63-
test "$output" = "Hello, World!"
44+
declare -A examples=(
45+
["helloworld"]='Hello World!'
46+
["addition"]='7'
47+
['bubblesort:978365412']='123456789'
48+
['bubblesort:aZefcYbdX']='XYZabcdef'
49+
['rot13:Uryyb, Jbeyq!']='Hello, World!'
50+
['rot13:Hello, World!']='Uryyb, Jbeyq!'
51+
)
52+
53+
for example in "${!examples[@]}"; do
54+
name="$example"
55+
input=""
56+
expected="${examples[$example]}"
57+
58+
if [[ $example == *:* ]]; then
59+
name="${example%%:*}"
60+
input="${example##*:}"
61+
fi
62+
63+
echo "Running examples/$name.b $input"
64+
.github/test.sh "$name" "$expected" "$input"
65+
done

0 commit comments

Comments
 (0)