Skip to content

Commit

Permalink
automatic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei.winitzki committed Nov 29, 2023
1 parent d096f8b commit 2113768
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
architecture: x64
java-package: jdk
java-version: "${{ matrix.java}}"
- run: "sbt -DJDK_VERSION=${{ matrix.java}} \"++${{ matrix.scala}} test\""
- run: "bash run_sbt.sh -DJDK_VERSION=${{ matrix.java}} \"++${{ matrix.scala}} test\""
strategy:
matrix:
java:
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
architecture: x64
java-package: jdk
java-version: '17'
- run: sbt scalafmtCheckAll scalafmtSbtCheck
- run: bash reformat_all_code.sh
name: build_and_test
on:
pull_request: {}
Expand Down
3 changes: 1 addition & 2 deletions chapter01/worksheets/solution1.6.1.1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
def staggeredFactorial(n: Int): Int = (n to 1 by -2).product

// scala> staggeredFactorial(8)
// res7: Int = 384
assert(staggeredFactorial(8) == 384)
1 change: 1 addition & 0 deletions chapter02/worksheets/solution2.1.7.3_SW.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ val b: List[(String, Boolean)] = names.zip(a)
val c: List[(String, Boolean)] = b.filter { case (x, y) => y }
val d: List[String] = c.map { case (x, y) => x }

assert(d == List("Joe", "Mary"))
2 changes: 1 addition & 1 deletion chapter02/worksheets/solution2.1.7.3_as_function_SW.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ val a: List[Boolean] = List(true, false, true)
def selectTrueOperatorSyntax(names: List[String], flags: List[Boolean]): List[String] =
names zip flags filter (_._2) map (_._1)

selectTrueOperatorSyntax(names, a)
assert(selectTrueOperatorSyntax(names, a) == List("Joe", "Mary"))

// scala> :load solution2.1.7.3_as_function_SW.scala
// Loading solution2.1.7.3_as_function_SW.scala...
Expand Down
2 changes: 1 addition & 1 deletion github-scala-build-and-test.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ in GithubActions.Workflow::{
# [ GithubActions.steps.actions/setup-java
{ java-version = "\${{ matrix.java}}" }
, GithubActions.steps.run
{ run = "sbt -DJDK_VERSION=\${{ matrix.java}} \"++\${{ matrix.scala}} test\"" }
{ run = "bash run_sbt.sh -DJDK_VERSION=\${{ matrix.java}} \"++\${{ matrix.scala}} test\"" }
]
}
}
Expand Down
35 changes: 35 additions & 0 deletions run_sbt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copy solutions to source files.
for chapter in chapter[0-9][0-9]; do

cat <<EOF1 > $chapter/src/test/scala/sofp/unit/Solutions.scala
package sofp.unit
import com.eed3si9n.expecty.Expecty.expect
import munit.FunSuite
class WorksheetsTest extends FunSuite {
EOF1
for worksheet in $chapter/worksheets/*.scala; do

cat <<EOF2 >> $chapter/src/test/scala/sofp/unit/Solutions.scala
test("verify $worksheet") {
EOF2

cat $worksheet >> $chapter/src/test/scala/sofp/unit/Solutions.scala

cat <<EOF3 >> $chapter/src/test/scala/sofp/unit/Solutions.scala
}
EOF3

done

cat <<EOF4 >> $chapter/src/test/scala/sofp/unit/Solutions.scala
}
EOF4

done

sbt "$@"

0 comments on commit 2113768

Please sign in to comment.