From 63a21444cc5102ea7c615e9216ae2440cf4e86aa Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Fri, 21 Oct 2022 11:47:33 -0500 Subject: [PATCH] fix huff-tests-action --- .github/workflows/test.yaml | 25 +++++++++++++++++ README.md | 26 +++++++++--------- action.yaml | 23 ++++++++-------- foundry.toml | 5 ++++ hufftests.sh | 16 +++++++---- tests/test.t.huff | 54 +++++++++++++++++++++++++++++++++++++ 6 files changed, 121 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/test.yaml create mode 100644 foundry.toml create mode 100644 tests/test.t.huff diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..86271dd --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,25 @@ +name: ci + +on: [push] + +jobs: + name: Tests in Huff + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + - name: Install Huff + uses: huff-language/huff-toolchain@v2 + with: + version: nightly + - name: Huff Tests + uses: huff-language/huff-tests@v3.0.0 + with: + with-location: "tests" # defaults to "src" + with-extension: "*.t.huff" # default + with-format: "table" # default, either ["list", "table", "json"] diff --git a/README.md b/README.md index 9a0bd7d..f5f98ce 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ -# Huff Tests Github Action +## Huff Tests Github Action Github Action that: 1. Checks out your local repository 2. Installs huffc -3. Runs Huff tests on any files named \*.t.huff +3. Runs Huff tests on any files that match the default or specified parameters: -Optionally: - -- Install Foundry and run Forge tests if the `with-forge-tests` option is set to true +- 1. Named `*.t.huff` or the specified extension +- 2. Located in `src` or the specified directory +- 3. With the specified output or `list` ## Example Workflow @@ -25,17 +25,19 @@ jobs: - name: Run Huff Tests uses: huff-language/huff-tests-action@v2 with: - # Optional - with-forge-tests: false - test-extension: ".t.huff" + # Below arguments are optional: + with-location: "tests" # Defaults to "src" + with-extension: "*.t.huff" # Defaults to "*.t.huff*" + with-format: "table" # Defaults to "list" ``` ## Inputs -| **Name** | **Required** | **Description** | **Type** | -| ------------------ | ------------ | ----------------------------------------------------------------------- | -------- | -| `test-extension` | False | The extension of your huff tests, e.g. `t.huff` or `.poggers.huff`. | string | -| `with-forge-tests` | False | Installs foundry and runs `forge test -vvv` along side your huff tests. | boolean | +| **Name** | **Required** | **Description** | **Type** | +| ---------------- | ------------ | ---------------------------------------------------------------------- | -------- | +| `with-extension` | False | The extension of your huff tests, e.g. `t.huff` or `.poggers.huff`. | string | +| `with-location` | False | The location of your huff test files, e.g. `src` or `contracts` | string | +| `with-format` | False | The format of your huff test output. One of ["list", "table", "json"]. | string | ## Contributing diff --git a/action.yaml b/action.yaml index 7723b72..259da11 100644 --- a/action.yaml +++ b/action.yaml @@ -1,13 +1,19 @@ --- -description: "Run all Huff test files in the repository" +description: "Run Native Huff-language Tests" inputs: - test-extension: + with-location: + default: src + description: "The location of your huff test files" + required: false + with-extension: default: .t.huff description: "The File extension of your Huff test files" required: false - with-forge-tests: - default: false + with-format: + default: list + description: "The format of your huff test output" required: false + name: "Huff Tests" runs: steps: @@ -29,12 +35,7 @@ runs: - run: 'echo "${{ github.action_path }}" >> $GITHUB_PATH' shell: bash - - if: inputs.with-forge-tests == true - name: "Running Forge tests" - run: "forge test -vvv" - shell: bash - - - name: "Running Huff tests" - run: "bash hufftests.sh ${{ inputs.test-extension }}" + - name: "Running Huff Tests" + run: "bash hufftests.sh ${{ inputs.with-extension }} ${{ inputs.with-location }} ${{ inputs.with-format }}" shell: bash using: composite diff --git a/foundry.toml b/foundry.toml new file mode 100644 index 0000000..72a34df --- /dev/null +++ b/foundry.toml @@ -0,0 +1,5 @@ +[profile.default] +out = 'out' +libs = ['lib'] +ffi = true +fuzz_runs = 1000 diff --git a/hufftests.sh b/hufftests.sh index 2ef7b9e..56dd275 100644 --- a/hufftests.sh +++ b/hufftests.sh @@ -1,11 +1,17 @@ #!/bin/bash -SOURCE=$(pwd) -files=`find "$SOURCE" -type f -name "*$1"` -for i in "${files[@]}" -do - huffc $i test +location=${1:-"src"} +extension=${2:-"*.t.huff"} +format=${3:-"list"} + +files=`find $location -type f -name "$extension"` + +set -- junk $files +shift +for word; do + huffc $word test --format $format done + echo "Tests ran on" printf '%s\n' "${files[@]}" diff --git a/tests/test.t.huff b/tests/test.t.huff new file mode 100644 index 0000000..2bcb29a --- /dev/null +++ b/tests/test.t.huff @@ -0,0 +1,54 @@ +/// @title Test +/// @author asnared +/// @notice Example huff tests + + +/// @notice Returns an incorrect sum +#define macro BAD_SUM() = takes (2) returns (1) { + // Input Stack: [a, b] + sub // [sub] +} + + +/// @notice The example summing macro +#define macro SUM() = takes (2) returns (1) { + // Input Stack: [a, b] + add // [sum] +} + +/// @notice Helper macro to test two values are equal +#define macro TEST_ASSERT_EQ() = { + eq continue jumpi + 0x00 dup1 revert + continue: +} + +/// @notice Tests adding numbers +#define test TEST_SUM() = { + 0x01 // [1] + 0x01 // [1, 1] + SUM() // [sum] + 0x02 // [2, sum] + TEST_ASSERT_EQ() + continue jump + + fail: + 0x00 dup1 revert + continue: +} + +/// @notice Tests bad summation of numbers +#define test FAIL_TEST_BAD_SUM() = { + 0x01 // [1] + 0x01 // [1, 1] + BAD_SUM() // [sum] + 0x02 // [2, sum] + TEST_ASSERT_EQ() + continue jump + + // We should fail + fail: + 0x00 dup1 revert + continue: +} +