aboutsummaryrefslogtreecommitdiff
path: root/starlarktest
diff options
context:
space:
mode:
authoralandonovan <adonovan@google.com>2019-01-04 13:04:59 -0500
committerGitHub <noreply@github.com>2019-01-04 13:04:59 -0500
commit9d9777168d883df01c5a74800b807e5315fb9850 (patch)
tree7690a231bdd08eb87ce50d01088c6bfada674263 /starlarktest
parent1ed6497385c9b84fa2c4d85f440d256793df3df7 (diff)
downloadstarlark-go-9d9777168d883df01c5a74800b807e5315fb9850.tar.gz
starlarkstruct: add 'module' type, and use it for assert module (#91)
...instead of struct, which is more suited to dynamic values. This type will be used for Stargo (see wip-stargo branch). For example, this load statement load("go", http="net/http", json="encoding/json") would load two modules.
Diffstat (limited to 'starlarktest')
-rw-r--r--starlarktest/assert.star42
-rw-r--r--starlarktest/starlarktest.go2
2 files changed, 22 insertions, 22 deletions
diff --git a/starlarktest/assert.star b/starlarktest/assert.star
index f453aac..ba8b598 100644
--- a/starlarktest/assert.star
+++ b/starlarktest/assert.star
@@ -1,45 +1,45 @@
-
# Predeclared built-ins for this module:
#
# error(msg): report an error in Go's test framework without halting execution.
# catch(f): evaluate f() and returns its evaluation error message, if any
# matches(str, pattern): report whether str matches regular expression pattern.
-# struct: a constructor for a simple HasFields implementation.
+# module(**kwargs): a constructor for a module.
# _freeze(x): freeze the value x and everything reachable from it.
#
# Clients may use these functions to define their own testing abstractions.
def _eq(x, y):
- if x != y:
- error("%r != %r" % (x, y))
+ if x != y:
+ error("%r != %r" % (x, y))
def _ne(x, y):
- if x == y:
- error("%r == %r" % (x, y))
+ if x == y:
+ error("%r == %r" % (x, y))
-def _true(cond, msg="assertion failed"):
- if not cond:
- error(msg)
+def _true(cond, msg = "assertion failed"):
+ if not cond:
+ error(msg)
def _lt(x, y):
- if not (x < y):
- error("%s is not less than %s" % (x, y))
+ if not (x < y):
+ error("%s is not less than %s" % (x, y))
def _contains(x, y):
- if y not in x:
- error("%s does not contain %s" % (x, y))
+ if y not in x:
+ error("%s does not contain %s" % (x, y))
def _fails(f, pattern):
- "assert_fails asserts that evaluation of f() fails with the specified error."
- msg = catch(f)
- if msg == None:
- error("evaluation succeeded unexpectedly (want error matching %r)" % pattern)
- elif not matches(pattern, msg):
- error("regular expression (%s) did not match error (%s)" % (pattern, msg))
+ "assert_fails asserts that evaluation of f() fails with the specified error."
+ msg = catch(f)
+ if msg == None:
+ error("evaluation succeeded unexpectedly (want error matching %r)" % pattern)
+ elif not matches(pattern, msg):
+ error("regular expression (%s) did not match error (%s)" % (pattern, msg))
-freeze = _freeze # an exported global whose value is the built-in freeze function
+freeze = _freeze # an exported global whose value is the built-in freeze function
-assert = struct(
+assert = module(
+ "assert",
fail = error,
eq = _eq,
ne = _ne,
diff --git a/starlarktest/starlarktest.go b/starlarktest/starlarktest.go
index 4cf315b..5436d22 100644
--- a/starlarktest/starlarktest.go
+++ b/starlarktest/starlarktest.go
@@ -63,7 +63,7 @@ func LoadAssertModule() (starlark.StringDict, error) {
"error": starlark.NewBuiltin("error", error_),
"catch": starlark.NewBuiltin("catch", catch),
"matches": starlark.NewBuiltin("matches", matches),
- "struct": starlark.NewBuiltin("struct", starlarkstruct.Make),
+ "module": starlark.NewBuiltin("module", starlarkstruct.MakeModule),
"_freeze": starlark.NewBuiltin("freeze", freeze),
}
filename := DataFile("starlarktest", "assert.star")