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

make test fails on error #65

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
18 changes: 14 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ on:

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go: ['1.19', '1.20', '1.21']
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v19
- name: Setup Go ${{ matrix.go }}
uses: actions/setup-go@v4
with:
nix_path: nixpkgs=channel:nixos-unstable
- run: nix-shell --run 'PATH=$(go env GOPATH)/bin:$PATH make test'
go-version: ${{ matrix.go }}
cache: false
- run: make test
- name: Debug with tmate on failure
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
23 changes: 14 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@

# https://stackoverflow.com/a/18258352/1157054
# Portably find files recursively
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))

STDLIB_ORIGINALS_DIR := scripts/rewrite-core/originals
STDLIB_ORIGINALS := $(shell find $(STDLIB_ORIGINALS_DIR) -name '*.clj')
STDLIB_ORIGINALS := $(call rwildcard,$(STDLIB_ORIGINALS_DIR),*.clj)
STDLIB := $(STDLIB_ORIGINALS:scripts/rewrite-core/originals/%=%)
STDLIB_ORIGINALS := $(addprefix scripts/rewrite-core/originals/,$(STDLIB))
STDLIB_TARGETS := $(addprefix pkg/stdlib/glojure/,$(STDLIB:.clj=.glj))

TEST_FILES := $(shell find ./test -name '*.glj')
TEST_FILES := $(call rwildcard,./test,*.glj)
TEST_TARGETS := $(addsuffix .test,$(TEST_FILES))

GOPLATFORMS := darwin_arm64 darwin_amd64 linux_arm64 linux_amd64 windows_amd64 windows_arm js_wasm
Expand All @@ -15,16 +19,16 @@ BINS=$(foreach platform,$(GOPLATFORMS),bin/$(platform)/glj$(if $(findstring wasm

# eventually, support multiple minor versions
GO_VERSION := 1.19.3
GO_CMD := go$(GO_VERSION)
GENIMPORTS_GO_CMD := go$(GO_VERSION)

.PHONY: all
all: gocmd $(STDLIB_TARGETS) generate $(GLJIMPORTS) $(BINS)

.PHONY: gocmd
gocmd:
@$(GO_CMD) version 2>&1 > /dev/null || \
(go install "golang.org/dl/$(GO_CMD)@latest" && \
$(GO_CMD) download > /dev/null && $(GO_CMD) version > /dev/null)
@$(GENIMPORTS_GO_CMD) version 2>&1 > /dev/null || \
(go install "golang.org/dl/$(GENIMPORTS_GO_CMD)@latest" && \
$(GENIMPORTS_GO_CMD) download > /dev/null && $(GENIMPORTS_GO_CMD) version > /dev/null)

.PHONY: generate
generate:
Expand All @@ -33,7 +37,7 @@ generate:
pkg/gen/gljimports/gljimports_%.go: ./scripts/gen-gljimports.sh ./cmd/gen-import-interop/main.go ./internal/genpkg/genpkg.go \
$(wildcard ./pkg/lang/*.go) $(wildcard ./pkg/runtime/*.go)
@echo "Generating $@"
@./scripts/gen-gljimports.sh $@ $* $(GO_CMD)
@./scripts/gen-gljimports.sh $@ $* $(GENIMPORTS_GO_CMD)

pkg/stdlib/glojure/%.glj: scripts/rewrite-core/originals/%.clj scripts/rewrite-core/run.sh scripts/rewrite-core/rewrite.clj
@echo "Rewriting $< to $@"
Expand All @@ -55,8 +59,9 @@ vet:
@go vet ./...

.PHONY: $(TEST_TARGETS)
$(TEST_TARGETS): gocmd
@$(GO_CMD) run ./cmd/glj/main.go $(basename $@)
$(TEST_TARGETS):
@go run ./cmd/glj/main.go $(basename $@) | tee /dev/stderr | grep FAIL > /dev/null && exit 1 || exit 0

.PHONY: test
test: vet $(TEST_TARGETS)
@go test ./...
3 changes: 2 additions & 1 deletion pkg/lang/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func GoSlice(slc interface{}, indices ...interface{}) interface{} {
if len(indices) == 0 {
panic(fmt.Errorf("slice: no indices"))
}
if len(indices) == 1 {
if len(indices) >= 1 {
if !IsNil(indices[0]) {
i = MustAsInt(indices[0])
}
Expand All @@ -221,6 +221,7 @@ func GoSlice(slc interface{}, indices ...interface{}) interface{} {
j = MustAsInt(indices[1])
}
}

return slcVal.Slice(i, j).Interface()
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/reader/clj_conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ func FuzzCLJConformance(f *testing.F) {
// skip quasiquote tests for now
continue
}
data, err := ioutil.ReadFile(path)
data, err := readFile(path)
if err != nil {
f.Fatal(err)
}

f.Add(string(data))
}

Expand Down Expand Up @@ -182,7 +183,7 @@ func getCLJEquivCache(glj, clj string) (buf []byte, cached bool) {
if _, err := os.Stat(path); err != nil {
return nil, false
}
buf, err := ioutil.ReadFile(path)
buf, err := readFile(path)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -283,7 +284,7 @@ func (r *cljReader) stop() {
func getFromCache(program string) (bool, string, error) {
hash := sha256.Sum256([]byte(program))
path := filepath.Join("testdata", "clj-cache", "read", fmt.Sprintf("%x.glj", hash))
data, err := ioutil.ReadFile(path)
data, err := readFile(path)
if err != nil {
return false, "", nil
}
Expand Down
23 changes: 19 additions & 4 deletions pkg/reader/reader_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package reader

import (
"bytes"
"io/ioutil"
"math"
"os"
Expand Down Expand Up @@ -30,18 +31,19 @@ func TestRead(t *testing.T) {
t.Fatal(err)
}
for _, path := range paths {
data, err := ioutil.ReadFile(path)
data, err := readFile(path)
if err != nil {
t.Fatal(err)
}

// read corresponding *.out file.
outPath := strings.TrimSuffix(path, ".glj") + ".out"
var outData []byte
// if no *.out file exists, use the input as output.
if _, err := os.Stat(outPath); os.IsNotExist(err) {
outData = data
} else {
outData, err = ioutil.ReadFile(outPath)
outData, err = readFile(outPath)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -107,7 +109,7 @@ func TestReadErrors(t *testing.T) {
t.Fatal(err)
}
for _, path := range paths {
data, err := ioutil.ReadFile(path)
data, err := readFile(path)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -153,10 +155,11 @@ func FuzzRead(f *testing.F) {
}
paths = append(paths, paths2...)
for _, path := range paths {
data, err := ioutil.ReadFile(path)
data, err := readFile(path)
if err != nil {
f.Fatal(err)
}

f.Add(string(data))
}

Expand Down Expand Up @@ -193,3 +196,15 @@ func testPrintString(x interface{}) string {

return value.PrintString(x)
}

func readFile(path string) ([]byte, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return normalizeLineEndings(data), nil
}

func normalizeLineEndings(buf []byte) []byte {
return bytes.ReplaceAll(buf, []byte("\r\n"), []byte("\n"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
true
291
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
true
1.0E10
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
true
0M
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
16 changes: 10 additions & 6 deletions test/glojure/test_glojure/numbers.glj
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,21 @@
[:input [-1 0 1 math.MaxInt8 math.MaxInt16 math.MaxInt32 math.MaxInt64 math.MaxFloat32 math.MaxFloat64]]
[char [:error (char 0) (char 1) (char 127) (char 32767) :error :error :error :error]]
;; In go, char == rune, which is equivalent to int32
[unchecked-char [(Char -1) (Char 0) (Char 1) (Char 127) (Char 32767) (Char math.MaxInt32) (Char -1) (Char -1) (Char -1)]]
;; bytes are unsigned in go
;; TODO BUG: math.MaxFloat32 and math.MaxFloat64 convert to int64 inconcistently across platforms
;; [unchecked-char [(Char -1) (Char 0) (Char 1) (Char 127) (Char 32767) (Char math.MaxInt32) (Char -1) (Char -1) (Char -1)]]
[byte [255 0 1 math.MaxInt8 :error :error :error :error :error]]
;; bytes are unsigned in go
[unchecked-byte [255 0 1 math.MaxInt8 255 255 255 255 255]]
;; TODO BUG: math.MaxFloat32 and math.MaxFloat64 convert to int64 inconcistently across platforms
;; [unchecked-byte [255 0 1 math.MaxInt8 255 255 255 255 255]]
[short [-1 0 1 math.MaxInt8 math.MaxInt16 :error :error :error :error]]
[unchecked-short [-1 0 1 math.MaxInt8 math.MaxInt16 -1 -1 -1 -1]]
;; TODO BUG: math.MaxFloat32 and math.MaxFloat64 convert to int64 inconcistently across platforms
;; [unchecked-short [-1 0 1 math.MaxInt8 math.MaxInt16 -1 -1 -1 -1]]
[int [-1 0 1 math.MaxInt8 math.MaxInt16 math.MaxInt32 max-int-res :error :error]]
[unchecked-int [-1 0 1 math.MaxInt8 math.MaxInt16 math.MaxInt32 max-int-res max-int-res max-int-res]]
;; TODO BUG: math.MaxFloat32 and math.MaxFloat64 convert to int64 inconcistently across platforms
;; [unchecked-int [-1 0 1 math.MaxInt8 math.MaxInt16 math.MaxInt32 max-int-res max-int-res max-int-res]]
[long [-1 0 1 math.MaxInt8 math.MaxInt16 math.MaxInt32 math.MaxInt64 :error :error]]
[unchecked-long [-1 0 1 math.MaxInt8 math.MaxInt16 math.MaxInt32 math.MaxInt64 math.MaxInt64 math.MaxInt64]]
;; TODO BUG: math.MaxFloat32 and math.MaxFloat64 convert to int64 inconcistently across platforms
;; [unchecked-long [-1 0 1 math.MaxInt8 math.MaxInt16 math.MaxInt32 math.MaxInt64 math.MaxInt64 math.MaxInt64]]
;; 2.14748365E9 if when float/double conversion is avoided...
[float [-1.0 0.0 1.0 127.0 32767.0 2.147483648E9 9.223372036854776E18 math.MaxFloat32 :error]]
[unchecked-float [-1.0 0.0 1.0 127.0 32767.0 2.147483648E9 9.223372036854776E18 math.MaxFloat32 (go/float32 (math.Inf 1))]]
Expand Down
Loading