Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
fix huff-tests-action
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Oct 21, 2022
1 parent 12fd85a commit 63a2144
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 28 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
with-location: "tests" # defaults to "src"
with-extension: "*.t.huff" # default
with-format: "table" # default, either ["list", "table", "json"]
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand Down
23 changes: 12 additions & 11 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
5 changes: 5 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[profile.default]
out = 'out'
libs = ['lib']
ffi = true
fuzz_runs = 1000
16 changes: 11 additions & 5 deletions hufftests.sh
Original file line number Diff line number Diff line change
@@ -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[@]}"

54 changes: 54 additions & 0 deletions tests/test.t.huff
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/// @title Test
/// @author asnared <https://github.com/abigger87>
/// @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:
}

0 comments on commit 63a2144

Please sign in to comment.