From 18e909bba7acfdbe1e394f4865496bd6b7f03bd3 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Sat, 4 Nov 2023 18:20:22 +0100 Subject: [PATCH 1/3] Use EXAMPLES_DIR everywhere --- .github/workflows/ci.yml | 2 +- ci/all_tests.sh | 14 ++++++++------ ci/expect_scripts/args.exp | 2 +- ci/expect_scripts/command.exp | 2 +- ci/expect_scripts/countdown.exp | 2 +- ci/expect_scripts/dir.exp | 2 +- ci/expect_scripts/echo.exp | 2 +- ci/expect_scripts/env.exp | 2 +- ci/expect_scripts/file-read.exp | 2 +- ci/expect_scripts/form.exp | 2 +- ci/expect_scripts/hello-world.exp | 2 +- ci/expect_scripts/http-get.exp | 2 +- ci/expect_scripts/piping.exp | 2 +- ci/expect_scripts/record-builder.exp | 2 +- ci/expect_scripts/stdin.exp | 2 +- ci/expect_scripts/tcp-client.exp | 2 +- ci/expect_scripts/time.exp | 2 +- ci/test_latest_release.sh | 10 ++++++---- 18 files changed, 30 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02b1eeca..5e54f815 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: - run: expect -v # Run all tests - - run: ./ci/all_tests.sh + - run: EXAMPLES_DIR=./examples ./ci/all_tests.sh # TODO clippy, rustfmt, roc fmt check diff --git a/ci/all_tests.sh b/ci/all_tests.sh index 9b3ada15..386485b6 100755 --- a/ci/all_tests.sh +++ b/ci/all_tests.sh @@ -3,20 +3,22 @@ # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ set -euxo pipefail -roc='./roc_nightly/roc' +if [ -z "${EXAMPLES_DIR}" ]; then + echo "ERROR: The EXAMPLES_DIR environment variable is not set." >&2 + exit 1 +fi -# Use EXAMPLES_DIR if set, otherwise use a default value -examples_dir="${EXAMPLES_DIR:-./examples/}" +roc='./roc_nightly/roc' # roc check -for roc_file in $examples_dir*.roc; do +for roc_file in $EXAMPLES_DIR*.roc; do $roc check $roc_file done # roc build architecture=$(uname -m) -for roc_file in $examples_dir*.roc; do +for roc_file in $EXAMPLES_DIR*.roc; do base_file=$(basename "$roc_file") # Skip argsBROKEN.roc @@ -33,7 +35,7 @@ for roc_file in $examples_dir*.roc; do done # check output -for roc_file in $examples_dir*.roc; do +for roc_file in $EXAMPLES_DIR*.roc; do base_file=$(basename "$roc_file") # Skip argsBROKEN.roc diff --git a/ci/expect_scripts/args.exp b/ci/expect_scripts/args.exp index 31b8dbd8..bcb6c956 100755 --- a/ci/expect_scripts/args.exp +++ b/ci/expect_scripts/args.exp @@ -5,7 +5,7 @@ set timeout 7 -spawn ./examples/args log -b 3 --num 81 +spawn $env(EXAMPLES_DIR)/args log -b 3 --num 81 source ./ci/expect_scripts/shared-code.exp diff --git a/ci/expect_scripts/command.exp b/ci/expect_scripts/command.exp index 17746b80..58605d7d 100644 --- a/ci/expect_scripts/command.exp +++ b/ci/expect_scripts/command.exp @@ -7,7 +7,7 @@ set timeout 7 source ./ci/expect_scripts/shared-code.exp -spawn ./examples/command +spawn $env(EXAMPLES_DIR)command expect -exact "BAZ=DUCK\r\nFOO=BAR\r\nSuccess\r\nSTATUS Success\r\nSTDOUT '-rw-r--r--'\r\n\r\nSTDERR \r\n" { diff --git a/ci/expect_scripts/countdown.exp b/ci/expect_scripts/countdown.exp index 464d25ba..2581c262 100644 --- a/ci/expect_scripts/countdown.exp +++ b/ci/expect_scripts/countdown.exp @@ -7,7 +7,7 @@ set timeout 7 source ./ci/expect_scripts/shared-code.exp -spawn ./examples/countdown +spawn $env(EXAMPLES_DIR)countdown expect -exact "\r\nLet's count down from 3 together - all you have to do is press .\r\n" diff --git a/ci/expect_scripts/dir.exp b/ci/expect_scripts/dir.exp index 8968a339..d3439a71 100644 --- a/ci/expect_scripts/dir.exp +++ b/ci/expect_scripts/dir.exp @@ -7,7 +7,7 @@ set timeout 7 source ./ci/expect_scripts/shared-code.exp -spawn ./examples/dir +spawn $env(EXAMPLES_DIR)dir expect "Success!\r\n" { expect eof { diff --git a/ci/expect_scripts/echo.exp b/ci/expect_scripts/echo.exp index af36c2f3..4bdbda41 100644 --- a/ci/expect_scripts/echo.exp +++ b/ci/expect_scripts/echo.exp @@ -5,7 +5,7 @@ set timeout 7 -spawn ./examples/echo +spawn $env(EXAMPLES_DIR)echo expect -exact "🗣 Shout into this cave and hear the echo! 👂👂👂\r\n" diff --git a/ci/expect_scripts/env.exp b/ci/expect_scripts/env.exp index 1afd1083..b35aa215 100644 --- a/ci/expect_scripts/env.exp +++ b/ci/expect_scripts/env.exp @@ -11,7 +11,7 @@ set env(EDITOR) nano set env(SHLVL) 2 set env(LETTERS) a,c,e,j -spawn ./examples/env +spawn $env(EXAMPLES_DIR)env expect "Your favorite editor is nano!\r\n" { diff --git a/ci/expect_scripts/file-read.exp b/ci/expect_scripts/file-read.exp index 458982e0..febb29ce 100644 --- a/ci/expect_scripts/file-read.exp +++ b/ci/expect_scripts/file-read.exp @@ -7,7 +7,7 @@ set timeout 7 source ./ci/expect_scripts/shared-code.exp -spawn ./examples/file-read +spawn $env(EXAMPLES_DIR)file-read expect "First line of README.md: # basic-cli\r\n" { expect eof { diff --git a/ci/expect_scripts/form.exp b/ci/expect_scripts/form.exp index bf597984..108e7315 100644 --- a/ci/expect_scripts/form.exp +++ b/ci/expect_scripts/form.exp @@ -7,7 +7,7 @@ set timeout 7 source ./ci/expect_scripts/shared-code.exp -spawn ./examples/form +spawn $env(EXAMPLES_DIR)form expect "What's your first name?\r\n" diff --git a/ci/expect_scripts/hello-world.exp b/ci/expect_scripts/hello-world.exp index ea666b43..d59ee094 100644 --- a/ci/expect_scripts/hello-world.exp +++ b/ci/expect_scripts/hello-world.exp @@ -7,7 +7,7 @@ set timeout 7 source ./ci/expect_scripts/shared-code.exp -spawn ./examples/hello-world +spawn $env(EXAMPLES_DIR)hello-world expect "Hello, World!\r\n" { expect eof { diff --git a/ci/expect_scripts/http-get.exp b/ci/expect_scripts/http-get.exp index 53f306dc..db81641b 100644 --- a/ci/expect_scripts/http-get.exp +++ b/ci/expect_scripts/http-get.exp @@ -7,7 +7,7 @@ set timeout 7 source ./ci/expect_scripts/shared-code.exp -spawn ./examples/http-get +spawn $env(EXAMPLES_DIR)http-get expect -exact "Enter a URL to fetch. It must contain a scheme like \"http://\" or \"https://\".\r\n" diff --git a/ci/expect_scripts/piping.exp b/ci/expect_scripts/piping.exp index 0c6939e7..7d98f52d 100644 --- a/ci/expect_scripts/piping.exp +++ b/ci/expect_scripts/piping.exp @@ -8,7 +8,7 @@ set timeout 7 source ./ci/expect_scripts/shared-code.exp # Spawn the command to pipe in the data to the script B -spawn bash -c "echo -e \"test\n123\" | ./examples/piping" +spawn bash -c "echo -e \"test\n123\" | $env(EXAMPLES_DIR)/piping" # Expect the output expect -exact "I read 2 lines from stdin.\r\n" { diff --git a/ci/expect_scripts/record-builder.exp b/ci/expect_scripts/record-builder.exp index 6a90d6ff..e0425b84 100644 --- a/ci/expect_scripts/record-builder.exp +++ b/ci/expect_scripts/record-builder.exp @@ -7,7 +7,7 @@ set timeout 7 source ./ci/expect_scripts/shared-code.exp -spawn ./examples/record-builder +spawn spawn $env(EXAMPLES_DIR)record-builder expect "Apples: Granny Smith, Pink Lady, Golden Delicious\r\nOranges: Navel, Blood Orange, Clementine\r\n" { expect eof { diff --git a/ci/expect_scripts/stdin.exp b/ci/expect_scripts/stdin.exp index ddd33c11..5b2e9433 100644 --- a/ci/expect_scripts/stdin.exp +++ b/ci/expect_scripts/stdin.exp @@ -7,7 +7,7 @@ set timeout 7 source ./ci/expect_scripts/shared-code.exp -spawn ./examples/stdin +spawn $env(EXAMPLES_DIR)stdin expect -exact "Enter a series of number characters (0-9):\r\n" diff --git a/ci/expect_scripts/tcp-client.exp b/ci/expect_scripts/tcp-client.exp index 82c450f9..34583905 100644 --- a/ci/expect_scripts/tcp-client.exp +++ b/ci/expect_scripts/tcp-client.exp @@ -11,7 +11,7 @@ set cat_path [exec which cat] spawn ncat -e $cat_path -l 8085 sleep 5 -spawn ./examples/tcp-client +spawn $env(EXAMPLES_DIR)tcp-client expect "Connected!\r\n" { diff --git a/ci/expect_scripts/time.exp b/ci/expect_scripts/time.exp index 7497434c..742fcb07 100644 --- a/ci/expect_scripts/time.exp +++ b/ci/expect_scripts/time.exp @@ -7,7 +7,7 @@ set timeout 7 source ./ci/expect_scripts/shared-code.exp -spawn ./examples/time +spawn $env(EXAMPLES_DIR)time expect -re "Completed in \[0-9]+ns\r\n" { expect eof { diff --git a/ci/test_latest_release.sh b/ci/test_latest_release.sh index bbcc9eaf..ec568389 100755 --- a/ci/test_latest_release.sh +++ b/ci/test_latest_release.sh @@ -3,6 +3,11 @@ # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ set -euxo pipefail +if [ -z "${EXAMPLES_DIR}" ]; then + echo "ERROR: The EXAMPLES_DIR environment variable is not set." >&2 + exit 1 +fi + # Install jq if it's not already available command -v jq &>/dev/null || sudo apt install -y jq @@ -30,11 +35,8 @@ mv "$NIGHTLY_FOLDER" roc_nightly CLI_RELEASES_JSON=$(curl -s https://api.github.com/repos/roc-lang/basic-cli/releases) CLI_RELEASE_URL=$(echo $CLI_RELEASES_JSON | jq -r '.[0].assets | .[] | select(.name | test("\\.tar\\.br$")) | .browser_download_url') -# Use EXAMPLES_DIR if set, otherwise use a default value -examples_dir="${EXAMPLES_DIR:-./examples/}" - # Use the latest basic-cli release as the platform for every example -sed -i "s|../src/main.roc|$CLI_RELEASE_URL|g" $examples_dir/*.roc +sed -i "s|../src/main.roc|$CLI_RELEASE_URL|g" $EXAMPLES_DIR/*.roc # Install required packages for tests if they're not already available command -v ncat &>/dev/null || sudo apt install -y ncat From e1854f3e626608556a279471f25401ade1d470d3 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Sat, 4 Nov 2023 18:22:32 +0100 Subject: [PATCH 2/3] fix EXAMPLES_DIR path --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e54f815..f2d516b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: - run: expect -v # Run all tests - - run: EXAMPLES_DIR=./examples ./ci/all_tests.sh + - run: EXAMPLES_DIR=./examples/ ./ci/all_tests.sh # TODO clippy, rustfmt, roc fmt check From ce8d01c79e17ea28795f7b3f8bcbc78c6e4e4da8 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Sat, 4 Nov 2023 18:58:48 +0100 Subject: [PATCH 3/3] typo in spawn --- ci/expect_scripts/record-builder.exp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/expect_scripts/record-builder.exp b/ci/expect_scripts/record-builder.exp index e0425b84..efa24d7e 100644 --- a/ci/expect_scripts/record-builder.exp +++ b/ci/expect_scripts/record-builder.exp @@ -7,7 +7,7 @@ set timeout 7 source ./ci/expect_scripts/shared-code.exp -spawn spawn $env(EXAMPLES_DIR)record-builder +spawn $env(EXAMPLES_DIR)record-builder expect "Apples: Granny Smith, Pink Lady, Golden Delicious\r\nOranges: Navel, Blood Orange, Clementine\r\n" { expect eof { @@ -16,4 +16,4 @@ expect "Apples: Granny Smith, Pink Lady, Golden Delicious\r\nOranges: Navel, Blo } puts stderr "\nError: output was different from expected value." -exit 1 \ No newline at end of file +exit 1