{"id":26590555,"url":"https://github.com/emcfarlane/starlarkassert","last_synced_at":"2025-10-29T00:42:56.227Z","repository":{"id":42442573,"uuid":"376276305","full_name":"emcfarlane/starlarkassert","owner":"emcfarlane","description":"Assert module","archived":false,"fork":false,"pushed_at":"2023-04-12T16:25:04.000Z","size":76,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-21T00:58:22.325Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emcfarlane.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-12T11:44:28.000Z","updated_at":"2024-04-21T00:58:22.326Z","dependencies_parsed_at":"2022-08-28T05:51:08.326Z","dependency_job_id":null,"html_url":"https://github.com/emcfarlane/starlarkassert","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emcfarlane%2Fstarlarkassert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emcfarlane%2Fstarlarkassert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emcfarlane%2Fstarlarkassert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emcfarlane%2Fstarlarkassert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emcfarlane","download_url":"https://codeload.github.com/emcfarlane/starlarkassert/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245111929,"owners_count":20562511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-23T13:52:42.372Z","updated_at":"2025-10-29T00:42:56.149Z","avatar_url":"https://github.com/emcfarlane.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# starlarkassert\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/emcfarlane/starlarkassert.svg)](https://pkg.go.dev/github.com/emcfarlane/starlarkassert)\n\nPackage starlarkassert binds starlark scripts to go's testing framework. Create tests in starlark files by prefixing starlark functions with `test_` that take one arg `t`. Each function will be bound to go's test runner. Set the test files in a root Go project and provide any global functions or methods to callback. Than run `go test` as usual.\n\n```python\n# tests are prefixed with \"test_\"\ndef test_are_prefix(assert):\n    assert.true(True)\n    print(\"here\")  # print formats in go's t.Log(...)\n\n# tests can run subtests with \"assert.run()\"\ndef test_subtest(assert):\n    for name in [\"test\", \"names\"]:\n        assert.run(name, lambda assert: print(name))\n```\n\n```python\n# benches are prefixed with \"bench_\"\ndef bench_append(b):\n    a = []\n    b.restart()\n    for i in range(b.n):\n        a.append(i)\n```\n\nIntegrate starlark Scripts with go's test framework:\n```go\nfunc TestScript(t *testing.T) {\n\tglobals := starlark.StringDict{\n\t\t\"struct\": starlark.NewBuiltin(\"struct\", starlarkstruct.Make),\n\t}\n\tRunTests(t, \"testdata/*.star\", globals)\n}\n```\n\nThen run tests like you would with Go:\n```sh\n$ go test -v .\n=== RUN   TestRunTests\n=== RUN   TestRunTests/test_here\n    testdata/test.star:6:10 here\n=== RUN   TestRunTests/test_array\n    testdata/test.star:11:14 name: lord\n    testdata/test.star:11:14 name: of\n    testdata/test.star:11:14 name: the\n    testdata/test.star:11:14 name: rings\n=== RUN   TestRunTests/test_t_run\n=== RUN   TestRunTests/test_t_run/harry\n    testdata/test.star:16:36 harry\n=== RUN   TestRunTests/test_t_run/potter\n    testdata/test.star:16:36 potter\n=== RUN   TestRunTests/test_globals\n=== RUN   TestRunTests/test_globals_frozen\n=== RUN   TestRunTests/test_load\n    testdata/test.star:35:10 hello, world\n--- PASS: TestRunTests (0.00s)\n    --- PASS: TestRunTests/test_here (0.00s)\n    --- PASS: TestRunTests/test_array (0.00s)\n    --- PASS: TestRunTests/test_t_run (0.00s)\n        --- PASS: TestRunTests/test_t_run/harry (0.00s)\n        --- PASS: TestRunTests/test_t_run/potter (0.00s)\n    --- PASS: TestRunTests/test_globals (0.00s)\n    --- PASS: TestRunTests/test_globals_frozen (0.00s)\n    --- PASS: TestRunTests/test_load (0.00s)\n=== RUN   Test_depsInterface\n    testing_test.go:28: \n--- SKIP: Test_depsInterface (0.00s)\nPASS\nok  \tgithub.com/emcfarlane/starlarkassert\t(cached)\n```\n\n## test\n\n### test·error\n\n`t.error(msg)` reports the error msg to the test runner.\n\n| Parameter | Type | Description |\n| --------- | ---- | ----------- |\n| msg | string | Message. |\n\n### test·fail\n\n`t.fail()` fails the test and halts test running.\n\n### test·fatal\n\n`t.fatal(msg)` reports the error msg to the test runner, and fails the test.\n\n| Parameter | Type | Description |\n| --------- | ---- | ----------- |\n| msg | value | Message. |\n\n### test·freeze\n\n`t.freeze(val)` the value, for testing freeze behaviour.\nAll mutations after freeze should fail.\n\n| Parameter | Type | Description |\n| --------- | ---- | ----------- |\n| val | value | Value to freeze. |\n\n### test·run\n\n`t.run(subtest)` runs the function with a test instance as the first arg.\n\n| Parameter | Type | Description |\n| --------- | ---- | ----------- |\n| subtest | function | Function to run as a subtest. |\n\n### test·skip\n\n`t.skip()` skips the current test.\n\n### test·equal\n\n`t.equal(a, b)` compares two values of the same type are equal.\nIf the value is diffable it will report the difference between the two.\n\n| Parameter | Type | Description |\n| --------- | ---- | ----------- |\n| a | value | Value expected. |\n| b | value | Value given. |\n\n### test·not_equal\n\n`t.not_equal(a, b)` compares two values of the same type are not equal, r\n\n| Parameter | Type | Description |\n| --------- | ---- | ----------- |\n| a | value | Value expected. |\n| b | value | Value given. |\n\n### test·less_than\n\n`t.less_than(a, b)` compares two values of the same type are less than.\n\n| Parameter | Type | Description |\n| --------- | ---- | ----------- |\n| a | value | Value expected. |\n| b | value | Value given. |\n\n### test·true\n\n`t.true(a, msg)` checks truthyness reporting the message if falsy.\n\n| Parameter | Type | Description |\n| --------- | ---- | ----------- |\n| a | value | Value expected to be truthy. |\n| msg | string | Message to report on falsyness. |\n\n### test·contains\n\n`t.contains(a, b)` checks `b` is in `a`.\n\n| Parameter | Type | Description |\n| --------- | ---- | ----------- |\n| a | iterable | Iterable item. |\n| b | value | Value expected. |\n\n### test·fails\n\n`t.fails(f, pattern)` runs the function and checks the returned error matches the regex pattern.\n\n| Parameter | Type | Description |\n| --------- | ---- | ----------- |\n| f | function | value to run. |\n| pattern | string | Regex pattern to match. |\n\n\n## bench\n\nBench is a superset of test. All attributes are included plus the following.\n\n### bench·restart\n\n`b.restart()` the benchmark clock.\n\n### bench·start\n\n`b.start()` the benchmark clock.\n\n### bench·stop\n\n`b.stop()` the benchmark clock.\n\n### bench·n\n\n`b.n` returns the current benchmark iteration size.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femcfarlane%2Fstarlarkassert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femcfarlane%2Fstarlarkassert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femcfarlane%2Fstarlarkassert/lists"}