diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e2a57dd..b966c65d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,6 +40,34 @@ jobs: - name: Test as root, without cgo, and with busybox run: docker run -v="$PWD:/pwd" -w=/pwd -e=CGO_ENABLED=0 golang:1.22.0-alpine go test ./... + test-tinygo: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Tinygo + uses: acifani/setup-tinygo@v2 + with: + tinygo-version: 0.32.0 + + - name: Create temporary main package + run: | + mkdir _tinygo && cat< _tinygo/main.go + package main + + import ( + _ "mvdan.cc/sh/v3/expand" + _ "mvdan.cc/sh/v3/interp" + _ "mvdan.cc/sh/v3/syntax" + ) + + func main() {} + EOF + + - name: Build with Tinygo natively + run: tinygo build -o /dev/null ./_tinygo + - name: Build with Tinygo on WASM + run: tinygo build -o /dev/null -target wasm ./_tinygo + docker: name: Build and test Docker images # Only deploy if previous stages pass. diff --git a/internal/tinygostub/samefile.go b/internal/tinygostub/samefile.go new file mode 100644 index 00000000..3bbe27ff --- /dev/null +++ b/internal/tinygostub/samefile.go @@ -0,0 +1,10 @@ +//go:build !(tinygo && wasm) + +package tinygostub + +import "os" + +// SameFile calls [os.SameFile]. +func SameFile(fi1, fi2 os.FileInfo) bool { + return os.SameFile(fi1, fi2) +} diff --git a/internal/tinygostub/samefile_tinygo_wasm.go b/internal/tinygostub/samefile_tinygo_wasm.go new file mode 100644 index 00000000..13a374be --- /dev/null +++ b/internal/tinygostub/samefile_tinygo_wasm.go @@ -0,0 +1,10 @@ +//go:build tinygo && wasm + +package tinygostub + +import "os" + +// SameFile returns false. +func SameFile(fi1, fi2 os.FileInfo) bool { + return false +} diff --git a/interp/test.go b/interp/test.go index 3f8ffca7..a6f441d6 100644 --- a/interp/test.go +++ b/interp/test.go @@ -13,6 +13,7 @@ import ( "golang.org/x/term" "mvdan.cc/sh/v3/expand" + "mvdan.cc/sh/v3/internal/tinygostub" "mvdan.cc/sh/v3/syntax" ) @@ -88,7 +89,7 @@ func (r *Runner) binTest(ctx context.Context, op syntax.BinTestOperator, x, y st if err1 != nil || err2 != nil { return false } - return os.SameFile(info1, info2) + return tinygostub.SameFile(info1, info2) case syntax.TsEql: return atoi(x) == atoi(y) case syntax.TsNeq: