Skip to content

Commit

Permalink
Convert assert.go back to assert.star and bump Go version to 1.16. (
Browse files Browse the repository at this point in the history
#453)

* Convert `assert.go` back to `assert.star`.

* Add newline to `assert.star`.

* Add back `DataFile` public API.
  • Loading branch information
yuxincs authored Jan 18, 2023
1 parent fae38c8 commit ddd531c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module go.starlark.net

go 1.13
go 1.16

require (
github.com/chzyer/logex v1.1.10 // indirect
Expand Down
7 changes: 0 additions & 7 deletions starlarktest/assert.go → starlarktest/assert.star
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
package starlarktest

// assertStar contains the logical data file assert.star.
// TODO(adonovan): move it back into an actual file,
// when fs.Embed is more than two releases old.
const assertStar = `
# Predeclared built-ins for this module:
#
# error(msg): report an error in Go's test framework without halting execution.
Expand Down Expand Up @@ -55,4 +49,3 @@ assert = module(
contains = _contains,
fails = _fails,
)
`
13 changes: 7 additions & 6 deletions starlarktest/starlarktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package starlarktest // import "go.starlark.net/starlarktest"

import (
_ "embed"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -50,9 +51,11 @@ func GetReporter(thread *starlark.Thread) Reporter {
}

var (
once sync.Once
assert starlark.StringDict
assertErr error
once sync.Once
assert starlark.StringDict
//go:embed assert.star
assertFileSrc string
assertErr error
)

// LoadAssertModule loads the assert module.
Expand All @@ -66,10 +69,8 @@ func LoadAssertModule() (starlark.StringDict, error) {
"module": starlark.NewBuiltin("module", starlarkstruct.MakeModule),
"_freeze": starlark.NewBuiltin("freeze", freeze),
}
// TODO(adonovan): embed the file using embed.FS when we can rely on go1.16,
// and make the apparent filename reference that file.
thread := new(starlark.Thread)
assert, assertErr = starlark.ExecFile(thread, "builtins/assert.star", assertStar, predeclared)
assert, assertErr = starlark.ExecFile(thread, "assert.star", assertFileSrc, predeclared)
})
return assert, assertErr
}
Expand Down

0 comments on commit ddd531c

Please sign in to comment.