Skip to content

Commit 5f822ea

Browse files
authored
Merge pull request #243 from roc-lang/examples-basic-cli-20
update to basic-cli 0.20.0 + improvements
2 parents c20a8b8 + 4a2322e commit 5f822ea

File tree

60 files changed

+861
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+861
-538
lines changed

.github/workflows/tests_alpha.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
on:
2+
pull_request:
3+
workflow_dispatch:
4+
5+
name: Test examples without nix using alpha release
6+
7+
# this cancels workflows currently in progress if you start a new one
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
# Do not add permissions here! Configure them at the job level!
13+
permissions: {}
14+
15+
jobs:
16+
test-examples:
17+
runs-on: ${{ matrix.operating-system }}
18+
strategy:
19+
matrix:
20+
operating-system: [ubuntu-22.04, ubuntu-24.04, ubuntu-24.04-arm, macos-13, macos-15]
21+
timeout-minutes: 90
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Set OS-specific variables
26+
id: vars
27+
run: |
28+
if [[ "${{ matrix.operating-system }}" =~ ^ubuntu- ]]; then
29+
if [[ "${{ matrix.operating-system }}" =~ -arm$ ]]; then
30+
echo "os_pattern=linux_arm64" >> $GITHUB_OUTPUT
31+
else
32+
echo "os_pattern=linux_x86_64" >> $GITHUB_OUTPUT
33+
fi
34+
elif [ "${{ matrix.operating-system }}" = "macos-13" ]; then
35+
echo "os_pattern=macos_x86_64" >> $GITHUB_OUTPUT
36+
else
37+
echo "os_pattern=macos_apple_silicon" >> $GITHUB_OUTPUT
38+
fi
39+
40+
- name: Download alpha release
41+
run: |
42+
curl -fOL https://github.com/roc-lang/roc/releases/download/alpha4-rolling/roc-${{ steps.vars.outputs.os_pattern }}-alpha4-rolling.tar.gz
43+
44+
- name: rename alpha tar
45+
run: mv $(ls | grep "roc-.*tar\.gz") roc_alpha.tar.gz
46+
47+
- name: decompress the tar
48+
run: tar -xzf roc_alpha.tar.gz
49+
50+
- run: rm roc_alpha.tar.gz
51+
52+
- name: simplify nightly folder name
53+
run: mv roc_nightly* roc_alpha
54+
55+
- name: get short commit SHA
56+
run: echo "SHORT_COMMIT_SHA=$(./roc_alpha/roc version | grep -oP 'commit \K[a-f0-9]+' )" >> $GITHUB_ENV
57+
58+
- name: Install dependencies (Ubuntu)
59+
if: startsWith(matrix.operating-system, 'ubuntu-')
60+
run: sudo apt install -y expect
61+
62+
- name: Install dependencies (macOS)
63+
if: startsWith(matrix.operating-system, 'macos-')
64+
run: |
65+
brew install expect
66+
brew install z3
67+
68+
- name: check if roc files are properly formatted
69+
run: ROC=./roc_alpha/roc ./ci_scripts/check_format.sh
70+
71+
- run: ROC=./roc_alpha/roc ./ci_scripts/all_tests.sh
72+
73+
- name: Checks if every folder in examples is mentioned in ./examples/index.md
74+
run: bash ./ci_scripts/check_index.sh

.github/workflows/tests.yml renamed to .github/workflows/tests_nightly.yml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ${{ matrix.operating-system }}
1818
strategy:
1919
matrix:
20-
operating-system: [ubuntu-22.04, ubuntu-24.04, ubuntu-24.04-arm, macos-13, macos-14]
20+
operating-system: [ubuntu-22.04, ubuntu-24.04, ubuntu-24.04-arm, macos-13, macos-15]
2121
timeout-minutes: 90
2222
steps:
2323
- uses: actions/checkout@v4
@@ -37,13 +37,7 @@ jobs:
3737
echo "os_pattern=macos_apple_silicon" >> $GITHUB_OUTPUT
3838
fi
3939
40-
- id: try_fetching_testing_release
41-
continue-on-error: true
42-
run: |
43-
curl -fOL https://github.com/roc-lang/roc/releases/download/nightly/roc_nightly-${{ steps.vars.outputs.os_pattern }}-TESTING.tar.gz
44-
45-
- name: There are no TESTING releases, checking regular releases instead
46-
if: steps.try_fetching_testing_release.outcome == 'failure'
40+
- name: Download latest nightly release
4741
run: |
4842
curl -fOL https://github.com/roc-lang/roc/releases/download/nightly/roc_nightly-${{ steps.vars.outputs.os_pattern }}-latest.tar.gz
4943
@@ -71,18 +65,10 @@ jobs:
7165
brew install expect
7266
brew install z3
7367
74-
- name: print runner CPU (Ubuntu)
75-
if: startsWith(matrix.operating-system, 'ubuntu-')
76-
run: lscpu
77-
78-
- name: print runner CPU (macOS)
79-
if: startsWith(matrix.operating-system, 'macos-')
80-
run: sysctl -n machdep.cpu.brand_string
81-
8268
- name: check if roc files are properly formatted
8369
run: ROC=./roc_nightly/roc ./ci_scripts/check_format.sh
8470

8571
- run: ROC=./roc_nightly/roc ./ci_scripts/all_tests.sh
8672

8773
- name: Checks if every folder in examples is mentioned in ./examples/index.md
88-
run: bash ./ci_scripts/check_index.sh
74+
run: bash ./ci_scripts/check_index.sh

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ main
66
generate-build
77

88
# example binaries
9-
examples/Arithmetic/main
109
examples/IngestFiles/main
1110
examples/FizzBuzz/main
1211
examples/HelloWorld/main

ci_scripts/all_tests.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ fi
1818
$ROC build ./examples/HelloWorld/main.roc
1919
expect ci_scripts/expect_scripts/HelloWorld.exp
2020

21-
$ROC build ./examples/Arithmetic/main.roc
22-
expect ci_scripts/expect_scripts/Arithmetic.exp
23-
2421
$ROC build ./examples/FizzBuzz/main.roc
2522
$ROC test ./examples/FizzBuzz/main.roc
2623
expect ci_scripts/expect_scripts/FizzBuzz.exp
@@ -48,27 +45,33 @@ expect ci_scripts/expect_scripts/RandomNumbers.exp
4845
$ROC build ./examples/CommandLineArgs/main.roc
4946
expect ci_scripts/expect_scripts/CommandLineArgs.exp
5047

48+
$ROC build ./examples/Commands/main.roc
49+
expect ci_scripts/expect_scripts/Commands.exp
50+
5151
$ROC build ./examples/CommandLineArgsFile/main.roc
5252
expect ci_scripts/expect_scripts/CommandLineArgsFile.exp
5353

54-
$ROC build ./examples/DesugaringTry/main.roc
55-
$ROC test ./examples/DesugaringTry/main.roc
56-
expect ci_scripts/expect_scripts/DesugaringTry.exp
54+
$ROC build ./examples/TryOperatorDesugaring/main.roc
55+
$ROC test ./examples/TryOperatorDesugaring/main.roc
56+
expect ci_scripts/expect_scripts/TryOperatorDesugaring.exp
5757

5858
$ROC build ./examples/Tuples/main.roc
5959
expect ci_scripts/expect_scripts/Tuples.exp
6060

6161
$ROC test ./examples/TowersOfHanoi/Hanoi.roc
6262

63-
$ROC build ./examples/Results/main.roc
64-
expect ci_scripts/expect_scripts/Results.exp
63+
$ROC test ./examples/ErrorHandlingBasic/ErrorHandlingBasic.roc
6564

66-
$ROC build ./examples/ErrorHandling/main.roc
67-
expect ci_scripts/expect_scripts/ErrorHandling.exp
65+
$ROC build ./examples/ErrorHandlingRealWorld/main.roc
66+
expect ci_scripts/expect_scripts/ErrorHandlingRealWorld.exp
6867

6968
$ROC build ./examples/LoopEffect/main.roc
7069
expect ci_scripts/expect_scripts/LoopEffect.exp
7170

71+
$ROC build ./examples/Snake/main.roc
72+
$ROC test ./examples/Snake/main.roc
73+
expect ci_scripts/expect_scripts/Snake.exp
74+
7275
$ROC test ./examples/RecordBuilder/DateParser.roc
7376

7477
$ROC test ./examples/BasicDict/BasicDict.roc

ci_scripts/expect_scripts/Arithmetic.exp

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/expect
2+
3+
# uncomment line below for debugging
4+
# exp_internal 1
5+
6+
set timeout 7
7+
8+
source ./ci_scripts/expect_scripts/shared-code.exp
9+
10+
spawn ./examples/Commands/main
11+
12+
set expected_output [normalize_output {
13+
Hello
14+
\{stderr_utf8_lossy: "", stdout_utf8: "Hi
15+
"\}
16+
BAZ=DUCK
17+
FOO=BAR
18+
XYZ=ABC
19+
cat: non_existent.txt: No such file or directory
20+
Exit code: 1
21+
\{stderr_bytes: \[\], stdout_bytes: \[72, 105, 10\]\}
22+
}]
23+
24+
expect $expected_output {
25+
expect eof {
26+
check_exit_and_segfault
27+
}
28+
}
29+
puts stderr "\nError: output was different from expected value."
30+
exit 1

ci_scripts/expect_scripts/ErrorHandling.exp renamed to ci_scripts/expect_scripts/ErrorHandlingRealWorld.exp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ set timeout 7
77

88
source ./ci_scripts/expect_scripts/shared-code.exp
99

10-
spawn ./examples/ErrorHandling/main "https://www.roc-lang.org" roc.html
10+
set env(HELLO) 1
11+
12+
spawn ./examples/ErrorHandlingRealWorld/main "https://www.roc-lang.org" roc.html
1113

1214
expect "Done\r\n" {
1315
expect eof {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/expect
2+
3+
# uncomment line below for debugging
4+
# exp_internal 1
5+
6+
set timeout 7
7+
8+
source ./ci_scripts/expect_scripts/shared-code.exp
9+
10+
spawn ./examples/Snake/main
11+
12+
expect "Score: 0\r\n" {
13+
14+
# Press 's' key 9 times
15+
for {set i 1} {$i <= 9} {incr i} {
16+
send "s"
17+
18+
expect -re {Score:.*}
19+
}
20+
21+
# This press should make the snake collide with the bottom wall and lead to game over
22+
send "s"
23+
24+
expect -re {.*Game Over.*} {
25+
expect eof {
26+
check_exit_and_segfault
27+
}
28+
}
29+
30+
}
31+
32+
puts stderr "\nExpect script failed: output was different from expected value. uncomment `exp_internal 1` to debug."
33+
exit 1

ci_scripts/expect_scripts/DesugaringTry.exp renamed to ci_scripts/expect_scripts/TryOperatorDesugaring.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set timeout 7
77

88
source ./ci_scripts/expect_scripts/shared-code.exp
99

10-
spawn ./examples/DesugaringTry/main
10+
spawn ./examples/TryOperatorDesugaring/main
1111

1212
expect -exact "(Ok {birth_year: 1990, name: \"Alice\"})\r\n(Ok {birth_year: 1990, name: \"Alice\"})\r\n" {
1313
expect eof {

examples/Arithmetic/README.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)