Skip to content

Commit 7cb423e

Browse files
committed
Converted to zsh and improved handling of error cases and arg lists for the main routines. Added a description of the check-*.sh scripts to the README.
Signed-off-by: Dean Wampler <[email protected]>
1 parent 1d836d8 commit 7cb423e

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# "Programming Scala, 3rd Edition" Code Examples
22

3+
<!--
34
[![Join the chat at https://gitter.im/deanwampler/programming-scala-book-code-examples](https://badges.gitter.im/deanwampler/programming-scala-book-code-examples.svg)](https://gitter.im/deanwampler/programming-scala-book-code-examples?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5+
-->
46
[![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org)
57

68
* [Dean Wampler](mailto:[email protected])
7-
* Dean Wampler's [Bluesky](https://bsky.app/profile/deanwampler.bsky.social), [Mastodon](https://discuss.systems/@deanwampler), or [LinkedIn](https://www.linkedin.com/in/deanwampler/) accounts.
9+
* Dean Wampler's [Bluesky](https://bsky.app/profile/deanwampler.bsky.social), [Mastodon](https://discuss.systems/@deanwampler), and [LinkedIn](https://www.linkedin.com/in/deanwampler/) accounts.
810
* [My Book Page](http://programming-scala.org)
911
* [Blog about Scala 3](https://medium.com/scala-3)
1012

@@ -173,6 +175,17 @@ $
173175
> [!NOTE]
174176
> The `--` argument separator is required for Scala 3.5.0 and later. It is not used for Scala 3.4.X and earlier.
175177
178+
### Testing the Scala Scripts and "Mains"
179+
180+
There are a lot of _script_ files under `src/script/scala/...`, which are used in the book as suggestions to try in the console as you are reading the book. However, they are hard to test in the usual way. Similarly, there are many `@main` routines and they are also not covered by tests. So, to "semi-automate" testing them, try the following two `zsh` scripts, both of which take a long time to run:
181+
182+
```shell
183+
check-scripts.sh
184+
check-mains.sh
185+
```
186+
187+
Both have `--help` options to see what options they accept. Both do their best to check that the output is expected, but a complication is the fact that many of the Scala scripts and "mains" have deliberate errors for illustrative purposes. The `check-*.sh` scripts attempt to compensate for this, for example by knowing which scripts should fail and allowing them to fail "successfully", but to be _absolutely certain_ they are running correctly, it is really necessary to visually inspect the saved output from the runs (as described in console output of the `check-*.sh`) to see if the behavior _looks_ correct.
188+
176189
## Feedback
177190

178191
I welcome feedback on the Book and these examples. Please post comments, corrections, etc. to one of the following places:
@@ -185,6 +198,8 @@ There is also my dedicated site for the book where occasional updates, clarifica
185198

186199
## A Little History
187200

201+
Some milestones (but probably not all of them...).
202+
188203
| Key Dates | Description |
189204
| :----------------- | :---------- |
190205
| August 11, 2014 | 2nd edition examples |
@@ -202,5 +217,6 @@ There is also my dedicated site for the book where occasional updates, clarifica
202217
| September 15, 2024 | Scala 3.5.0 changes, e.g. the [new Scala CLI](https://docs.scala-lang.org/sips/scala-cli.html). |
203218
| December 21, 2024 | Scala 3.6.2 changes, supporting new syntax options. |
204219
| June 17, 2025 | Scala 3.7.X breaking changes and fixed some old bugs in some of the "scripts". |
220+
| September 20, 2025 | Scala 3.7.3 breaking changes. Yes, a "patch" release, but in fairness, triggered by my strict compiler flags. |
205221

206222

check-mains.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env zsh
22

33
out_root="target/main-tests"
44
out_ext="out"
@@ -53,7 +53,7 @@ def_mains=(
5353
progscala3.meta.TryStaging
5454
progscala3.meta.TryTracer
5555
progscala3.meta.TryUsingClassTagViews
56-
"progscala3.meta.performance.InlinePerf true 10"
56+
progscala3.meta.performance.InlinePerf
5757
progscala3.objectsystem.CommandArgs
5858
progscala3.objectsystem.JavaArrays
5959
progscala3.objectsystem.objects.TryPerson
@@ -67,7 +67,16 @@ def_mains=(
6767
progscala3.typesystem.payroll.TryPhantomTypesPipeline
6868
progscala3.typesystem.selftype.TryButtonSubjectObserver
6969
)
70-
expected_errors_in=()
70+
71+
declare -A mains_args
72+
mains_args["progscala3.meta.performance.InlinePerf"]="true 10"
73+
mains_args["progscala3.objectsystem.CommandArgs"]="--help"
74+
75+
expected_errors_in=(
76+
progscala3.meta.TryInvariant
77+
progscala3.meta.TryInvariant1
78+
progscala3.objectsystem.JavaArrays
79+
)
7180

7281
error() {
7382
echo "ERROR: $@"
@@ -165,7 +174,7 @@ count_problem() {
165174
}
166175

167176
report() {
168-
let status=$1
177+
let run_status=$1
169178
main=$2
170179
out=$3
171180
for skip in ${expected_errors_in[@]}
@@ -177,7 +186,7 @@ report() {
177186
fi
178187
done
179188
let error_count=0
180-
if [[ $status -ne 0 ]]
189+
if [[ $run_status -ne 0 ]]
181190
then
182191
echo "ERROR: $main failed! ($out)"
183192
let error_count+=1
@@ -202,10 +211,10 @@ check() {
202211
if [[ -z "$NOOP" ]]
203212
then
204213
mkdir -p $(dirname "$out")
205-
TERM=dumb sbt "runMain $main $@" > "$out"
214+
TERM=dumb sbt "runMain $main $mains_args[\"$main\"] $@" > "$out"
206215
else
207216
$NOOP mkdir -p $(dirname $out)
208-
$NOOP "TERM=dumb sbt runMain $main $@ > $out"
217+
$NOOP "TERM=dumb sbt runMain $main $mains_args[\"$main\"] $@ > $out"
209218
fi
210219
fi
211220
$NOOP report $? "$main" "$out"

check-scripts.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env zsh
22

33
default_dirs=( "src/script/scala" )
44
out_root="target/script-tests"
@@ -173,7 +173,7 @@ count_problem() {
173173
}
174174

175175
report() {
176-
let status=$1
176+
let run_status=$1
177177
script=$2
178178
out=$3
179179
for skip in ${expected_errors_in[@]}
@@ -185,7 +185,7 @@ report() {
185185
fi
186186
done
187187
let error_count=0
188-
if [[ $status -ne 0 ]]
188+
if [[ $run_status -ne 0 ]]
189189
then
190190
echo "ERROR: $script failed! ($out)"
191191
let error_count+=1

0 commit comments

Comments
 (0)