{"id":13544083,"url":"https://github.com/rluba/stubborn","last_synced_at":"2025-04-02T14:30:23.062Z","repository":{"id":73421636,"uuid":"308109262","full_name":"rluba/stubborn","owner":"rluba","description":"Stubborn – a test assertion and matcher library for Jai","archived":false,"fork":false,"pushed_at":"2025-02-24T15:59:37.000Z","size":43,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-24T16:52:53.151Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rluba.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-28T18:39:33.000Z","updated_at":"2025-02-24T15:59:43.000Z","dependencies_parsed_at":"2024-01-16T17:02:35.605Z","dependency_job_id":"3c50bb7b-e823-4fea-b4b8-2bfe0fdfc428","html_url":"https://github.com/rluba/stubborn","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/rluba%2Fstubborn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rluba%2Fstubborn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rluba%2Fstubborn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rluba%2Fstubborn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rluba","download_url":"https://codeload.github.com/rluba/stubborn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246832043,"owners_count":20841096,"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":"2024-08-01T11:00:41.811Z","updated_at":"2025-04-02T14:30:22.763Z","avatar_url":"https://github.com/rluba.png","language":null,"funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"# Stubborn – a test assertion and matcher library for Jai\n\nStubborn is a first attempt at porting [Hamjest](https://github.com/rluba/hamjest) to Jai.\nIt’s still very, *very*, **veeery** early and contains only a handful of matchers, but it already supports …\n\n* … enumerating and running all tests at compile-time.\n* … parameterized tests\n* … compile errors that point to the failed assertion\n\nUnfortunately, I haven’t found an elegant way to support nesting of matchers yet. Baby steps.\n\n# Writing tests\n\nTests are normal functions annotated with `@Test` inside any file ending in `.spec.jai`:\n\n```Jai\n// visit_files.spec.jai\nyour_test_function_with_a_descriptive_name :: () {\n\n} @Test\n```\n\nUse `assert_that(actualValue, matcher)` to write test assertions:\n\n```Jai\n// visit_files.spec.jai\nignores_dirs_and_follows_links_by_default :: () {\n\tresult: [..] string;\n\tdefer cleanup(result);\n\n\tsuccess := visit_files(\"tests/links\", true, *result, (info: *File_Visit_Info, result: * [..] string) {\n\t\tarray_add(result, copy_string(info.full_name));\n\t});\n\n\tassert_that(success, is(true));\n\tassert_that(result, contains_in_any_order(\n\t\t\"tests/links/link_dir/file.txt\",\n\t\t\"tests/links/real_dir/file.txt\",\n\t\t\"tests/links/linked.txt\",\n\t\t\"tests/links/broken_link\"\n\t));\n} @Test\n```\n\nThe first failing assertion will stop compilation with an error at the line of the assert.\nSee [Matchers](#Matchers) for a list of available matchers.\n\n## Parameterized tests\n\nYou probably want to parameterize some of your tests to avoid repeating the same test code over and over again.\nSimply provide a global array with the parameters thats called like your test function + `_params` and let your test function take an argument:\n\n```Jai\n// count_a.spec.jai\n\nCount_Test_Args :: struct {\n\tinput: string;\n\texpected: int;\n}\n\ncounts_number_of_as_correctly_params :: Count_Test_Args.[\n\t.{\"jonathan\", 2},\n\t.{\"raphael\", 2},\n\t.{\"jim\", 0},\n\t.{\"jane\", 1},\n];\n\ncounts_number_of_as_correctly :: (args: Count_Test_Args) {\n\tresult := count_a(args.input);\n\n\tassert_that(result, is(args.expected));\n} @Test\n```\n\nRunning the tests will (hopefully) output:\n\n```\ncount_a.spec.jai:\n\tcounts_number_of_as_correctly({\"jonathan\", 2}): PASSED\n\tcounts_number_of_as_correctly({\"raphael\", 2}): PASSED\n\tcounts_number_of_as_correctly({\"jim\", 0}): PASSED\n\tcounts_number_of_as_correctly({\"jane\", 1}): PASSED\n```\n\n# Running the tests\n\n`#load` (not `#import`!) the [run.jai](./run.jai) as part of you build file and call `build_tests(…)`:\n\n```Jai\n#load \"modules/stubborn/run.jai\";\n\n#run {\n\targs := compiler_get_command_line_arguments();\n\n\tentrypoint := ifx args.count then args[0] else \"\";\n\tif entrypoint == \"test\" {\n        options := get_build_options();\n\t\tbuild_tests(options, \"\u003cpath_to_your_test_folder\u003e\", #string END\n\t\t\t// Any code or modules that should be loaded before the tests are run goes here…\n\t\t\t// For example:\n\t\t\t#load \"your_main_entry_file.jai\";\n\t\tEND, \u003cpaths to custom modules go here\u003e);\n\t} else {\n\t\t// Your normal build stuff goes here…\n\t}\n}\n```\n\nStubborn will recursively enumerate all files ending in `.spec.jai` inside the folder you pass to `build_tests`, compile them, find all methods annotated with `@Test` and run them.\n\nTests will be run in the lexicographical order of their file names and in the order they’re define inside each file.\n\nThe first failing assertion stops compilation.\n\nYou can also compile the tests into a binary instead of running them at compile time by passing `run = false` to `build_tests`. (Useful for stepping through your tests with a debugger.)\n\n## Skipping tests\nYou can run only a sub-set of tests by passing a list of test names as `args` to `build_tests`.\n\n# Matchers\n\nFor now, this module contains only a minimal set of [Hamjest’s](https://github.com/rluba/hamjest) matchers:\n\n* `is(expected_value)` for any type\n* `contains(.. expected_values)` for arrays\n* `contains_in_any_order(.. expected_values` for arrays\n* `has_count` for anything with a `.count` member (arrays, strings, collections, …)\n\nNone of the matchers support nesting, yet.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frluba%2Fstubborn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frluba%2Fstubborn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frluba%2Fstubborn/lists"}