Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Run separate cairo integration test files as a separate Go test #392

Merged
merged 9 commits into from
May 13, 2024
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUq
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o=
github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Set to run some specific file tests (ex. fib.cairo,alloc.cairo)
INTEGRATION_TESTS_FILTERS=
xiaolou86 marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 23 additions & 2 deletions integration_tests/cairozero_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/NethermindEth/cairo-vm-go/pkg/vm"
"github.com/consensys/gnark-crypto/ecc/stark-curve/fp"
"github.com/joho/godotenv"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -19,8 +20,16 @@ func TestCairoZeroFiles(t *testing.T) {
testFiles, err := os.ReadDir(root)
require.NoError(t, err)

// Get the filter value from the environment variable
// filter is for debugging purposes
filter := ""
err = godotenv.Load("./.env")
if err != nil {
t.Errorf("Error loading .env file: %v", err)
}

filtersRaw := os.Getenv("INTEGRATION_TESTS_FILTERS")
filtersRaw = strings.TrimSpace(filtersRaw)
filters := strings.Split(filtersRaw, ",")
xiaolou86 marked this conversation as resolved.
Show resolved Hide resolved

for _, dirEntry := range testFiles {
if dirEntry.IsDir() || isGeneratedFile(dirEntry.Name()) {
Expand All @@ -29,9 +38,21 @@ func TestCairoZeroFiles(t *testing.T) {

path := filepath.Join(root, dirEntry.Name())

if !strings.Contains(path, filter) {
matched := false
if len(filters) == 0 {
matched = true
} else {
for _, filter := range filters {
if strings.Contains(dirEntry.Name(), strings.TrimSpace(filter)) {
matched = true
break
}
}
}
if !matched {
continue
}

t.Logf("testing: %s\n", path)

compiledOutput, err := compileZeroCode(path)
Expand Down