{"id":18809280,"url":"https://github.com/thingsym/bats-assertion","last_synced_at":"2025-09-02T10:41:25.243Z","repository":{"id":144902708,"uuid":"128620666","full_name":"thingsym/bats-assertion","owner":"thingsym","description":"Bats Assertion is a helper script for Bats","archived":false,"fork":false,"pushed_at":"2020-12-09T08:25:57.000Z","size":10,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T20:36:04.950Z","etag":null,"topics":["assertion","bats","helper-script"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thingsym.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-04-08T08:52:44.000Z","updated_at":"2021-02-02T13:11:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"8fc86ea7-7913-464d-afa5-38304577beaf","html_url":"https://github.com/thingsym/bats-assertion","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/thingsym/bats-assertion","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thingsym%2Fbats-assertion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thingsym%2Fbats-assertion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thingsym%2Fbats-assertion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thingsym%2Fbats-assertion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thingsym","download_url":"https://codeload.github.com/thingsym/bats-assertion/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thingsym%2Fbats-assertion/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273272503,"owners_count":25075976,"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","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["assertion","bats","helper-script"],"created_at":"2024-11-07T23:15:51.591Z","updated_at":"2025-09-02T10:41:25.235Z","avatar_url":"https://github.com/thingsym.png","language":"Shell","readme":"# Bats Assertion\n\nBats Assertion is a helper script for [Bats](https://github.com/bats-core/bats-core/).\n\n[![Build Status](https://travis-ci.org/thingsym/bats-assertion.svg?branch=master)](https://travis-ci.org/thingsym/bats-assertion)\n\n## Example\n\n```\n#!/usr/bin/env bats\n\nload bats-assertion\n\n@test \"assert_success\" {\n  run bash -c 'exit 0'\n  assert_success\n}\n\n@test \"assert_failure\" {\n  run bash -c 'exit 1'\n  assert_failure\n\n  run bash -c 'exit 123'\n  assert_failure\n}\n\n@test \"assert_status \u003cstatus\u003e\" {\n  run bash -c 'exit 0'\n  assert_status 0\n\n  run bash -c 'exit 1'\n  assert_status 1\n\n  run bash -c 'exit 123'\n  assert_status 123\n}\n\n@test \"assert_equal \u003cexpected\u003e \u003cactual\u003e\" {\n  run bash -c 'echo \"abc\"'\n  assert_equal \"abc\" \"abc\"\n}\n\n@test \"assert_match \u003cexpected\u003e \u003cactual\u003e\" {\n  run bash -c 'echo \"abc\"'\n  assert_match \"ab\" \"abc\"\n\n  # regular expression matching\n  run assert_match \"^ab\" \"abc\"\n  run assert_match \"bc$\" \"abc\"\n}\n\n@test \"assert_lines_equal \u003cexpected\u003e \u003cline\u003e\" {\n  run bash -c 'echo -e \"abc\\ndef\\nghi\"'\n  assert_lines_equal \"abc\" 0\n  assert_lines_equal \"def\" 1\n  assert_lines_equal \"ghi\" 2\n  assert_lines_equal \"ghi\" -1\n}\n\n@test \"assert_lines_match \u003cexpected\u003e \u003cline\u003e\" {\n  run bash -c 'echo -e \"abc\\ndef\\nghi\"'\n  assert_lines_match \"ab\" 0\n  assert_lines_match \"de\" 1\n  assert_lines_match \"gh\" 2\n  assert_lines_match \"gh\" -1\n\n  # regular expression matching\n  assert_lines_match \"^ab\" 0\n  assert_lines_match \"hi$\" 2\n  assert_lines_match \"^[sfd][aec][emf]$\" 1\n  assert_lines_match \"^[sfd][aec][emf]$\" -2\n}\n```\n\n### Failure output Example\n\n```\n✗ assert_status\n  (from function `assert_status \u003cstatus\u003e' in file bats-assertion.bash, line 30,\n  in test file sample.bats, line 7)\n    `assert_status 1' failed\n  Expected: 1\n  Actual  : 0\n\n✗ assert_equal \u003cexpected\u003e \u003cactual\u003e\n  (from function `assert_equal' in file bats-assertion.bash, line 40,\n  in test file sample.bats, line 31)\n    `assert_equal \"cba\" \"abc\"' failed\n  Expected: cba\n  Actual  : abc\n\n✗ assert_lines_equal \u003cexpected\u003e \u003cline\u003e\n  (from function `assert_lines_equal' in file bats-assertion.bash, line 94,\n  in test file sample.bats, line 45)\n    `assert_lines_equal \"abc\" 1' failed\n  Expected: abc\n  Actual  : def\n  Index   : 1\n```\n\n## Getting Started\n\n### 1. Download Bats Assertion\n\n```\ngit clone https://github.com/thingsym/bats-assertion\n```\n\n### 2. Import Bats Assertion in bats file\n\n```\nload bats-assertion/bats-assertion\n```\n\n### 3. Write tests using Bats Assertion\n\n```\n@test \"assert_status\" {\n  run ./bin/foo\n  assert_status 0\n}\n```\n\n## Assertion Reference\n\n### assert_success\n\nReports an error if `$status` is not 0.\n\n```\nassert_success\n```\n\n### assert_failure\n\nReports an error if `$status` is 0.\n\n```\nassert_failure\n```\n\n### assert_status\n\nReports an error if the two variables `\u003cstatus\u003e` and `$status` are not equal.\n\n```\nassert_status \u003cstatus\u003e\n```\n\n### assert_equal\n\nReports an error if the two variables `\u003cexpected\u003e` and `\u003cactual\u003e` are not equal.\n\n```\nassert_equal \u003cexpected\u003e \u003cactual\u003e\n```\n\nUsing `$output` as `\u003cactual\u003e`\n\n```\nassert_equal \u003cexpected\u003e\n```\n\n\n### assert_fail_equal\n\nReports an error if the two variables `\u003cexpected\u003e` and `\u003cactual\u003e` are equal.\n\n```\nassert_fail_equal \u003cexpected\u003e \u003cactual\u003e\n```\n\nUsing `$output` as `\u003cactual\u003e`\n\n```\nassert_fail_equal \u003cexpected\u003e\n```\n\n### assert_match\n\nReports an error if the two variables `\u003cexpected\u003e` and `\u003cactual\u003e` are not match.\n\n```\nassert_match \u003cexpected\u003e \u003cactual\u003e\n```\n\nUsing `$output` as `\u003cactual\u003e`\n\n```\nassert_match \u003cexpected\u003e\n```\n\n### assert_fail_match\n\nReports an error if the two variables `\u003cexpected\u003e` and `\u003cactual\u003e` are match.\n\n```\nassert_fail_match \u003cexpected\u003e \u003cactual\u003e\n```\n\nUsing `$output` as `\u003cactual\u003e`\n\n```\nassert_fail_match \u003cexpected\u003e\n```\n\n### assert_lines_equal\n\nReports an error if the two variables `\u003cexpected\u003e` and the line of output in the `$lines` array passing the number of lines as a variable `\u003cline\u003e` are not equal.\n\n```\nassert_lines_equal \u003cexpected\u003e \u003cline\u003e\n```\n\n### assert_fail_lines_equal\n\nReports an error if the two variables `\u003cexpected\u003e` and the line of output in the `$lines` array passing the number of lines as a variable `\u003cline\u003e` are equal.\n\n```\nassert_fail_lines_equal \u003cexpected\u003e \u003cline\u003e\n```\n\nUsing reserved word, `first` and `last`\n\nAssert the `first` line of `$lines` array.\n\n```\nassert_fail_lines_equal \u003cexpected\u003e \"first\"\n```\n\nAssert the `last` line of `$lines` array.\n\n```\nassert_fail_lines_equal \u003cexpected\u003e \"last\"\n```\n\nAssert all elements of `$lines` array.\n\n```\nassert_fail_lines_equal \u003cexpected\u003e\n```\n\n### assert_lines_match\n\nReports an error if the two variables `\u003cexpected\u003e` and the line of output in the `$lines` array passing the number of lines as a variable `\u003cline\u003e` are not match.\n\n```\nassert_lines_match \u003cexpected\u003e \u003cline\u003e\n```\n\n\nUsing reserved word, `first` and `last`\n\nAssert the `first` line of `$lines` array.\n\n```\nassert_lines_match \u003cexpected\u003e \"first\"\n```\n\nAssert the `last` line of `$lines` array.\n\n```\nassert_lines_match \u003cexpected\u003e \"last\"\n```\n\nAssert all elements of `$lines` array.\n\n```\nassert_lines_match \u003cexpected\u003e\n```\n\n### assert_fail_lines_match\n\nReports an error if the two variables `\u003cexpected\u003e` and the line of output in the `$lines` array passing the number of lines as a variable `\u003cline\u003e` are match.\n\n```\nassert_fail_lines_match \u003cexpected\u003e \u003cline\u003e\n```\n\nUsing reserved word, `first` and `last`\n\nAssert the `first` line of `$lines` array.\n\n```\nassert_fail_lines_match \u003cexpected\u003e \"first\"\n```\n\nAssert the `last` line of `$lines` array.\n\n```\nassert_fail_lines_match \u003cexpected\u003e \"last\"\n```\n\nAssert all elements of `$lines` array.\n\n```\nassert_fail_lines_match \u003cexpected\u003e\n```\n\n## Helper\n\n### _dump\n\nDumps information about a variable.\n\n```\n_dump \u003cvariable\u003e\n```\n\nUsing `$output` as `\u003cvariable\u003e`\n\n```\n_dump\n```\n\n## Contribution\n\n### Patches and Bug Fixes\n\nSmall patches and bug reports can be submitted a issue tracker in Github. Forking on Github is another good way. You can send a pull request.\n\n1. Fork [Bats Assertion](https://github.com/thingsym/bats-assertion) from GitHub repository\n2. Create a feature branch: git checkout -b my-new-feature\n3. Commit your changes: git commit -am 'Add some feature'\n4. Push to the branch: git push origin my-new-feature\n5. Create new Pull Request\n\n## Changelog\n\n* Version 0.1.0\n  * Initial release.\n\n## License\n\nLicensed under the MIT License.\n\n## Author\n\n[thingsym](https://github.com/thingsym)\n\nCopyright (c) 2018 thingsym\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthingsym%2Fbats-assertion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthingsym%2Fbats-assertion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthingsym%2Fbats-assertion/lists"}