Skip to content

Commit

Permalink
Merge pull request #121 from roc-lang/examples-dir-everywhere
Browse files Browse the repository at this point in the history
Use EXAMPLES_DIR everywhere
  • Loading branch information
Anton-4 authored Nov 4, 2023
2 parents c31eade + ce8d01c commit d6bd045
Show file tree
Hide file tree
Showing 18 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

14 changes: 8 additions & 6 deletions ci/all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/args.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/command.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/countdown.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ENTER>.\r\n"
Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/dir.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/echo.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/env.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/file-read.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/form.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/hello-world.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/http-get.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/piping.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
4 changes: 2 additions & 2 deletions ci/expect_scripts/record-builder.exp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set timeout 7

source ./ci/expect_scripts/shared-code.exp

spawn ./examples/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 {
Expand All @@ -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
exit 1
2 changes: 1 addition & 1 deletion ci/expect_scripts/stdin.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/tcp-client.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/time.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions ci/test_latest_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d6bd045

Please sign in to comment.