From 13e2eafa359a7257a0d7bbdc8d030a33a0b175a8 Mon Sep 17 00:00:00 2001 From: Dmitri Polchinski Date: Mon, 24 Feb 2025 03:37:25 +0400 Subject: [PATCH] refactor: simplify script for integration tests (examples) --- .github/scripts/test.sh | 55 +++++++++++++++++++++++++--------------- .github/workflows/ci.yml | 24 +----------------- 2 files changed, 36 insertions(+), 43 deletions(-) diff --git a/.github/scripts/test.sh b/.github/scripts/test.sh index 0ad1dbc..ec30234 100755 --- a/.github/scripts/test.sh +++ b/.github/scripts/test.sh @@ -2,26 +2,41 @@ set -euo pipefail -file="examples/$1.b" -expected=$2 -input=${3:-} +declare -A examples=( + ['helloworld']='Hello World!' + ['addition']='7' + ['bubblesort:978365412']='123456789' + ['bubblesort:aZefcYbdX']='XYZabcdef' + ['rot13:Uryyb, Jbeyq!']='Hello, World!' + ['rot13:Hello, World!']='Uryyb, Jbeyq!' +) -if [ ! -f "$file" ]; then - echo "error: file $file doesn't exist" - exit 1 -fi +for example in "${!examples[@]}"; do + name="$example" + input="" + expected="${examples[$example]}" + + if [[ $example == *:* ]]; then + name="${example%%:*}" + input="${example##*:}" + fi + + file="examples/$name.b" + + if [ ! -f "$file" ]; then + echo "error: File $file doesn't exist" + exit 1 + fi -if [ -n "$input" ]; then output=$(echo -n "$input" | scala-cli run . -q -- "$(< "$file")") -else - output=$(scala-cli run . -q -- "$(< "$file")") -fi - -if [ "$output" = "$expected" ]; then - echo "✓ $file passed" -else - echo "✗ $file failed" - echo " expected: '$expected'" - echo " got: '$output'" - exit 1 -fi + + echo "Running $file $input" + if [ "$output" = "$expected" ]; then + echo "✓ $file passed" + else + echo "✗ $file failed" + echo " expected: '$expected'" + echo " got: '$output'" + exit 1 + fi +done diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 704ea9c..abc9e82 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,29 +41,7 @@ jobs: - uses: VirtusLab/scala-cli-setup@main - name: Run integration tests - run: | - declare -A examples=( - ["helloworld"]='Hello World!' - ["addition"]='7' - ['bubblesort:978365412']='123456789' - ['bubblesort:aZefcYbdX']='XYZabcdef' - ['rot13:Uryyb, Jbeyq!']='Hello, World!' - ['rot13:Hello, World!']='Uryyb, Jbeyq!' - ) - - for example in "${!examples[@]}"; do - name="$example" - input="" - expected="${examples[$example]}" - - if [[ $example == *:* ]]; then - name="${example%%:*}" - input="${example##*:}" - fi - - echo "Running examples/$name.b $input" - .github/scripts/test.sh "$name" "$expected" "$input" - done + run: .github/scripts/test.sh build-native: strategy: