{"id":19687221,"url":"https://github.com/trinitronx/bats-utils","last_synced_at":"2025-11-22T10:03:39.987Z","repository":{"id":136204457,"uuid":"61619468","full_name":"trinitronx/bats-utils","owner":"trinitronx","description":"Bootstrap helper utilities for use in Bats testing","archived":false,"fork":false,"pushed_at":"2016-08-18T16:33:31.000Z","size":27,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-10T07:47:23.382Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trinitronx.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}},"created_at":"2016-06-21T09:12:51.000Z","updated_at":"2020-02-02T21:55:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"0a788ef2-16d2-4b0e-959b-2a6277401072","html_url":"https://github.com/trinitronx/bats-utils","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinitronx%2Fbats-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinitronx%2Fbats-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinitronx%2Fbats-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinitronx%2Fbats-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trinitronx","download_url":"https://codeload.github.com/trinitronx/bats-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240993952,"owners_count":19890419,"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-11-11T18:33:25.330Z","updated_at":"2025-11-22T10:03:34.951Z","avatar_url":"https://github.com/trinitronx.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bats-utils\n\n[![GitHub license](https://img.shields.io/github/license/trinitronx/bats-utils.svg?maxAge=2592000)](https://raw.githubusercontent.com/trinitronx/bats-utils/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/ztombol/bats-file.svg)](https://github.com/trinitronx/bats-utils/releases/latest)\n[![Build Status](https://travis-ci.org/trinitronx/bats-utils.svg?branch=master)](https://travis-ci.org/trinitronx/bats-utils)\n\n`bats-utils` is a helper library providing common test dependencies\nand a function to bootstrap them into [Bats][bats].\n\nThe test dependency bootstrap function installs the utility passed using\na recipe found under `src/`.  If an error occurs during install, \nthey return 1 on failure and 0 otherwise. \nOutput, [formatted][bats-support-output] for readability, is sent\nto standard error to make the `install_test_dependency` function \nusable outside of `@test` blocks too.\n\nDependencies:\n- [`bats-support`][bats-support] - output formatting\n\nSee the [shared documentation][bats-docs] to learn how to install and\nload this library.\n\n\n## Usage\n\n### `install_test_dependency`\n\nTry to load the test dependency library and execute a function named `install_$dep`.\nIf a problem installing occurs, output an error and fail.  If installation succeeds,\nthe utility may be used in subsequent tests.  If the utility already exists, silently\ncontinue.\n\nFor included test dependency install recipes, see the `src/` directory.\n\n### Helper Utilities\n\n#### `shellcheck`\n\n**Installs:**\n\n - [`shellcheck`][koalaman-shellcheck], a static analysis tool for shell scripts http://www.shellcheck.net\n\n```bash\n@test '/etc/default files must pass shellcheck tests' {\n  install_test_dependency shellcheck\n  for f in /etc/default/*; do\n    local error_message=\"File: '$f' did not pass 'shellcheck --shell=bash --exclude=SC1014,SC2148' tests\"\n\n    run shellcheck --shell=bash --exclude=SC1014,SC2148 $f\n    assert_success                         || fail $error_message\n    refute_line --regexp 'SC[[:digit:]]+:' || fail $error_message\n    refute_line --regexp 'In.*line'        || fail $error_message\n  done\n}\n```\n\nOn failure, the `error_message` is displayed.\n\n```\n     `assert_success                         || fail $error_message' failed\n\n   -- command failed --\n   status : 1\n   output (11 lines):\n\n     In default/foo line 1:\n     if [ \"$foo\" ]\n     ^-- SC1049: Did you forget the 'then' for this 'if'?\n     ^-- SC1073: Couldn't parse this if expression.\n\n\n     In default/foo line 2:\n     fi\n     ^-- SC1050: Expected 'then'.\n       ^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.\n   --\n\n   File: 'default/foo' did not pass 'shellcheck --shell=bash --exclude=SC1014,SC2148' tests\n```\n\n\n#### `jq`\n\n**Installs:**\n\n - [`jq`][stedolan-jq], Command-line JSON processor http://stedolan.github.io/jq/\n\n```bash\nsetup() {\n  install_test_dependency jq\n}\n\n@test \"stedolan/jq should have a description\" {\n  run bash -c \"curl -s 'https://api.github.com/repos/stedolan/jq' | jq '.description'\"\n  assert_output '\"Command-line JSON processor\"'\n}\n```\n\nOn failure, the differing output would be displayed.\n\n```\n     `assert_output '\"Command-line JSON processor\"'' failed\n\n   -- output differs --\n   expected : \"Command-line JSON processor\"\n   actual   : \"pythonic filesystem library\"\n   --\n```\n\n#### `y2j`\n\n**Installs:**\n\n - [`y2j`][wildducktheories-y2j], A command line tool for converting between YAML and JSON and vice versa.\n\n```bash\nsetup() {\n  install_test_dependency y2j\n}\n\n@test \"First of list should be true\" {\n  run bash -c \"curl -s 'https://raw.githubusercontent.com/yaml/yaml-node-js/master/tests/booleans.yaml' | y2j | jq '.[0]'\"\n  assert_output 'true'\n}\n```\n\nOn failure, the differing output would be displayed.\n\n```\n     `assert_output 'true'' failed\n\n   -- output differs --\n   expected : true\n   actual   : false\n   --\n```\n\n#### `xxd`\n\n**Installs:**\n\n - [`xxd`][vim-xxd], Utility to make a hexdump or do the reverse. http://vim.wikia.com/wiki/Hex_dump\n\n```bash\nsetup() {\n  install_test_dependency xxd\n}\n\n@test \"/etc/cron.d files end in newline\" {\n  for f in /etc/cron.d/*; do\n    run xxd $f\n    assert [ $status -eq 0 ] || fail \"command failed: xxd $f\"\n    let \"last_line = ${#lines[@]} - 1\" || true\n    let \"last_line \u003c 0 ? last_line = 0 : noop\" || true\n    assert_line --index $last_line --regexp '0a[[:space:]]*.' || fail \"File: '$f' did not end in newline\"\n  done\n}\n```\n\nOn failure, the differing output would be displayed.\n\n```\n`assert_line --index $last_line --regexp '0a[[:space:]]*.' || fail \"File: '$f' did not end in newline\"' failed\n\n-- regular expression does not match line --\nindex  : 0\nregexp : 0a[[:space:]]*.\nline   :\n--\n\nFile: '/etc/cron.d/derp' did not end in newline\n```\n\n\n\n\u003c!-- REFERENCES --\u003e\n\n[bats]: https://github.com/sstephenson/bats\n[bats-support-output]: https://github.com/ztombol/bats-support#output-formatting\n[bats-support]: https://github.com/ztombol/bats-support\n[bats-docs]: https://github.com/ztombol/bats-docs\n[koalaman-shellcheck]: https://github.com/koalaman/shellcheck\n[stedolan-jq]: https://github.com/stedolan/jq\n[wildducktheories-y2j]: https://github.com/wildducktheories/y2j\n[vim-xxd]: http://linux.die.net/man/1/xxd\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrinitronx%2Fbats-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrinitronx%2Fbats-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrinitronx%2Fbats-utils/lists"}