├── .github ├── dependabot.yaml ├── release.yaml └── workflows │ ├── scorecard.yaml │ ├── test-local-action-inside-home.yaml │ ├── test-local-action-with-conditionals.yaml │ ├── test-local-action.yaml │ ├── test-public-action.yaml │ └── update-pre-commit-hooks.yaml ├── .pre-commit-config.yaml ├── LICENSE ├── README.md ├── action.yaml └── tests ├── 1-example-tests.bats └── tests_helper.bash /.github/dependabot.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | target-branch: main 8 | assignees: ["brokenpip3"] 9 | groups: 10 | actions: 11 | patterns: 12 | - "*" 13 | -------------------------------------------------------------------------------- /.github/release.yaml: -------------------------------------------------------------------------------- 1 | changelog: 2 | categories: 3 | - title: 🏕 Features 4 | labels: 5 | - '*' 6 | exclude: 7 | labels: 8 | - dependencies 9 | - title: 👒 Dependencies 10 | labels: 11 | - dependencies 12 | -------------------------------------------------------------------------------- /.github/workflows/scorecard.yaml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. They are provided 2 | # by a third-party and are governed by separate terms of service, privacy 3 | # policy, and support documentation. 4 | 5 | name: Scorecard supply-chain security 6 | on: 7 | # For Branch-Protection check. Only the default branch is supported. See 8 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection 9 | branch_protection_rule: 10 | # To guarantee Maintained check is occasionally updated. See 11 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained 12 | schedule: 13 | - cron: '44 10 * * 6' 14 | push: 15 | branches: [ "main" ] 16 | 17 | # Declare default permissions as read only. 18 | permissions: read-all 19 | 20 | jobs: 21 | analysis: 22 | name: Scorecard analysis 23 | runs-on: ubuntu-latest 24 | permissions: 25 | # Needed to upload the results to code-scanning dashboard. 26 | security-events: write 27 | # Needed to publish results and get a badge (see publish_results below). 28 | id-token: write 29 | # Uncomment the permissions below if installing in a private repository. 30 | # contents: read 31 | # actions: read 32 | 33 | steps: 34 | - name: "Checkout code" 35 | uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 36 | with: 37 | persist-credentials: false 38 | 39 | - name: "Run analysis" 40 | uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0 41 | with: 42 | results_file: results.sarif 43 | results_format: sarif 44 | # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: 45 | # - you want to enable the Branch-Protection check on a *public* repository, or 46 | # - you are installing Scorecard on a *private* repository 47 | # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat. 48 | # repo_token: ${{ secrets.SCORECARD_TOKEN }} 49 | 50 | # Public repositories: 51 | # - Publish results to OpenSSF REST API for easy access by consumers 52 | # - Allows the repository to include the Scorecard badge. 53 | # - See https://github.com/ossf/scorecard-action#publishing-results. 54 | # For private repositories: 55 | # - `publish_results` will always be set to `false`, regardless 56 | # of the value entered here. 57 | publish_results: true 58 | 59 | # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF 60 | # format to the repository Actions tab. 61 | - name: "Upload artifact" 62 | uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 63 | with: 64 | name: SARIF file 65 | path: results.sarif 66 | retention-days: 5 67 | 68 | # Upload the results to GitHub's code scanning dashboard. 69 | - name: "Upload to code-scanning" 70 | uses: github/codeql-action/upload-sarif@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7 71 | with: 72 | sarif_file: results.sarif 73 | -------------------------------------------------------------------------------- /.github/workflows/test-local-action-inside-home.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | workflow_dispatch: 4 | pull_request: 5 | release: 6 | types: [published] 7 | push: 8 | branches: ["main"] 9 | tags: ["*"] 10 | 11 | jobs: 12 | local_test_home: 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | version: ["1.7.0", "1.9.0", "1.11.0", "latest"] 17 | os: [ ubuntu-22.04, ubuntu-latest, windows-2022, windows-latest, macos-14, macos-latest ] 18 | runs-on: ${{ matrix.os }} 19 | env: 20 | TERM: xterm 21 | name: local-inside-home 22 | steps: 23 | - name: Checkout 24 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 25 | - name: Setup Bats and Bats libs 26 | id: setup-bats 27 | uses: ./ 28 | with: 29 | bats-version: ${{ matrix.version }} 30 | support-clean: "false" 31 | support-path: "${{ github.workspace }}/tests/bats-support" 32 | assert-clean: "false" 33 | assert-path: "${{ github.workspace }}/tests/bats-assert" 34 | detik-clean: "false" 35 | detik-path: "${{ github.workspace }}/tests/bats-detik" 36 | file-clean: "false" 37 | file-path: "${{ github.workspace }}/tests/bats-file" 38 | - name: Execute test to check Bats-support 39 | if: steps.setup-bats.outputs.support-installed == 'true' 40 | shell: bash 41 | env: 42 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 43 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 44 | run: | 45 | cd ${TMP_PATH}/bats-support/ 46 | bats test 47 | - name: Execute test to check Bats-assert 48 | if: steps.setup-bats.outputs.assert-installed == 'true' 49 | shell: bash 50 | env: 51 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 52 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 53 | run: | 54 | cd ${TMP_PATH}/bats-assert/ 55 | bats test 56 | - name: Execute test to check Bats-detik 57 | if: steps.setup-bats.outputs.detik-installed == 'true' 58 | # Currently the bats-detik tests are broken 59 | # in macos 60 | continue-on-error: ${{ runner.os == 'macOS' }} 61 | shell: bash 62 | env: 63 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 64 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 65 | run: | 66 | cd ${TMP_PATH}/bats-detik/ 67 | bats tests 68 | - name: Execute test to check Bats-file 69 | if: steps.setup-bats.outputs.file-installed == 'true' 70 | shell: bash 71 | env: 72 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 73 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 74 | # Currently the bats-file tests are broken 75 | # in gh runner env 76 | continue-on-error: true 77 | run: | 78 | cd ${TMP_PATH}/bats-file/ 79 | bats test 80 | - name: Execute example tests 81 | shell: bash 82 | env: 83 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 84 | run: | 85 | echo $PATH 86 | bats -T -p tests 87 | 88 | local_test_home_trigger_cache: 89 | needs: [local_test_home] 90 | strategy: 91 | fail-fast: false 92 | matrix: 93 | version: ["1.7.0", "1.8.2", "1.9.0", "1.10.0", "1.11.0", "latest"] 94 | os: [ ubuntu-22.04, ubuntu-latest, windows-2022, windows-latest, macos-14, macos-latest ] 95 | runs-on: ${{ matrix.os }} 96 | env: 97 | TERM: xterm 98 | name: local-inside-home-cache 99 | steps: 100 | - name: Checkout 101 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 102 | - name: Setup Bats and Bats libs 103 | id: setup-bats 104 | uses: ./ 105 | with: 106 | bats-version: ${{ matrix.version }} 107 | support-clean: "false" 108 | support-path: "${{ github.workspace }}/tests/bats-support" 109 | assert-clean: "false" 110 | assert-path: "${{ github.workspace }}/tests/bats-assert" 111 | detik-clean: "false" 112 | detik-path: "${{ github.workspace }}/tests/bats-detik" 113 | file-clean: "false" 114 | file-path: "${{ github.workspace }}/tests/bats-file" 115 | - name: Execute example tests 116 | shell: bash 117 | env: 118 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 119 | run: 120 | bats -T -p tests 121 | -------------------------------------------------------------------------------- /.github/workflows/test-local-action-with-conditionals.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | workflow_dispatch: 4 | pull_request: 5 | release: 6 | types: [published] 7 | push: 8 | branches: ["main"] 9 | tags: ["*"] 10 | 11 | jobs: 12 | local_test_options: 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | version: ["1.7.0", "1.9.0", "1.11.0", "latest"] 17 | os: [ ubuntu-22.04, ubuntu-latest, windows-2022, windows-latest, macos-14, macos-latest ] 18 | runs-on: ${{ matrix.os }} 19 | env: 20 | TERM: xterm 21 | name: local-options 22 | steps: 23 | - name: Checkout 24 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 25 | - name: Setup Bats and Bats libs 26 | id: setup-bats 27 | uses: ./ 28 | with: 29 | bats-version: ${{ matrix.version }} 30 | support-clean: "false" 31 | assert-clean: "false" 32 | detik-install: "true" 33 | file-install: "true" 34 | - name: Execute test to check Bats-support 35 | shell: bash 36 | env: 37 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 38 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 39 | run: | 40 | cd ${TMP_PATH}/bats-support/ 41 | bats test 42 | - name: Execute test to check Bats-assert 43 | shell: bash 44 | env: 45 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 46 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 47 | run: | 48 | cd ${TMP_PATH}/bats-assert/ 49 | bats test 50 | - name: Execute example tests 51 | shell: bash 52 | env: 53 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 54 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 55 | run: 56 | bats -T -p tests 57 | -------------------------------------------------------------------------------- /.github/workflows/test-local-action.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | workflow_dispatch: 4 | pull_request: 5 | release: 6 | types: [published] 7 | push: 8 | branches: ["main"] 9 | tags: ["*"] 10 | 11 | jobs: 12 | local_test: 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | version: ["1.7.0", "1.9.0", "1.11.0", "latest"] 17 | os: [ ubuntu-22.04, ubuntu-latest, windows-2022, windows-latest, macos-14, macos-latest ] 18 | runs-on: ${{ matrix.os }} 19 | env: 20 | TERM: xterm 21 | name: local 22 | steps: 23 | - name: Checkout 24 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 25 | - name: Setup Bats and Bats libs 26 | id: setup-bats 27 | uses: ./ 28 | with: 29 | bats-version: ${{ matrix.version }} 30 | support-clean: "false" 31 | assert-clean: "false" 32 | detik-clean: "false" 33 | file-clean: "false" 34 | - name: Execute test to check Bats-support 35 | shell: bash 36 | env: 37 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 38 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 39 | run: | 40 | cd ${TMP_PATH}/bats-support/ 41 | echo $BATS_LIB_PATH 42 | bats test 43 | - name: Execute test to check Bats-assert 44 | shell: bash 45 | env: 46 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 47 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 48 | run: | 49 | cd ${TMP_PATH}/bats-assert/ 50 | bats test 51 | - name: Execute test to check Bats-detik 52 | shell: bash 53 | continue-on-error: true 54 | env: 55 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 56 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 57 | run: | 58 | cd ${TMP_PATH}/bats-detik/ 59 | bats tests 60 | - name: Execute test to check Bats-file 61 | shell: bash 62 | # Currently the bats-file tests are broken 63 | # in gh runner env 64 | continue-on-error: true 65 | env: 66 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 67 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 68 | run: | 69 | cd ${TMP_PATH}/bats-file/ 70 | bats test 71 | - name: Execute example tests 72 | env: 73 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 74 | shell: bash 75 | run: 76 | bats -T -p tests 77 | 78 | local_test_trigger_cache: 79 | needs: [local_test] 80 | strategy: 81 | fail-fast: false 82 | matrix: 83 | version: ["1.7.0", "1.9.0", "1.11.0", "latest"] 84 | os: [ ubuntu-22.04, ubuntu-latest, windows-2022, windows-latest, macos-14, macos-latest ] 85 | runs-on: ${{ matrix.os }} 86 | env: 87 | TERM: xterm 88 | name: local-default-no-cache 89 | steps: 90 | - name: Checkout 91 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 92 | - name: Setup Bats and Bats libs 93 | uses: ./ 94 | id: setup-bats 95 | with: 96 | bats-version: ${{ matrix.version }} 97 | support-clean: "false" 98 | assert-clean: "false" 99 | detik-clean: "false" 100 | file-clean: "false" 101 | - name: Execute example tests 102 | env: 103 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 104 | shell: bash 105 | run: 106 | bats -T -p tests 107 | -------------------------------------------------------------------------------- /.github/workflows/test-public-action.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | workflow_dispatch: 4 | pull_request: 5 | release: 6 | types: [published] 7 | push: 8 | branches: ["main"] 9 | tags: ["*"] 10 | 11 | jobs: 12 | public_test: 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | version: ["1.7.0", "1.9.0", "1.11.0", "latest"] 17 | os: [ ubuntu-22.04, ubuntu-latest, windows-2022, windows-latest, macos-14, macos-latest ] 18 | runs-on: ${{ matrix.os }} 19 | env: 20 | BATS_LIB_PATH: "/usr/lib" 21 | TERM: xterm 22 | name: public 23 | steps: 24 | - name: Checkout 25 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 26 | - name: Setup Bats and Bats libs 27 | id: setup-bats 28 | uses: bats-core/bats-action@main 29 | with: 30 | bats-version: ${{ matrix.version }} 31 | support-clean: "false" 32 | assert-clean: "false" 33 | detik-clean: "false" 34 | file-clean: "false" 35 | - name: Execute test to check Bats-support 36 | shell: bash 37 | env: 38 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 39 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 40 | run: | 41 | cd ${TMP_PATH}/bats-support/ 42 | echo $BATS_LIB_PATH 43 | bats test 44 | - name: Execute test to check Bats-assert 45 | shell: bash 46 | env: 47 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 48 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 49 | run: | 50 | cd ${TMP_PATH}/bats-assert/ 51 | bats test 52 | - name: Execute test to check Bats-detik 53 | shell: bash 54 | continue-on-error: true 55 | env: 56 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 57 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 58 | run: | 59 | cd ${TMP_PATH}/bats-detik/ 60 | bats tests 61 | - name: Execute test to check Bats-file 62 | shell: bash 63 | # Currently the bats-file tests are broken 64 | # in gh runner env 65 | continue-on-error: true 66 | env: 67 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 68 | TMP_PATH: ${{ steps.setup-bats.outputs.tmp-path }} 69 | run: | 70 | cd ${TMP_PATH}/bats-file/ 71 | bats test 72 | - name: Execute example tests 73 | env: 74 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 75 | shell: bash 76 | run: 77 | bats -T -p tests 78 | 79 | public_test_trigger_cache: 80 | needs: [public_test] 81 | strategy: 82 | fail-fast: false 83 | matrix: 84 | version: ["1.7.0", "1.9.0", "1.11.0", "latest"] 85 | os: [ ubuntu-22.04, ubuntu-latest, windows-2022, windows-latest, macos-14, macos-latest ] 86 | runs-on: ${{ matrix.os }} 87 | env: 88 | TERM: xterm 89 | name: public-no-cache 90 | steps: 91 | - name: Checkout 92 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 93 | - name: Setup Bats and Bats-libs 94 | uses: bats-core/bats-action@main 95 | id: setup-bats 96 | with: 97 | bats-version: ${{ matrix.version }} 98 | support-clean: "false" 99 | assert-clean: "false" 100 | detik-clean: "false" 101 | file-clean: "false" 102 | - name: Execute example tests 103 | env: 104 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 105 | shell: bash 106 | run: 107 | bats -T -p tests 108 | -------------------------------------------------------------------------------- /.github/workflows/update-pre-commit-hooks.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: "0 10 * * *" 7 | 8 | jobs: 9 | pre-commit-update: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Check out code 13 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 14 | - name: Update pre-commit hooks 15 | uses: brokenpip3/action-pre-commit-update@main 16 | with: 17 | github-token: ${{ secrets.GITHUB_TOKEN }} 18 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/sirosen/check-jsonschema 3 | rev: 828a213a1dd17aa9862aab706e3162c13281ff93 # frozen: 0.31.2 4 | hooks: 5 | - id: check-github-workflows 6 | - repo: https://github.com/pre-commit/pre-commit-hooks 7 | rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 8 | hooks: 9 | - id: detect-private-key 10 | - id: trailing-whitespace 11 | - id: end-of-file-fixer 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Setup Bats and Bats libraries 2 | 3 | This GitHub Action installs [Bats](https://github.com/bats-core/bats-core) and the four major bats libraries: 4 | 5 | * [bats-support](https://github.com/bats-core/bats-support) 6 | * [bats-assert](https://github.com/bats-core/bats-assert) 7 | * [bats-detik](https://github.com/bats-core/bats-detik) 8 | * [bats-file](https://github.com/bats-core/bats-file) 9 | 10 | The action can be also instructed to select which libraries to install. 11 | While Linux is fully supported, windows and macos runners should work as well, check the [specific](#windows-and-macos-support) readme part. 12 | 13 | ## How to use it 14 | 15 | ``` yaml 16 | on: [push] 17 | 18 | jobs: 19 | my_test: 20 | runs-on: ubuntu-latest 21 | name: Install Bats and bats libs 22 | steps: 23 | - name: Checkout 24 | uses: actions/checkout@v5 25 | - name: Setup Bats and bats libs 26 | id: setup-bats 27 | uses: bats-core/bats-action@3.0.1 28 | - name: My test 29 | shell: bash 30 | env: 31 | BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} 32 | TERM: xterm 33 | run: bats test/my-test 34 | ``` 35 | 36 | By default the action will pass the `BATS_LIB_PATH` value as output `lib-path`. 37 | You can use it like the below example and load the libraries in your tests with: 38 | 39 | ```bash 40 | _tests_helper() { 41 | export BATS_LIB_PATH=${BATS_LIB_PATH:-"/usr/lib"} 42 | bats_load_library bats-support 43 | bats_load_library bats-assert 44 | bats_load_library bats-file 45 | bats_load_library bats-detik/detik.bash 46 | } 47 | ``` 48 | 49 | ## Libraries Path 50 | 51 | For each of the Bats libraries, you can choose to install them in the default location (`/usr/lib/bats-` for linux) or specify a custom path. 52 | 53 | For example, if you want to install `bats-support` in the `./test/bats-support` directory, you can configure it as follows: 54 | 55 | 56 | ``` yaml 57 | [...] 58 | - name: Setup Bats and Bats libs 59 | id: setup-bats 60 | uses: bats-core/bats-action@3.0.1 61 | with: 62 | support-path: ${{ github.workspace }}/test/bats-support 63 | [...] 64 | ``` 65 | 66 | ## About Caching 67 | 68 | The caching mechanism for the `bats binary` is always available. However, the caching for the `bats libraries` is dependent on the location of each library path. If a library is located within the $HOME directory, caching is supported. Conversely, if a library is located outside the $HOME directory (which is the default location per each library), caching is not supported. This is due to a known limitation with sudo and the cache action, as detailed in this GitHub issue: https://github.com/actions/toolkit/issues/946. 69 | 70 | **If you want to cache bats libraries you must install them inside HOME directory**. 71 | For instance this is an example that will use the github workspace handle (works for linux/win/mac): 72 | 73 | ```yaml 74 | [...] 75 | - name: Setup Bats and bats libs 76 | id: setup-bats 77 | uses: bats-core/bats-action@3.0.1 78 | with: 79 | support-path: "${{ github.workspace }}/tests/bats-support" 80 | assert-path: "${{ github.workspace }}/tests/bats-assert" 81 | detik-path: "${{ github.workspace }}/tests/bats-detik" 82 | file-path: "${{ github.workspace }}/tests/bats-file" 83 | [...] 84 | ``` 85 | 86 | ## Windows and macos support 87 | 88 | * Macos is fully supported for both default path and custom home path, just be aware that under `/usr` only `/usr/local/` is writable, 89 | the rest is read only (you may consider to use an home path leverage the cache). 90 | * default libraries installation: `/usr/local/lib` 91 | * default temp directory (for dev testing): `/tmp` 92 | * Windows is fully supported as well, however they may be some hiccup around the libraries installation in another drive that is not `C:`. 93 | Please report any issue. 94 | * default libraries installation: `/c/Users/runneradmin` 95 | * default temp directory (for dev testing): `$HOME/AppData/Local/Temp` 96 | 97 | ## Inputs 98 | 99 | | Key | Default | Required | Description | 100 | |------------------|---------|----------|------------------------------------------------| 101 | | bats-install | `true` | false | Bats installation, cache supported | 102 | | bats-version | `latest` | false | Bats version | 103 | | support-install | `true` | false | Bats-support installation | 104 | | support-version | `0.3.0` | false | Bats-support version | 105 | | support-path | `/usr/lib/bats-support` | false | Bats-support path | 106 | | support-clean | `true` | false | Bats-support: clean temp files | 107 | | assert-install | `true` | false | Bats-assert installation | 108 | | assert-version | `2.1.0` | false | Bats-assert version | 109 | | assert-path | `/usr/lib/bats-assert` | false | Bats-assert path | 110 | | assert-clean | `true` | false | Bats-assert: clean temp files | 111 | | detik-install | `true` | false | Bats-detik installation | 112 | | detik-version | `1.3.0` | false | Bats-detik version | 113 | | detik-path | `/usr/lib/bats-detik` | false | Bats-detik path | 114 | | detik-clean | `true` | false | Bats-detik: clean temp files | 115 | | file-install | `true` | false | Bats-file installation | 116 | | file-version | `0.4.0` | false | Bats-file version | 117 | | file-path | `/usr/lib/bats-file` | false | Bats-file path | 118 | | file-clean | `true` | false | Bats-file: clean temp files | 119 | 120 | ## Outputs 121 | 122 | | Key | Description | 123 | |------------------|------------------------------------------------| 124 | | bats-installed | True/False if bats has been installed | 125 | | support-installed| True/False if bats-support has been installed | 126 | | assert-installed | True/False if bats-assert has been installed | 127 | | detik-installed | True/False if bats-detik has been installed | 128 | | file-installed | True/False if bats-file has been installed | 129 | | lib-path | Bats lib path to use to load the libraries | 130 | | tmp-path | Temporary path with each library tests | 131 | -------------------------------------------------------------------------------- /action.yaml: -------------------------------------------------------------------------------- 1 | name: Setup Bats and Bats libraries 2 | description: A GitHub Action for installing Bats and Bats-libs(support, assert, detik, file) 3 | author: bats-core 4 | branding: 5 | color: yellow 6 | icon: command 7 | inputs: 8 | # Bats binary 9 | bats-install: 10 | description: "Bats installation, default to true" 11 | required: false 12 | default: true 13 | bats-version: 14 | description: "Bats version, default to latest (1.11.0 atm)" 15 | required: false 16 | # support 17 | support-install: 18 | description: "Bats-support installation, default to true" 19 | required: false 20 | default: true 21 | support-version: 22 | description: "Bats-support version, default to latest" 23 | required: false 24 | default: "0.3.0" 25 | support-path: 26 | description: "Bats-support path, default to /usr/lib/bats-support" 27 | required: false 28 | default: "/usr/lib/bats-support" 29 | support-clean: 30 | description: "Bats-support: clean temp files" 31 | required: false 32 | default: true 33 | # assert 34 | assert-install: 35 | description: "Bats-assert installation, default to true" 36 | required: false 37 | default: true 38 | assert-version: 39 | description: "Bats-assert version, default to latest" 40 | required: false 41 | default: "2.1.0" 42 | assert-path: 43 | description: "Bats-assert path, default to /usr/lib/bats-assert" 44 | required: false 45 | default: "/usr/lib/bats-assert" 46 | assert-clean: 47 | description: "Bats-assert: clean temp files" 48 | required: false 49 | default: true 50 | # detik 51 | detik-install: 52 | description: "Bats-detik installation, default to true" 53 | required: false 54 | default: true 55 | detik-version: 56 | description: "Bats-detik version, default to latest" 57 | required: false 58 | default: "1.3.2" 59 | detik-path: 60 | description: "Bats-detik path, default to /usr/lib/bats-detik" 61 | required: false 62 | default: "/usr/lib/bats-detik" 63 | detik-clean: 64 | description: "Bats-detik: clean temp files" 65 | required: false 66 | default: true 67 | # file 68 | file-install: 69 | description: "Bats-file installation, default to true" 70 | required: false 71 | default: true 72 | file-version: 73 | description: "Bats-file version, default to latest" 74 | required: false 75 | default: "0.4.0" 76 | file-path: 77 | description: "Bats-file path, default to /usr/lib/bats-file" 78 | required: false 79 | default: "/usr/lib/bats-file" 80 | file-clean: 81 | description: "Bats-file: clean temp files" 82 | required: false 83 | default: true 84 | github-token: 85 | description: "GitHub token to use to download the releases" 86 | required: false 87 | default: ${{ github.token }} 88 | outputs: 89 | bats-installed: 90 | description: "True/False if bats has been installed" 91 | value: ${{ (steps.bats-install.outputs.bats-installed != '') }} 92 | support-installed: 93 | description: "True/False if bats-support has been installed" 94 | value: ${{ (steps.support-install.outputs.support-installed != '') }} 95 | assert-installed: 96 | description: "True/False if bats-assert has been installed" 97 | value: ${{ (steps.assert-install.outputs.assert-installed != '') }} 98 | detik-installed: 99 | description: "True/False if bats-detik has been installed" 100 | value: ${{ (steps.detik-install.outputs.detik-installed != '') }} 101 | file-installed: 102 | description: "True/False if bats-file has been installed" 103 | value: ${{ (steps.file-install.outputs.file-installed != '') }} 104 | lib-path: 105 | description: "Bats lib path to use to load the libraries" 106 | value: ${{ steps.libpath.outputs.libpath }} 107 | tmp-path: 108 | description: "Temporary path with each library tests" 109 | value: ${{ steps.set-paths.outputs.tmp-path }} 110 | 111 | runs: 112 | using: composite 113 | steps: 114 | # This action would be much easier if only matrix steps will be supported in a composite action 115 | - name: "Set cache for Bats" 116 | uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4 117 | if: inputs.bats-install == 'true' 118 | id: bats-cache 119 | with: 120 | path: | 121 | ~/.local/share/bats 122 | key: ${{ runner.os }}-${{ runner.arch }}-bats-${{ inputs.bats-version }} 123 | 124 | - name: "Set PATH in case of cache-hit" 125 | if: inputs.bats-install == 'true' && steps.bats-cache.outputs.cache-hit == 'true' 126 | id: bats-cache-path 127 | shell: bash 128 | run: | 129 | DESTDIR="$HOME/.local/share/bats" 130 | echo "${DESTDIR}/bin" >> "$GITHUB_PATH" 131 | 132 | - name: "Download and install Bats" 133 | if: inputs.bats-install == 'true' && steps.bats-cache.outputs.cache-hit != 'true' 134 | id: bats-install 135 | shell: bash 136 | run: | 137 | # In $HOME to avoid sudo requirements 138 | VERSION=${{ inputs.bats-version }} 139 | DESTDIR="$HOME/.local/share/bats" 140 | TEMPDIR="/tmp/bats" 141 | URL="https://github.com/bats-core/bats-core/" 142 | 143 | # From https://github.com/fluxcd/flux2/blob/44d69d6fc0c353e79c1bad021a4aca135033bce8/action/action.yml#L35 144 | if [[ -z "$VERSION" ]] || [[ "$VERSION" = "latest" ]]; then 145 | VERSION=$(curl -fsSL --retry 4 --retry-connrefused -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/bats-core/bats-core/releases/latest | grep tag_name | cut -d '"' -f 4) 146 | fi 147 | [[ $VERSION == v* ]] && VERSION="${VERSION:1}" 148 | 149 | mkdir -p ${TEMPDIR} 150 | mkdir -p ${DESTDIR} 151 | 152 | curl -sL --retry 4 --retry-connrefused -H "Authorization: token $GITHUB_TOKEN" ${URL}/archive/refs/tags/v${VERSION}.tar.gz | tar xz -C ${TEMPDIR} --strip-components 1 && cd ${TEMPDIR} 153 | 154 | ./install.sh ${DESTDIR} 155 | echo "Bats v${VERSION} installed in ${DESTDIR}" 156 | echo "${DESTDIR}/bin" >> "$GITHUB_PATH" 157 | echo "bats-installed=true" >> $GITHUB_OUTPUT 158 | 159 | rm -rf ${TEMPDIR} || exit 0 160 | env: 161 | GITHUB_TOKEN: ${{ inputs.github-token }} 162 | 163 | - name: Set paths and commands for libraries 164 | shell: bash 165 | id: set-paths 166 | run: | 167 | if [[ "$RUNNER_OS" == "macOS" ]]; then 168 | DEFAULT_BASE_DIR="/usr/local/lib" 169 | [[ "${DEFAULT_BASE_DIR}" == "$HOME"* ]] && CMD="" || CMD="sudo" 170 | TEMPDIR="/tmp" 171 | elif [[ "$RUNNER_OS" == "Windows" ]]; then 172 | DEFAULT_BASE_DIR="/c/Users/runneradmin" 173 | CMD="" 174 | TEMPDIR="$HOME/AppData/Local/Temp" 175 | else 176 | DEFAULT_BASE_DIR="/usr/lib" 177 | [[ "${DEFAULT_BASE_DIR}" == "$HOME"* ]] && CMD="" || CMD="sudo" 178 | TEMPDIR="/tmp" 179 | fi 180 | 181 | echo "_LIB_PATH=$DEFAULT_BASE_DIR" >> /tmp/bats-lib-path 182 | echo "DEFAULT_BASE_DIR=$DEFAULT_BASE_DIR" >> $GITHUB_ENV 183 | echo "CMD=$CMD" >> $GITHUB_ENV 184 | echo "TEMPDIR=$TEMPDIR" >> $GITHUB_ENV 185 | echo "tmp-path=$TEMPDIR" >> $GITHUB_OUTPUT 186 | 187 | - name: "Calculate DESTDIR for Bats-support" 188 | if: inputs.support-install == 'true' 189 | id: calculate-support-destdir 190 | shell: bash 191 | run: | 192 | if [ -z "${{ inputs.support-path }}" ] || [ "${{ inputs.support-path }}" == "/usr/lib/bats-support" ]; then 193 | echo "SUPPORT_DESTDIR=${DEFAULT_BASE_DIR}/bats-support" >> $GITHUB_ENV 194 | else 195 | echo "SUPPORT_DESTDIR=${{ inputs.support-path }}" >> $GITHUB_ENV 196 | fi 197 | 198 | - name: "Set cache for Bats-support" 199 | if: inputs.support-install == 'true' 200 | uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4 201 | id: support-cache 202 | with: 203 | path: ${{ env.SUPPORT_DESTDIR }} 204 | key: ${{ runner.os }}-${{ runner.arch }}-bats-support-${{ inputs.support-version }} 205 | 206 | - name: "Download and install Bats-support" 207 | if: inputs.support-install == 'true' && steps.support-cache.outputs.cache-hit != 'true' 208 | id: support-install 209 | shell: bash 210 | run: | 211 | VERSION=${{ inputs.support-version }} 212 | url="https://github.com/bats-core/bats-support/archive/refs/tags/v${VERSION}.tar.gz" 213 | TEMPDIR="${TEMPDIR}/bats-support" 214 | DESTDIR=${SUPPORT_DESTDIR} 215 | 216 | mkdir -p ${TEMPDIR} 217 | ${CMD} mkdir -p ${DESTDIR}/src/ 218 | curl -sL --retry 4 --retry-connrefused ${url} | tar xz -C ${TEMPDIR} --strip-components 1 && cd ${TEMPDIR} 219 | # Archlinux style, except that we are not in a fakeroot env 220 | ${CMD} install -m755 load.bash ${DESTDIR}/load.bash 221 | for fn in src/*.bash; do 222 | ${CMD} install -m755 $fn \ 223 | ${DESTDIR}/src/$(basename $fn) 224 | done 225 | echo "Bats Support v$VERSION installed in $DESTDIR" 226 | echo "support-installed=true" >> $GITHUB_OUTPUT 227 | [[ "${{ inputs.support-clean }}" == "true" ]] && rm -rf ${TEMPDIR} || exit 0 228 | 229 | - name: "Calculate DESTDIR for Bats-assert" 230 | if: inputs.assert-install == 'true' 231 | id: calculate-assert-destdir 232 | shell: bash 233 | run: | 234 | if [ -z "${{ inputs.assert-path }}" ] || [ "${{ inputs.assert-path }}" == "/usr/lib/bats-assert" ]; then 235 | echo "ASSERT_DESTDIR=${DEFAULT_BASE_DIR}/bats-assert" >> $GITHUB_ENV 236 | else 237 | echo "ASSERT_DESTDIR=${{ inputs.assert-path }}" >> $GITHUB_ENV 238 | fi 239 | 240 | - name: "Set cache for Bats-assert" 241 | if: inputs.assert-install == 'true' 242 | uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4 243 | id: assert-cache 244 | with: 245 | path: ${{ env.ASSERT_DESTDIR }} 246 | key: ${{ runner.os }}-${{ runner.arch }}-bats-assert-${{ inputs.assert-version }} 247 | 248 | - name: "Download and install Bats-assert" 249 | if: inputs.assert-install == 'true' && steps.assert-cache.outputs.cache-hit != 'true' 250 | id: assert-install 251 | shell: bash 252 | run: | 253 | VERSION=${{ inputs.assert-version }} 254 | url="https://github.com/bats-core/bats-assert/archive/refs/tags/v${VERSION}.tar.gz" 255 | TEMPDIR="${TEMPDIR}/bats-assert" 256 | DESTDIR=${ASSERT_DESTDIR} 257 | 258 | mkdir -p ${TEMPDIR} 259 | ${CMD} mkdir -p ${DESTDIR}/src/ 260 | curl -sL --retry 4 --retry-connrefused ${url} | tar xz -C ${TEMPDIR} --strip-components 1 && cd ${TEMPDIR} 261 | # Archlinux style, except that we are not in a fakeroot env 262 | ${CMD} install -m755 load.bash ${DESTDIR}/load.bash 263 | for fn in src/*.bash; do 264 | ${CMD} install -m755 $fn \ 265 | ${DESTDIR}/src/$(basename $fn) 266 | done 267 | echo "Bats Assert v$VERSION installed in $DESTDIR" 268 | echo "assert-installed=true" >> "$GITHUB_OUTPUT" 269 | [[ "${{ inputs.assert-clean }}" == "true" ]] && rm -rf ${TEMPDIR} || exit 0 270 | 271 | - name: "Calculate DESTDIR for Bats-detik" 272 | if: inputs.detik-install == 'true' 273 | id: calculate-detik-destdir 274 | shell: bash 275 | run: | 276 | if [ -z "${{ inputs.detik-path }}" ] || [ "${{ inputs.detik-path }}" == "/usr/lib/bats-detik" ]; then 277 | echo "DETIK_DESTDIR=${DEFAULT_BASE_DIR}/bats-detik" >> $GITHUB_ENV 278 | else 279 | echo "DETIK_DESTDIR=${{ inputs.detik-path }}" >> $GITHUB_ENV 280 | fi 281 | 282 | - name: "Set cache for Bats-detik" 283 | if: inputs.detik-install == 'true' 284 | uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4 285 | id: detik-cache 286 | with: 287 | path: ${{ env.DETIK_DESTDIR }} 288 | key: ${{ runner.os }}-${{ runner.arch }}-bats-detik-${{ inputs.detik-version }} 289 | 290 | - name: "Download and install Bats-detik" 291 | if: inputs.detik-install == 'true' && steps.detik-cache.outputs.cache-hit != 'true' 292 | id: detik-install 293 | shell: bash 294 | run: | 295 | VERSION=${{ inputs.detik-version }} 296 | url="https://github.com/bats-core/bats-detik/archive/refs/tags/v${VERSION}.tar.gz" 297 | TEMPDIR="${TEMPDIR}/bats-detik" 298 | DESTDIR="${DETIK_DESTDIR}" 299 | 300 | mkdir -p ${TEMPDIR} 301 | ${CMD} mkdir -p ${DESTDIR}/src/ 302 | curl -sL --retry 4 --retry-connrefused ${url} | tar xz -C ${TEMPDIR} --strip-components 1 && cd ${TEMPDIR} 303 | # Archlinux style, except that we are not in a fakeroot env so we need to use sudo 304 | for fn in lib/*.bash; do 305 | ${CMD} install -m755 $fn \ 306 | ${DESTDIR}/$(basename $fn) 307 | done 308 | echo "Bats Detik v$VERSION installed in $DESTDIR" 309 | echo "detik-installed=true" >> $GITHUB_OUTPUT 310 | [[ "${{ inputs.detik-clean }}" == "true" ]] && rm -rf ${TEMPDIR} || exit 0 311 | 312 | - name: "Calculate DESTDIR for Bats-file" 313 | if: inputs.file-install == 'true' 314 | id: calculate-file-destdir 315 | shell: bash 316 | run: | 317 | if [ -z "${{ inputs.file-path }}" ] || [ "${{ inputs.file-path }}" == "/usr/lib/bats-file" ]; then 318 | echo "FILE_DESTDIR=${DEFAULT_BASE_DIR}/bats-file" >> $GITHUB_ENV 319 | else 320 | echo "FILE_DESTDIR=${{ inputs.file-path }}" >> $GITHUB_ENV 321 | fi 322 | 323 | - name: "Set cache for Bats-file" 324 | if: inputs.file-install == 'true' 325 | uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4 326 | id: file-cache 327 | with: 328 | path: ${{ env.FILE_DESTDIR }} 329 | key: ${{ runner.os }}-${{ runner.arch }}-bats-file-${{ inputs.file-version }} 330 | 331 | - name: "Download and install Bats-file" 332 | if: inputs.file-install == 'true' && steps.file-cache.outputs.cache-hit != 'true' 333 | id: file-install 334 | shell: bash 335 | run: | 336 | VERSION=${{ inputs.file-version }} 337 | url="https://github.com/bats-core/bats-file/archive/refs/tags/v${VERSION}.tar.gz" 338 | TEMPDIR="${TEMPDIR}/bats-file" 339 | DESTDIR="${FILE_DESTDIR}" 340 | 341 | mkdir -p ${TEMPDIR} 342 | ${CMD} mkdir -p ${DESTDIR}/src/ 343 | curl -sL --retry 4 --retry-connrefused ${url} | tar xz -C ${TEMPDIR} --strip-components 1 && cd ${TEMPDIR} 344 | # Archlinux style, except that we are not in a fakeroot env 345 | ${CMD} install -m755 load.bash ${DESTDIR}/load.bash 346 | for fn in src/*.bash; do 347 | ${CMD} install -m755 $fn \ 348 | ${DESTDIR}/src/$(basename $fn) 349 | done 350 | echo "Bats File v$VERSION installed in $DESTDIR" 351 | echo "file-installed=true" >> $GITHUB_OUTPUT 352 | [[ "${{ inputs.file-clean }}" == "true" ]] && rm -rf ${TEMPDIR} || exit 0 353 | 354 | - name: "build BATS_LIB_PATH" 355 | id: libpath 356 | shell: bash 357 | run: | 358 | # In case of windows if the path passed 359 | # as github workspace could be something like 360 | # D:\a\bats-action\bats-action/tests 361 | # so we need to translate D: into /d/ 362 | # and replace the wrong slash 363 | winfix() { 364 | local winpath="$1" 365 | echo "$winpath" | sed 's|\\|/|g' | sed 's|^\([A-Za-z]\):|/\L\1|' 366 | } 367 | if [[ "$RUNNER_OS" == "Windows" ]]; then 368 | S="$(winfix ${SUPPORT_DESTDIR%/*})" 369 | A="$(winfix ${ASSERT_DESTDIR%/*})" 370 | D="$(winfix ${DETIK_DESTDIR%/*})" 371 | F="$(winfix ${FILE_DESTDIR%/*})" 372 | LIB_PATH="${S}:${A}:${D}:${F}" 373 | else 374 | LIB_PATH="${SUPPORT_DESTDIR%/*}:${ASSERT_DESTDIR%/*}:${DETIK_DESTDIR%/*}:${FILE_DESTDIR%/*}" 375 | fi 376 | echo "libpath=$LIB_PATH" >> $GITHUB_OUTPUT 377 | 378 | 379 | - name: "Print info" 380 | id: info 381 | shell: bash 382 | run: | 383 | echo "Bats installed: ${{ (steps.bats-install.outputs.bats-installed != '') }}" 384 | echo "Support installed: ${{ (steps.support-install.outputs.support-installed != '') }}" 385 | echo "Assert installed: ${{ (steps.assert-install.outputs.assert-installed != '') }}" 386 | echo "Detik installed: ${{ (steps.detik-install.outputs.detik-installed != '') }}" 387 | echo "File installed: ${{ (steps.file-install.outputs.file-installed != '') }}" 388 | echo "Bats lib to use in BATS_LIB_PATH env ${{ steps.libpath.outputs.libpath }}" 389 | echo "Tmp path: ${{ steps.set-paths.outputs.tmp-path }}" 390 | -------------------------------------------------------------------------------- /tests/1-example-tests.bats: -------------------------------------------------------------------------------- 1 | setup() { 2 | load 'tests_helper' 3 | _tests_helper 4 | } 5 | 6 | #bats test_tags=github:true 7 | @test "0: Pre: Create file and dir" { 8 | _create_dir_file 9 | _delete_dir_file 10 | } 11 | 12 | #bats test_tags=github:true 13 | @test "1: Testing file existence" { 14 | _create_dir_file 15 | 16 | run ls testing/example 17 | assert_success 18 | run [ -f "testing/example" ] 19 | assert_success 20 | 21 | _delete_dir_file 22 | } 23 | 24 | #bats test_tags=github:true 25 | @test "2: Testing file permissions" { 26 | _create_dir_file 27 | if [[ "$(uname)" == "Darwin" ]]; then 28 | run stat -f%p testing/example 29 | else 30 | run stat -c "%a" testing/example 31 | fi 32 | assert_success 33 | if [[ "$(uname)" == "Darwin" ]]; then 34 | assert_output 100644 35 | else 36 | assert_output 644 37 | fi 38 | assert_file_permission 644 testing/example 39 | assert_success 40 | 41 | _delete_dir_file 42 | } 43 | 44 | #bats test_tags=github:true 45 | @test "3: Testing file content" { 46 | _create_dir_file 47 | 48 | run cat testing/example 49 | assert_success 50 | refute_output "Expected content" 51 | assert_file_empty testing/example 52 | assert_success 53 | 54 | _delete_dir_file 55 | } 56 | 57 | #bats test_tags=github:true 58 | @test "4: Testing directory creation" { 59 | _create_dir_file 60 | 61 | run mkdir testing/newdir 62 | assert_success 63 | 64 | [ -d "testing/newdir" ] 65 | assert_success 66 | 67 | run rmdir testing/newdir 68 | assert_success 69 | 70 | _delete_dir_file 71 | } 72 | 73 | #bats test_tags=github:true 74 | @test "5: Testing file creation and deletion inside directory" { 75 | _create_dir_file 76 | 77 | run mkdir testing/newdir 78 | assert_success 79 | 80 | run touch testing/newdir/newfile 81 | assert_success 82 | 83 | run [ -f "testing/newdir/newfile" ] 84 | assert_success 85 | 86 | run rm testing/newdir/newfile 87 | assert_success 88 | 89 | [ ! -f "testing/newdir/newfile" ] 90 | assert_success 91 | 92 | run rmdir testing/newdir 93 | assert_success 94 | 95 | run [ ! -d "testing/newdir" ] 96 | assert_success 97 | 98 | _delete_dir_file 99 | } 100 | -------------------------------------------------------------------------------- /tests/tests_helper.bash: -------------------------------------------------------------------------------- 1 | _tests_helper() { 2 | export BATS_LIB_PATH=${BATS_LIB_PATH:-"/usr/lib"} 3 | echo $BATS_LIB_PATH 4 | bats_load_library bats-support 5 | bats_load_library bats-assert 6 | bats_load_library bats-file 7 | bats_load_library bats-detik/detik.bash 8 | } 9 | 10 | _create_dir_file() { 11 | run mkdir testing 12 | assert_success 13 | 14 | run touch testing/example 15 | assert_success 16 | } 17 | 18 | _delete_dir_file() { 19 | run rm testing/example 20 | assert_success 21 | 22 | run rmdir testing 23 | assert_success 24 | } 25 | --------------------------------------------------------------------------------