github.com/mcuadros/ascode@v1.3.1/starlark/test/assert.star.go (about) 1 package test 2 3 const assertStarFile = ` 4 # Predeclared built-ins for this module: 5 # 6 # error(msg): report an error in Go's test framework without halting execution. 7 # This is distinct from the built-in fail function, which halts execution. 8 # catch(f): evaluate f() and returns its evaluation error message, if any 9 # matches(str, pattern): report whether str matches regular expression pattern. 10 # module(**kwargs): a constructor for a module. 11 # _freeze(x): freeze the value x and everything reachable from it. 12 # 13 # Clients may use these functions to define their own testing abstractions. 14 15 def _eq(x, y): 16 if x != y: 17 error("%r != %r" % (x, y)) 18 19 def _ne(x, y): 20 if x == y: 21 error("%r == %r" % (x, y)) 22 23 def _true(cond, msg = "assertion failed"): 24 if not cond: 25 error(msg) 26 27 def _lt(x, y): 28 if not (x < y): 29 error("%s is not less than %s" % (x, y)) 30 31 def _contains(x, y): 32 if y not in x: 33 error("%s does not contain %s" % (x, y)) 34 35 def _fails(f, pattern): 36 "assert_fails asserts that evaluation of f() fails with the specified error." 37 msg = catch(f) 38 if msg == None: 39 error("evaluation succeeded unexpectedly (want error matching %r)" % pattern) 40 elif not matches(pattern, msg): 41 error("regular expression (%s) did not match error (%s)" % (pattern, msg)) 42 43 freeze = _freeze # an exported global whose value is the built-in freeze function 44 45 assert = module( 46 "assert", 47 fail = error, 48 eq = _eq, 49 ne = _ne, 50 true = _true, 51 lt = _lt, 52 contains = _contains, 53 fails = _fails, 54 ) 55 `