{"id":22007732,"url":"https://github.com/rubberduck203/shunit2examples","last_synced_at":"2026-05-09T02:31:34.305Z","repository":{"id":83178257,"uuid":"82999046","full_name":"rubberduck203/shunit2Examples","owner":"rubberduck203","description":"Spike to see how hard it would be to TDD Bash scripts","archived":false,"fork":false,"pushed_at":"2017-02-25T15:57:39.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-28T13:52:39.630Z","etag":null,"topics":["bash","shunit2","unit-testing"],"latest_commit_sha":null,"homepage":null,"language":"Shell","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/rubberduck203.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":"2017-02-24T03:53:50.000Z","updated_at":"2017-02-25T16:05:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"7ec5fcc1-7cfe-4379-9a0c-9adfb885d56e","html_url":"https://github.com/rubberduck203/shunit2Examples","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/rubberduck203%2Fshunit2Examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubberduck203%2Fshunit2Examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubberduck203%2Fshunit2Examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubberduck203%2Fshunit2Examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubberduck203","download_url":"https://codeload.github.com/rubberduck203/shunit2Examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245066715,"owners_count":20555431,"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":["bash","shunit2","unit-testing"],"created_at":"2024-11-30T01:29:03.521Z","updated_at":"2025-10-05T08:17:47.612Z","avatar_url":"https://github.com/rubberduck203.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# shUnit2 Examples\n\n[![Build Status](https://travis-ci.org/ckuhn203/shunit2Examples.svg?branch=master)](https://travis-ci.org/ckuhn203/shunit2Examples)\n\n## Purpose\n\nFigure out how to test drive bash scripts and have reliable test results (i.e. no flaky integration tests!).\n\n## Notes\n\n*Some of these are likely not directly shunit2 things, but just bash things I don't know yet.*\n\n - Use a docker container to run the tests in so we don't inadvertantly `rm -rf /` or anything equally stupid while I'm learning\n - Import functions from another file with `. filename` source import\n - To match strings with spaces, you must wrap the function call in quotes.\n   * `assertEquals \"Hello World\" \"$(greet)\"`\n - If you don't pass a message as the first arg to an assert, it's hard to tell what failed.\n - Docker copy the source into the container to completely isolate your file system from the container.\n   * The runTests.sh script shows how to copy the source, execute the tests, and clean up the container.\n   * I don't bother with this in the travis ci build, because it's already running in a container there, \n       but for consistency, we could.\n - Use the $SHUNIT_TMPDIR variable to set a working directory to write files for integration testing to.\n   * Being realistic, many bash tests are going to be integration tests that are checking for existance of files and other side effects.\n   * The tests in this project use a `work` directory inside the current working directory.\n\n## Building docker image\n\n```bash\n# From inside project root\ndocker build -t shunit2 .\n```\n\n## Run Tests\n\n```bash\n./test.sh\n```\n\n## shUnit2 in 10 seconds\n\nDocs are installed in /usr/share/doc/shunit2/\n*Unfortunately, the HomeBrew Formulae doesn't seem to include the docs. The apt-get package does though.*\n\nBare bones test looks like this.\n\n```bash\n#! /bin/sh\n# file: examples/equality_test.sh\n\ntestEquality()\n{\n  assertEquals 1 1\n}\n\n# load shunit2\n. shunit2\n```\n\nWhich can be run by executing the `equality_test.sh` file.\n\n```bash\nchmod +x equality_test.sh\n./equality_test.sh\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubberduck203%2Fshunit2examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubberduck203%2Fshunit2examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubberduck203%2Fshunit2examples/lists"}