diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..3e283e2 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,35 @@ +name: "Run Tests" + +on: + pull_request: + push: + branches: + - main + +jobs: + test: + runs-on: ubuntu-22.04 + name: Run Tests + steps: + - name: Clone wake-extras + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Download wake + run: wget https://github.com/sifive/wake/releases/download/v39.1.0/ubuntu-22-04-wake_39.1.0-1_amd64.deb + + - name: Install wake + run: sudo apt-get install ./ubuntu-22-04-wake_39.1.0-1_amd64.deb + + - name: Initialize wake + run: wake --init . + + - name: Typecheck wake + run: wake -x 'Unit' + + - name: Check formatting + run: wake-format --dry-run --auto + + - name: Run tests + run: ./tests/test.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a237a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/**/wake.db* +/**/wake.log diff --git a/json.wake b/json.wake index 0a77b6e..878ebdb 100644 --- a/json.wake +++ b/json.wake @@ -1,7 +1,7 @@ package json from wake import _ -from utils import prefixError +from result import prefixError from query import _ # Anyone who depends on json will also diff --git a/result.wake b/result.wake new file mode 100644 index 0000000..fd6e5fe --- /dev/null +++ b/result.wake @@ -0,0 +1,17 @@ +package result + +# When `result` is Fail, prefixes the internal error message with `prefix` +# +# Parameters: +# - `prefix`: The message to prepend to `result` +# - `result`: The Result which may be prepended to +# +# Examples: +# ``` +# prefixError "foo" (Pass 123) -> Pass 123 +# prefixError "foo" (Fail (Error "bar" stack)) => Fail (Error "foobar" stack) +# ``` +export def prefixError (prefix: String): (result: Result a Error) => Result a Error = match _ + Pass r -> Pass r + Fail (Error msg stack) -> Fail (Error "{prefix}{msg}" stack) + diff --git a/tests/query.wake b/tests/query.wake new file mode 100644 index 0000000..a40502b --- /dev/null +++ b/tests/query.wake @@ -0,0 +1,10 @@ +package tests + +from wake import _ +from query import _ + +export def runQueryTests _ = + require 4, Nil = single 4 + else failWithError "Unexpected value for single" + + Pass Unit diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 0000000..df404bb --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,5 @@ +#! /bin/bash + +set -ex + +wake --in tests runQueryTests