Skip to content

Commit

Permalink
Make all tests pass (#6)
Browse files Browse the repository at this point in the history
* Fix tests for stdout

* Significant progess on official test suite

* Pass all tests

* Fix linting errors

* Refactor CI

* Add benchmark
  • Loading branch information
fpotier authored Aug 17, 2024
1 parent aa690bc commit e5c77c5
Show file tree
Hide file tree
Showing 138 changed files with 1,261 additions and 347 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: go
on:
push:
branches:
- master
pull_request:
jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: stable
cache-dependency-path: go.sum

- name: Generate code
run: go generate ./...
working-directory: go

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
install-mode: goinstall
version: latest
working-directory: go
args: --config="${GITHUB_WORKSPACE}/go/.golangci.yaml"

test:
name: test
runs-on: ubuntu-latest
defaults:
run:
working-directory: go
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: stable
cache-dependency-path: go.sum

- name: Install dependencies
run: go mod tidy

- name: Generate code
run: go generate ./...

- name: Compile
run: go build -v ./...

- name: Run tests
run: go test -v ./...

benchmark:
name: benchmark
runs-on: ubuntu-latest
defaults:
run:
working-directory: go
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: stable
cache-dependency-path: go.sum

- name: Generate code
run: go generate ./...

- name: Run benchmark
run: go test ./cmd/glox -bench=. -count 5 -run=^# -timeout 30m | tee output.txt

- name: Download previous benchmark data
uses: actions/cache@v4
with:
path: ./cache
key: ${{ runner.os }}-benchmark

- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
tool: 'go'
output-file-path: go/output.txt
external-data-json-path: ./cache/benchmark-data.json
fail-on-alert: true
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-on-alert: true
24 changes: 0 additions & 24 deletions .github/workflows/golangci-lint.yaml

This file was deleted.

46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ The test suite in `test/official_tests` comes from the [original implementation]

| Feature | Implementation |
| -------------------- | ------------------ |
| assignment | :x: |
| benchmark | :x: |
| assignment | :white_check_mark: |
| benchmark | :white_check_mark: |
| block | :white_check_mark: |
| bool | :white_check_mark: |
| call | :x: |
| class | :x: |
| closure | :x: |
| call | :white_check_mark: |
| class | :white_check_mark: |
| closure | :white_check_mark: |
| comments | :white_check_mark: |
| constructor | :x: |
| field | :x: |
| for | :x: |
| function | :x: |
| if | :x: |
| inheritance | :x: |
| constructor | :white_check_mark: |
| field | :white_check_mark: |
| for | :white_check_mark: |
| function | :white_check_mark: |
| if | :white_check_mark: |
| inheritance | :white_check_mark: |
| limit | :x: |
| logical operator | :white_check_mark: |
| method | :x: |
| method | :white_check_mark: |
| nil | :white_check_mark: |
| number | :x: |
| operator | :x: |
| print | :x: |
| regression | :x: |
| return | :x: |
| scanning | :x: |
| string | :x: |
| super | :x: |
| this | :x: |
| variable | :x: |
| while | :x: |
| operator | :white_check_mark: |
| print | :white_check_mark: |
| regression | :white_check_mark: |
| return | :white_check_mark: |
| scanning | :white_check_mark: |
| string | :white_check_mark: |
| super | :white_check_mark: |
| this | :white_check_mark: |
| variable | :white_check_mark: |
| while | :white_check_mark: |
| empty file | :white_check_mark: |
| precedence | :white_check_mark: |
| unexpected character | :x: |
| unexpected character | :white_check_mark: |

</details>
1 change: 1 addition & 0 deletions go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
generated*
16 changes: 14 additions & 2 deletions go/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ run:
timeout: 30m
tests: true
output:
format: colored-line-number
formats:
- format: colored-line-number
path: stderr
print-issued-lines: true
linters-settings:
gomnd:
Expand All @@ -27,4 +29,14 @@ linters:
- nlreturn
- nonamedreturns
- varnamelen
- wsl
- wrapcheck
- wsl
issues:
exclude-rules:
- path: .*generated-errors\.go
linters:
- goconst
- gofmt
- goimports
- gosimple
- perfsprint
38 changes: 38 additions & 0 deletions go/cmd/code-generator/errors_template.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package {{ .Package }}

{{- if eq (len .Imports) 1 }}
import "{{ index .Imports 0 }}"
{{- else }}
import (
{{- range .Imports }}
"{{ . }}"
{{- end }}
)
{{- end }}

{{ range .Types}}
type {{ .Name }} struct {
line int
{{ range .Fields }}{{ .Name }} {{ .Type }}
{{ end }}
}

func New{{ .Name }}(line int{{ range .Fields }}, {{ .Name }} {{ .Type }}{{ end }}) *{{ .Name }} {
return &{{ .Name }}{
line: line,
{{ range .Fields }}{{ .Name }}: {{ .Name }}, {{ end }}
}
}

func (e {{ .Name }}) Line() int {
return e.line
}

func (e {{ .Name }}) Kind() string {
return "{{ $.ErrorKind }}"
}

func (e {{ .Name }}) Message() string {
return fmt.Sprintf("{{ .Message }}", {{ range .Fields }}e.{{ .Name }}, {{ end }})
}
{{ end }}
Loading

0 comments on commit e5c77c5

Please sign in to comment.