diff --git a/vendor/README.md b/vendor/README.md index 948d6825..84328100 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -1,15 +1,10 @@ README for git-secret/vendor directory -We import bats-core v1.3.0 here for +We import bats-core here for https://github.com/sobolevn/git-secret/issues/377, "Don't depend on network during builds (re: bats-core)" -If you want upgrade bats-core, replace the files in vendor/bats-core. +If you want upgrade bats-core used by git-secret, replace the files in vendor/bats-core. They must remain exactly as distributed by the chosen release of bats-core - see issue linked above for details. - -## Changes: - -- 2021-05-03: Version update from `bats-core@1.1.0` to `bats-core@1.3.0` -- Initial import of `bats-core@1.1.0` diff --git a/vendor/bats-core/.github/ISSUE_TEMPLATE/bug_report.md b/vendor/bats-core/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..d11ac0aa --- /dev/null +++ b/vendor/bats-core/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,29 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: 'Type: Bug' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Environment (please complete the following information):** + - Bats Version [e.g. 1.4.0 or commit hash] + - OS: [e.g. Linux, FreeBSD, MacOS] + - Bash version: [e.g. 5.1] + +**Additional context** +Add any other context about the problem here. diff --git a/vendor/bats-core/.github/ISSUE_TEMPLATE/feature_request.md b/vendor/bats-core/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..0033b7e0 --- /dev/null +++ b/vendor/bats-core/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: 'Type: Enhancement' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context about the feature request here. diff --git a/vendor/bats-core/.github/workflows/check_pr_label.sh b/vendor/bats-core/.github/workflows/check_pr_label.sh new file mode 100755 index 00000000..197335bd --- /dev/null +++ b/vendor/bats-core/.github/workflows/check_pr_label.sh @@ -0,0 +1,10 @@ +#!/usr/bin/bash + +get_pr_json() { + curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/bats-core/bats-core/pulls/$1" +} + +PR_NUMBER="$1" +LABEL="$2" + +get_pr_json "$PR_NUMBER" | jq .labels[].name | grep "$LABEL" diff --git a/vendor/bats-core/.github/workflows/release.yml b/vendor/bats-core/.github/workflows/release.yml new file mode 100644 index 00000000..5fbb478b --- /dev/null +++ b/vendor/bats-core/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: Release + +on: + release: { types: [published] } + workflow_dispatch: + +jobs: + npmjs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + registry-url: "https://registry.npmjs.org" + - run: npm publish --ignore-scripts + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + github-npm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + registry-url: "https://npm.pkg.github.com" + - name: scope package name as required by GHPR + run: npm init -y --scope ${{ github.repository_owner }} + - run: npm publish --ignore-scripts + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/vendor/bats-core/.github/workflows/release_dockerhub.yml b/vendor/bats-core/.github/workflows/release_dockerhub.yml new file mode 100644 index 00000000..584c9b9b --- /dev/null +++ b/vendor/bats-core/.github/workflows/release_dockerhub.yml @@ -0,0 +1,38 @@ +name: Release to docker hub + +on: + release: { types: [published] } + workflow_dispatch: + inputs: + version: + description: 'Version to simulate for deploy' + required: true + +jobs: + dockerhub: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - id: version + run: | + EXPECTED_VERSION=${{ github.event.inputs.version }} + TAG_VERSION=${GITHUB_REF#refs/tags/v} # refs/tags/v1.2.3 -> 1.2.3 + echo ::set-output name=version::${EXPECTED_VERSION:-$TAG_VERSION} + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - + name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + - uses: docker/build-push-action@v2 + with: + platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6 + tags: ${{ secrets.DOCKER_USERNAME }}/bats:${{ steps.version.outputs.version }},${{ secrets.DOCKER_USERNAME }}/bats:latest + push: true diff --git a/vendor/bats-core/.github/workflows/tests.yml b/vendor/bats-core/.github/workflows/tests.yml new file mode 100644 index 00000000..c3227d90 --- /dev/null +++ b/vendor/bats-core/.github/workflows/tests.yml @@ -0,0 +1,167 @@ +name: Tests + +# Controls when the action will run. +on: [push, pull_request, workflow_dispatch] + +jobs: + changelog: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Check that PR is mentioned in Changelog + run: | + if ! ./.github/workflows/check_pr_label.sh "${{github.event.pull_request.number}}" "no changelog"; then + grep "#${{github.event.pull_request.number}}" docs/CHANGELOG.md + fi + if: ${{github.event.pull_request}} + shellcheck: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Run shellcheck + run: | + sudo apt-get update -y + sudo apt-get install shellcheck + ./shellcheck.sh + + linux: + strategy: + matrix: + os: ['ubuntu-20.04', 'ubuntu-18.04'] + env_vars: + - '' + # allow for some parallelity without GNU parallel, since it is not installed by default + - 'BATS_NO_PARALLELIZE_ACROSS_FILES=1 BATS_NUMBER_OF_PARALLEL_JOBS=2' + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - name: Run test on OS ${{ matrix.os }} + shell: 'script -q -e -c "bash {0}"' # work around tty issues + env: + TERM: linux # fix tput for tty issue work around + run: | + bash --version + bash -c "time ${{ matrix.env_vars }} bin/bats --print-output-on-failure --formatter tap test" + + npm_on_linux: + strategy: + matrix: + os: ['ubuntu-20.04', 'ubuntu-18.04'] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + - name: Run test on OS ${{ matrix.os }} + shell: 'script -q -e -c "bash {0}"' # work around tty issues + env: + TERM: linux # fix tput for tty issue work around + run: | + npm pack ./ + sudo npm install -g ./bats-*.tgz + bats test + + windows: + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + - run: | + bash --version + bash -c "time bin/bats --print-output-on-failure --formatter tap test" + + npm_on_windows: + strategy: + matrix: + os: ['windows-2019'] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + - run: npm pack ./ + - run: npm install -g (get-item .\bats-*.tgz).FullName + - run: bats -T --print-output-on-failure test + + macos: + strategy: + matrix: + os: ['macos-10.15'] + env_vars: + - '' + # allow for some parallelity without GNU parallel, since it is not installed by default + - 'BATS_NO_PARALLELIZE_ACROSS_FILES=1 BATS_NUMBER_OF_PARALLEL_JOBS=2' + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - name: Install unbuffer via expect + run: brew install expect + - name: Run test on OS ${{ matrix.os }} + shell: 'unbuffer bash {0}' # work around tty issues + env: + TERM: linux # fix tput for tty issue work around + run: | + bash --version + bash -c "time ${{ matrix.env_vars }} bin/bats --print-output-on-failure --formatter tap test" + + npm_on_macos: + strategy: + matrix: + os: ['macos-10.15'] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + - name: Install unbuffer via expect + run: brew install expect + - name: Run test on OS ${{ matrix.os }} + shell: 'unbuffer bash {0}' # work around tty issues + env: + TERM: linux # fix tput for tty issue work around + run: | + npm pack ./ + # somehow there is already an intalled bats version around + npm install --force -g ./bats-*.tgz + bats --print-output-on-failure test + + bash-version: + strategy: + matrix: + version: ['3.2', '4.0', '4.1', '4.2', '4.3', '4.4', '4', '5.0', '5.1', '5', 'latest'] + env_vars: + - '' + # also test running (recursively!) in parallel + - '-e BATS_NUMBER_OF_PARALLEL_JOBS=2' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run test on bash version ${{ matrix.version }} + shell: 'script -q -e -c "bash {0}"' # work around tty issues + run: | + set -e + docker build --build-arg bashver="${{ matrix.version }}" --tag "bats/bats:bash-${{ matrix.version }}" . + docker run -it "bash:${{ matrix.version }}" --version + time docker run -it ${{ matrix.env_vars }} "bats/bats:bash-${{ matrix.version }}" --print-output-on-failure --tap /opt/bats/test + + alpine: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run test on bash version ${{ matrix.version }} + shell: 'script -q -e -c "bash {0}"' # work around tty issues + run: | + set -e + time docker run -it -v $PWD:/opt/bats alpine sh -c "apk add bash ncurses; /opt/bats/bin/bats --print-output-on-failure --tap /opt/bats/test" + + freebsd: + runs-on: macos-10.15 + strategy: + matrix: + packages: + - flock + - "" + steps: + - uses: actions/checkout@v2 + - uses: vmactions/freebsd-vm@v0.1.5 + with: + prepare: pkg install -y bash parallel ${{ matrix.packages }} + run: | + time ./bin/bats --print-output-on-failure test/ + diff --git a/vendor/bats-core/README.md b/vendor/bats-core/README.md index 77b08668..1e8eea02 100644 --- a/vendor/bats-core/README.md +++ b/vendor/bats-core/README.md @@ -11,8 +11,6 @@ Bats is a [TAP](https://testanything.org/)-compliant testing framework for Bash. It provides a simple way to verify that the UNIX programs you write behave as expected. -[TAP]: https://testanything.org - A Bats test file is a Bash script with special syntax for defining test cases. Under the hood, each test case is just a function with a description. @@ -86,8 +84,7 @@ or look at the other communication channels. ## Contact -- We are `#bats` on freenode; -- Or leave a message on [gitter]. +- You can find and chat with us on our [Gitter]. ## Version history @@ -127,4 +124,4 @@ Bats is released under an MIT-style license; see `LICENSE.md` for details. See the [parent project](https://github.com/bats-core) at GitHub or the [AUTHORS](AUTHORS) file for the current project maintainer team. -[gitter]: https://gitter.im/bats-core/bats-core?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge +[gitter]: https://gitter.im/bats-core/bats-core diff --git a/vendor/bats-core/contrib/rpm/bats.spec b/vendor/bats-core/contrib/rpm/bats.spec index 2d6ad9a5..f4a86d02 100644 --- a/vendor/bats-core/contrib/rpm/bats.spec +++ b/vendor/bats-core/contrib/rpm/bats.spec @@ -3,7 +3,7 @@ %global repo bats-core Name: bats -Version: 1.5.0 +Version: 1.6.0 Release: 1%{?dist} Summary: Bash Automated Testing System diff --git a/vendor/bats-core/docs/CHANGELOG.md b/vendor/bats-core/docs/CHANGELOG.md index 71fe28d5..e64c58d1 100644 --- a/vendor/bats-core/docs/CHANGELOG.md +++ b/vendor/bats-core/docs/CHANGELOG.md @@ -8,6 +8,35 @@ The format is based on [Keep a Changelog][kac] and this project adheres to [kac]: https://keepachangelog.com/en/1.0.0/ [semver]: https://semver.org/ +## [Unreleased] + +## [1.6.0] - 2022-02-24 + +### Added + +* new flag `--code-quote-style` (and `$BATS_CODE_QUOTE_STYLE`) to customize +quotes around code blocks in error output (#506) +* an example/regression test for running background tasks without blocking the + test run (#525, #535) +* `bats_load_library` for loading libraries from the search path + `$BATS_LIB_PATH` (#548) + +### Fixed + +* improved error trace for some broken cases (#279) +* removed leftover debug file `/tmp/latch` in selftest suite + (single use latch) (#516) +* fix recurring errors on CTRL+C tests with NPM on Windows in selftest suite (#516) +* fixed leaking of local variables from debug trap (#520) +* don't mark FD3 output from `teardown_file` as `` in junit output (#532) +* fix unbound variable error with Bash pre 4.4 (#550) + +#### Documentation + +* remove links to defunct freenode IRC channel (#515) +* improved grammar (#534) +* fixed link to TAP spec (#537) + ## [1.5.0] - 2021-10-22 ### Added diff --git a/vendor/bats-core/docs/CONTRIBUTING.md b/vendor/bats-core/docs/CONTRIBUTING.md index 9d48969d..b8501627 100644 --- a/vendor/bats-core/docs/CONTRIBUTING.md +++ b/vendor/bats-core/docs/CONTRIBUTING.md @@ -57,8 +57,7 @@ CONTRIBUTING.md file][atom]. ## Quick links 🔗 -- [Gitter channel →][gitterurl]: These messages sync with the IRC channel -- [IRC Channel (#bats on freenode) →][ircurl]: These messages sync with Gitter +- [Gitter channel →][gitterurl]: Feel free to come chat with us on Gitter - [README →][README] - [Code of conduct →][CODE_OF_CONDUCT] - [License information →][LICENSE] @@ -101,7 +100,7 @@ specifics, see the [CODE_OF_CONDUCT][] file. Please check the [README][] or existing [issues][repoissues] first. If you cannot find an answer to your question, please feel free to hop on our -[gitter][gitterurl] [![Gitter](https://badges.gitter.im/bats-core/bats-core.svg)](https://gitter.im/bats-core/bats-core?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) or [via IRC (#bats on freenode)][ircurl]. +[Gitter][gitterurl]. [![Gitter](https://badges.gitter.im/bats-core/bats-core.svg)](https://gitter.im/bats-core/bats-core) ### Reporting issues @@ -391,4 +390,3 @@ by the [Free Software Foundation](https://www.fsf.org/), 2016 under the [Free Ar [osmit]: https://opensource.org/licenses/MIT [gitterurl]: https://gitter.im/bats-core/bats-core -[ircurl]: https://kiwiirc.com/client/irc.freenode.net:+6697/#bats diff --git a/vendor/bats-core/docs/source/conf.py b/vendor/bats-core/docs/source/conf.py index 88cca585..f0fee077 100644 --- a/vendor/bats-core/docs/source/conf.py +++ b/vendor/bats-core/docs/source/conf.py @@ -18,8 +18,8 @@ # -- Project information ----------------------------------------------------- project = 'bats-core' -copyright = '2021, bats-core origanization' -author = 'bats-core origanization' +copyright = '2021, bats-core organization' +author = 'bats-core organization' # The full version, including alpha/beta/rc tags release = '1' @@ -69,4 +69,4 @@ def setup(app): app.add_config_value('recommonmark_config', {'enable_eval_rst': True}, True) import recommonmark from recommonmark.transform import AutoStructify - app.add_transform(AutoStructify) \ No newline at end of file + app.add_transform(AutoStructify) diff --git a/vendor/bats-core/docs/source/faq.rst b/vendor/bats-core/docs/source/faq.rst index e1abc915..ebe1edf7 100644 --- a/vendor/bats-core/docs/source/faq.rst +++ b/vendor/bats-core/docs/source/faq.rst @@ -6,7 +6,7 @@ How do I set the working directory? The working directory is simply the directory where you started when executing bats. If you want to enforce a specific directory, you can use `cd` in the `setup_file`/`setup` functions. -However, be aware that code outside any function will run before any of these setup functions and my interfere with bats' internals. +However, be aware that code outside any function will run before any of these setup functions and might interfere with bats' internals. How do I see the output of the command under `run` when a test fails? @@ -166,4 +166,4 @@ There is also `BATS_TEST_SKIPPED` which will be non-empty (contains the skip mes How can I setup/cleanup before/after all tests? ----------------------------------------------- -Currently, this is not supported. Please contribute your usecase to issue `#39 `_. \ No newline at end of file +Currently, this is not supported. Please contribute your usecase to issue `#39 `_. diff --git a/vendor/bats-core/docs/source/gotchas.rst b/vendor/bats-core/docs/source/gotchas.rst index cba55ace..17dfc05d 100644 --- a/vendor/bats-core/docs/source/gotchas.rst +++ b/vendor/bats-core/docs/source/gotchas.rst @@ -118,3 +118,14 @@ don't abort the test when they fail, unless they are the last command before the making their exit code the return code. `[ ]` does not suffer from this, but is no replacement for all `[[ ]]` usecases. Appending ` || false` will work in all cases. + +Background tasks prevent the test run from terminating when finished +-------------------------------------------------------------------- + +When running a task in background, it will inherit the opened FDs of the process it was forked from. +This means that the background task forked from a Bats test will hold the FD for the pipe to the formatter that prints to the terminal, +thus keeping it open until the background task finished. +Due to implementation internals of Bats and bash, this pipe might be held in multiple FDs which all have to be closed by the background task. + +You can use `close_non_std_fds from `test/fixtures/bats/issue-205.bats` in the background job to close all FDs except stdin, stdout and stderr, thus solving the problem. +More details about the issue can be found in [#205](https://github.com/bats-core/bats-core/issues/205#issuecomment-973572596). diff --git a/vendor/bats-core/docs/source/usage.md b/vendor/bats-core/docs/source/usage.md index 52716187..ad0d6694 100644 --- a/vendor/bats-core/docs/source/usage.md +++ b/vendor/bats-core/docs/source/usage.md @@ -32,7 +32,7 @@ $ bats addition.bats If Bats is not connected to a terminal—in other words, if you run it from a continuous integration system, or redirect its output to a file—the results are -displayed in human-readable, machine-parsable [TAP format][TAP]. +displayed in human-readable, machine-parsable [TAP format][https://testanything.org]. You can force TAP output from a terminal by invoking Bats with the `--formatter tap` option. diff --git a/vendor/bats-core/docs/source/writing-tests.md b/vendor/bats-core/docs/source/writing-tests.md index cf365d32..8e96515d 100644 --- a/vendor/bats-core/docs/source/writing-tests.md +++ b/vendor/bats-core/docs/source/writing-tests.md @@ -12,6 +12,23 @@ For sample test files, see [examples](https://github.com/bats-core/bats-core/tre [bats-eval]: https://github.com/bats-core/bats-core/wiki/Bats-Evaluation-Process +## Comment syntax + +External tools (like `shellcheck`, `shfmt`, and various IDE's) may not support +the standard `.bats` syntax. Because of this, we provide a valid `bash` +alternative: + +```bash +function invoking_foo_without_arguments_prints_usage { #@test + run foo + [ "$status" -eq 1 ] + [ "${lines[0]}" = "usage: foo " ] +} +``` + +When using this syntax, the function name will be the title in the result output +and the value checked when using `--filter`. + ## `run`: Test other commands Many Bats tests need to run a command and then make assertions about its exit @@ -80,29 +97,13 @@ All additional parameters to run should come before the command. If you want to run a command that starts with `-`, prefix it with `--` to prevent `run` from parsing it as an option. -## Comment syntax - -External tools (like `shellcheck`, `shfmt`, and various IDE's) may not support -the standard `.bats` syntax. Because of this, we provide a valid `bash` -alternative: - -```bash -function invoking_foo_without_arguments_prints_usage { #@test - run foo - [ "$status" -eq 1 ] - [ "${lines[0]}" = "usage: foo " ] -} -``` - -When using this syntax, the function name will be the title in the result output -and the value checked when using `--filter`. - ## `load`: Share common code -You may want to share common code across multiple test files. Bats includes a -convenient `load` command for sourcing a Bash source file relative to the -location of the current test file. For example, if you have a Bats test in -`test/foo.bats`, the command +You may want to share common code across multiple test files. Bats +includes a convenient `load` command for sourcing a Bash source files +relative to the current test file and from absolute paths. + +For example, if you have a Bats test in `test/foo.bats`, the command ```bash load test_helper.bash @@ -111,18 +112,83 @@ load test_helper.bash will source the script `test/test_helper.bash` in your test file (limitations apply, see below). This can be useful for sharing functions to set up your environment or load fixtures. `load` delegates to Bash's `source` command after -resolving relative paths. +resolving paths. + +If `load` encounters errors - e.g. because the targeted source file +errored - it will print a message with the failing library and Bats +exits. -As pointed out by @iatrou in , +To allow to use `load` in conditions `bats_load_safe` has been added. +`bats_load_safe` prints a message and returns `1` if a source file cannot be +loaded instead of exiting Bats. +Aside from that `bats_load_safe` acts exactly like `load`. + +As pointed out by @iatrou in https://www.tldp.org/LDP/abs/html/declareref.html, using the `declare` builtin restricts scope of a variable. Thus, since actual `source`-ing is performed in context of the `load` function, `declare`d symbols will _not_ be made available to callers of `load`. +### `load` argument resolution + +`load` supports the following arguments: + +- absolute paths +- relative paths (to the current test file) + > For backwards compatibility `load` first searches for a file ending in > `.bash` (e.g. `load test_helper` searches for `test_helper.bash` before > it looks for `test_helper`). This behaviour is deprecated and subject to > change, please use exact filenames instead. +If `argument` is an absolute path `load` tries to determine the load +path directly. + +If `argument` is a relative path or a name `load` looks for a matching +path in the directory of the current test. + +## `bats_load_library`: Load system wide libraries + +Some libraries are installed on the system, e.g. by `npm` or `brew`. +These should not be `load`ed, as their path depends on the installation method. +Instead, one should use `bats_load_library` together with setting +`BATS_LIB_PATH`, a `PATH`-like colon-delimited variable. + +`bats_load_library` has two modes of resolving requests: + +1. by relative path from the `BATS_LIB_PATH` to a file in the library +2. by library name, expecting libraries to have a `load.bash` entrypoint + +For example if your `BATS_LIB_PATH` is set to +`~/.bats/libs:/usr/lib/bats`, then `bats_load_library test_helper` +would look for existing files with the following paths: + +- `~/.bats/libs/test_helper` +- `~/.bats/libs/test_helper/load.bash` +- `/usr/lib/bats/test_helper` +- `/usr/lib/bats/test_helper/load.bash` + +The first existing file in this list will be sourced. + +If you want to load only part of a library or the entry point is not named `load.bash`, +you have to include it in the argument: +`bats_load_library library_name/file_to_load` will try + +- `~/.bats/libs/library_name/file_to_load` +- `~/.bats/libs/library_name/file_to_load/load.bash` +- `/usr/lib/bats/library_name/file_to_load` +- `/usr/lib/bats/library_name/file_to_load/load.bash` + +Apart from the changed lookup rules, `bats_load_library` behaves like `load`. + +__Note:__ As seen above `load.bash` is the entry point for libraries and +meant to load more files from its directory or other libraries. + +__Note:__ Obviously, the actual `BATS_LIB_PATH` is highly dependant on the environment. +To maintain a uniform location across systems, (distribution) package maintainers +are encouraged to use `/usr/lib/bats/` as the install path for libraries where possible. +However, if the package manager has another preferred location, like `npm` or `brew`, +you should use this instead. + ## `skip`: Easily skip tests Tests can be skipped by using the `skip` command at the point in a test you wish @@ -225,7 +291,7 @@ that may launch long-running child processes**, e.g. `command_name 3>&-` . ## Printing to the terminal -Bats produces output compliant with [version 12 of the TAP protocol][TAP]. The +Bats produces output compliant with [version 12 of the TAP protocol](https://testanything.org/tap-specification.html). The produced TAP stream is by default piped to a pretty formatter for human consumption, but if Bats is called with the `-t` flag, then the TAP stream is directly printed to the console. diff --git a/vendor/bats-core/lib/bats-core/common.bash b/vendor/bats-core/lib/bats-core/common.bash index e6a5963d..891763f4 100644 --- a/vendor/bats-core/lib/bats-core/common.bash +++ b/vendor/bats-core/lib/bats-core/common.bash @@ -7,4 +7,18 @@ bats_prefix_lines_for_tap_output() { if [[ -n "$line" ]]; then printf '# %s\n' "$line" fi -} \ No newline at end of file +} + +function bats_replace_filename() { + local line + while read -r line; do + printf "%s\n" "${line//$BATS_TEST_SOURCE/$BATS_TEST_FILENAME}" + done + if [[ -n "$line" ]]; then + printf "%s\n" "${line//$BATS_TEST_SOURCE/$BATS_TEST_FILENAME}" + fi +} + +bats_quote_code() { # + printf -v "$1" -- "%s%s%s" "$BATS_BEGIN_CODE_QUOTE" "$2" "$BATS_END_CODE_QUOTE" +} diff --git a/vendor/bats-core/lib/bats-core/formatter.bash b/vendor/bats-core/lib/bats-core/formatter.bash index 05b60645..5d87b2e2 100644 --- a/vendor/bats-core/lib/bats-core/formatter.bash +++ b/vendor/bats-core/lib/bats-core/formatter.bash @@ -43,15 +43,16 @@ function bats_parse_internal_extended_tap() { ;; 'ok '*) ((++index)) - scope=ok if [[ "$line" =~ $ok_line_regexpr ]]; then ok_index="${BASH_REMATCH[1]}" test_name="${BASH_REMATCH[2]}" if [[ "$line" =~ $skip_line_regexpr ]]; then + scope=skipped test_name="${BASH_REMATCH[2]}" # cut off name before "# skip" local skip_reason="${BASH_REMATCH[4]}" bats_tap_stream_skipped "$ok_index" "$test_name" "$skip_reason" else + scope=ok if [[ "$line" =~ $timing_expr ]]; then bats_tap_stream_ok --duration "${BASH_REMATCH[1]}" "$ok_index" "$test_name" else diff --git a/vendor/bats-core/lib/bats-core/test_functions.bash b/vendor/bats-core/lib/bats-core/test_functions.bash index 33434a04..55eef95c 100644 --- a/vendor/bats-core/lib/bats-core/test_functions.bash +++ b/vendor/bats-core/lib/bats-core/test_functions.bash @@ -3,30 +3,162 @@ BATS_TEST_DIRNAME="${BATS_TEST_FILENAME%/*}" BATS_TEST_NAMES=() -# Shorthand for source-ing files relative to the BATS_TEST_DIRNAME, -# optionally with a .bash suffix appended. If the argument doesn't -# resolve relative to BATS_TEST_DIRNAME it is sourced as-is. -load() { - local file="${1:?}" - - # For backwards-compatibility first look for a .bash-suffixed file. - # TODO consider flipping the order here; it would be more consistent - # and less surprising to look for an exact-match first. - if [[ -f "${BATS_TEST_DIRNAME}/${file}.bash" ]]; then - file="${BATS_TEST_DIRNAME}/${file}.bash" - elif [[ -f "${BATS_TEST_DIRNAME}/${file}" ]]; then - file="${BATS_TEST_DIRNAME}/${file}" +# find_in_bats_lib_path echoes the first recognized load path to +# a library in BATS_LIB_PATH or relative to BATS_TEST_DIRNAME. +# +# Libraries relative to BATS_TEST_DIRNAME take precedence over +# BATS_LIB_PATH. +# +# Library load paths are recognized using find_library_load_path. +# +# If no library is found find_in_bats_lib_path returns 1. +find_in_bats_lib_path() { # + local return_var="${1:?}" + local library_name="${2:?}" + + local -a bats_lib_paths + IFS=: read -ra bats_lib_paths <<< "$BATS_LIB_PATH" + + for path in "${bats_lib_paths[@]}"; do + if [[ -f "$path/$library_name" ]]; then + printf -v "$return_var" "%s" "$path/$library_name" + # A library load path was found, return + return + elif [[ -f "$path/$library_name/load.bash" ]]; then + printf -v "$return_var" "%s" "$path/$library_name/load.bash" + # A library load path was found, return + return + fi + done + + return 1 +} + +# bats_internal_load expects an absolute path that is a library load path. +# +# If the library load path points to a file (a library loader) it is +# sourced. +# +# If it points to a directory all files ending in .bash inside of the +# directory are sourced. +# +# If the sourcing of the library loader or of a file in a library +# directory fails bats_internal_load prints an error message and returns 1. +# +# If the passed library load path is not absolute or is not a valid file +# or directory bats_internal_load prints an error message and returns 1. +bats_internal_load() { + local library_load_path="${1:?}" + + if [[ "${library_load_path:0:1}" != / ]]; then + printf "Passed library load path is not an absolute path: %s\n" "$library_load_path" >&2 + return 1 + fi + + # library_load_path is a library loader + if [[ -f "$library_load_path" ]]; then + # shellcheck disable=SC1090 + if ! source "$library_load_path"; then + printf "Error while sourcing library loader at '%s'\n" "$library_load_path" >&2 + return 1 + fi + return + fi + + printf "Passed library load path is neither a library loader nor library directory: %s\n" "$library_load_path" >&2 + return 1 +} + +# bats_load_safe accepts an argument called 'slug' and attempts to find and +# source a library based on the slug. +# +# A slug can be an absolute path, a library name or a relative path. +# +# If the slug is an absolute path bats_load_safe attempts to find the library +# load path using find_library_load_path. +# What is considered a library load path is documented in the +# documentation for find_library_load_path. +# +# If the slug is not an absolute path it is considered a library name or +# relative path. bats_load_safe attempts to find the library load path using +# find_in_bats_lib_path. +# +# If bats_load_safe can find a library load path it is passed to bats_internal_load. +# If bats_internal_load fails bats_load_safe returns 1. +# +# If no library load path can be found bats_load_safe prints an error message +# and returns 1. +bats_load_safe() { + local slug="${1:?}" + if [[ ${slug:0:1} != / ]]; then # relative paths are relative to BATS_TEST_DIRNAME + slug="$BATS_TEST_DIRNAME/$slug" fi - if [[ ! -f "$file" ]] && ! type -P "$file" >/dev/null; then - printf 'bats: %s does not exist\n' "$file" >&2 + if [[ -f "$slug.bash" ]]; then + bats_internal_load "$slug.bash" + return + elif [[ -f "$slug" ]]; then + bats_internal_load "$slug" + return + fi + + # loading from PATH (retained for backwards compatibility) + if [[ ! -f "$1" ]] && type -P "$1" >/dev/null; then + # shellcheck disable=SC1090 + source "$1" + return + fi + + # No library load path can be found + printf "bats_load_safe: Could not find '%s'[.bash]\n" "$slug" >&2 + return 1 +} + +bats_require_lib_path() { + if [[ -z "${BATS_LIB_PATH:-}" ]]; then + printf "%s: requires BATS_LIB_PATH to be set!\n" "${FUNCNAME[1]}" >&2 exit 1 fi +} + +bats_load_library_safe() { # + local slug="${1:?}" library_path + + bats_require_lib_path + + # Check for library load paths in BATS_TEST_DIRNAME and BATS_LIB_PATH + if [[ ${slug:0:1} != / ]]; then + find_in_bats_lib_path library_path "$slug" + if [[ -z "$library_path" ]]; then + printf "Could not find library '%s' relative to test file or in BATS_LIB_PATH\n" "$slug" >&2 + return 1 + fi + else + # absolute paths are taken as is + library_path="$slug" + if [[ ! -f "$library_path" ]]; then + printf "Could not find library on absolute path '%s'\n" "$library_path" >&2 + return 1 + fi + fi - # Dynamically loaded user file provided outside of Bats. - # Note: 'source "$file" || exit' doesn't work on bash3.2. - # shellcheck disable=SC1090 - source "${file}" + bats_internal_load "$library_path" + return $? +} + +# immediately exit on error, use bats_load_library_safe to catch and handle errors +bats_load_library() { # + bats_require_lib_path + if ! bats_load_library_safe "$@"; then + exit 1 + fi +} + +# load acts like bats_load_safe but exits the shell instead of returning 1. +load() { + if ! bats_load_safe "$@"; then + exit 1 + fi } bats_redirect_stderr_into_file() { @@ -39,8 +171,8 @@ bats_merge_stdout_and_stderr() { # write separate lines from into bats_separate_lines() { # - output_array_name="$1" - input_var_name="$2" + local output_array_name="$1" + local input_var_name="$2" if [[ $keep_empty_lines ]]; then local bats_separate_lines_lines=() while IFS= read -r line; do @@ -49,11 +181,14 @@ bats_separate_lines() { # eval "${output_array_name}=(\"\${bats_separate_lines_lines[@]}\")" else # shellcheck disable=SC2034,SC2206 - IFS=$'\n' read -d '' -r -a "$output_array_name" <<<"${!input_var_name}" + IFS=$'\n' read -d '' -r -a "$output_array_name" <<<"${!input_var_name}" || true # don't fail due to EOF fi } run() { # [!|-N] [--keep-empty-lines] [--separate-stderr] [--] + # This has to be restored on exit from this function to avoid leaking our trap INT into surrounding code. + # Non zero exits won't restore under the assumption that they will fail the test before it can be aborted, + # which allows us to avoid duplicating the restore code on every exit path trap bats_interrupt_trap_in_run INT local expected_rc= local keep_empty_lines= @@ -84,6 +219,10 @@ run() { # [!|-N] [--keep-empty-lines] [--separate-stderr] [--] &2 + return 1 + ;; esac shift done @@ -104,17 +243,16 @@ run() { # [!|-N] [--keep-empty-lines] [--separate-stderr] [--] - local output_var="$1" - local path="$2" + local output_var="$1" path="$2" + if [[ "$output_var" != NORMALIZED_INPUT ]]; then + local NORMALIZED_INPUT + fi if [[ $path == ?:* ]]; then NORMALIZED_INPUT="$(cd "$path" || exit 1; pwd)" else @@ -169,6 +185,52 @@ bats_emit_trace() { fi } +# bats_debug_trap tracks the last line of code executed within a test. This is +# necessary because $BASH_LINENO is often incorrect inside of ERR and EXIT +# trap handlers. +# +# Below are tables describing different command failure scenarios and the +# reliability of $BASH_LINENO within different the executed DEBUG, ERR, and EXIT +# trap handlers. Naturally, the behaviors change between versions of Bash. +# +# Table rows should be read left to right. For example, on bash version +# 4.0.44(2)-release, if a test executes `false` (or any other failing external +# command), bash will do the following in order: +# 1. Call the DEBUG trap handler (bats_debug_trap) with $BASH_LINENO referring +# to the source line containing the `false` command, then +# 2. Call the DEBUG trap handler again, but with an incorrect $BASH_LINENO, then +# 3. Call the ERR trap handler, but with a (possibly-different) incorrect +# $BASH_LINENO, then +# 4. Call the DEBUG trap handler again, but with $BASH_LINENO set to 1, then +# 5. Call the EXIT trap handler, with $BASH_LINENO set to 1. +# +# bash version 4.4.20(1)-release +# command | first DEBUG | second DEBUG | ERR | third DEBUG | EXIT +# -------------+-------------+--------------+---------+-------------+-------- +# false | OK | OK | OK | BAD[1] | BAD[1] +# [[ 1 = 2 ]] | OK | BAD[2] | BAD[2] | BAD[1] | BAD[1] +# (( 1 = 2 )) | OK | BAD[2] | BAD[2] | BAD[1] | BAD[1] +# ! true | OK | --- | BAD[4] | --- | BAD[1] +# $var_dne | OK | --- | --- | BAD[1] | BAD[1] +# source /dne | OK | --- | --- | BAD[1] | BAD[1] +# +# bash version 4.0.44(2)-release +# command | first DEBUG | second DEBUG | ERR | third DEBUG | EXIT +# -------------+-------------+--------------+---------+-------------+-------- +# false | OK | BAD[3] | BAD[3] | BAD[1] | BAD[1] +# [[ 1 = 2 ]] | OK | --- | BAD[3] | --- | BAD[1] +# (( 1 = 2 )) | OK | --- | BAD[3] | --- | BAD[1] +# ! true | OK | --- | BAD[3] | --- | BAD[1] +# $var_dne | OK | --- | --- | BAD[1] | BAD[1] +# source /dne | OK | --- | --- | BAD[1] | BAD[1] +# +# [1] The reported line number is always 1. +# [2] The reported source location is that of the beginning of the function +# calling the command. +# [3] The reported line is that of the last command executed in the DEBUG trap +# handler. +# [4] The reported source location is that of the call to the function calling +# the command. bats_debug_trap() { # on windows we sometimes get a mix of paths (when install via nmp install -g) # which have C:/... or /c/... comparing them is going to be problematic. @@ -176,7 +238,7 @@ bats_debug_trap() { local NORMALIZED_INPUT bats_normalize_windows_dir_path NORMALIZED_INPUT "${1%/*}" local file_excluded='' path - for path in "${_BATS_DEBUG_EXCLUDE_PATHS[@]}"; do + for path in "${BATS_DEBUG_EXCLUDE_PATHS[@]}"; do if [[ "$NORMALIZED_INPUT" == "$path"* ]]; then file_excluded=1 break @@ -186,6 +248,12 @@ bats_debug_trap() { # don't update the trace within library functions or we get backtraces from inside traps # also don't record new stack traces while handling interruptions, to avoid overriding the interrupted command if [[ -z "$file_excluded" && "${BATS_INTERRUPTED-NOTSET}" == NOTSET ]]; then + BATS_DEBUG_LASTLAST_STACK_TRACE=( + ${BATS_DEBUG_LAST_STACK_TRACE[@]+"${BATS_DEBUG_LAST_STACK_TRACE[@]}"} + ) + + BATS_DEBUG_LAST_LINENO=(${BASH_LINENO[@]+"${BASH_LINENO[@]}"}) + BATS_DEBUG_LAST_SOURCE=(${BASH_SOURCE[@]+"${BASH_SOURCE[@]}"}) bats_capture_stack_trace bats_emit_trace fi @@ -195,21 +263,19 @@ bats_debug_trap() { # command failure, but the `EXIT` trap will. Also, some command failures may not # set `$?` properly. See #72 and #81 for details. # -# For this reason, we call `bats_error_trap` at the very beginning of -# `bats_teardown_trap` (the `DEBUG` trap for the call will fix the stack trace) -# and check the value of `$BATS_TEST_COMPLETED` before taking other actions. -# We also adjust the exit status value if needed. +# For this reason, we call `bats_check_status_from_trap` at the very beginning +# of `bats_teardown_trap` and check the value of `$BATS_TEST_COMPLETED` before +# taking other actions. We also adjust the exit status value if needed. # # See `bats_exit_trap` for an additional EXIT error handling case when `$?` # isn't set properly during `teardown()` errors. -bats_error_trap() { +bats_check_status_from_trap() { local status="$?" if [[ -z "$BATS_TEST_COMPLETED" ]]; then BATS_ERROR_STATUS="${BATS_ERROR_STATUS:-$status}" if [[ "$BATS_ERROR_STATUS" -eq 0 ]]; then BATS_ERROR_STATUS=1 fi - BATS_STACK_TRACE=("${BATS_CURRENT_STACK_TRACE[@]}") trap - DEBUG fi } @@ -220,15 +286,16 @@ bats_add_debug_exclude_path() { # return 1 fi if [[ "$OSTYPE" == cygwin || "$OSTYPE" == msys ]]; then + local normalized_dir bats_normalize_windows_dir_path normalized_dir "$1" - _BATS_DEBUG_EXCLUDE_PATHS+=("$normalized_dir") + BATS_DEBUG_EXCLUDE_PATHS+=("$normalized_dir") else - _BATS_DEBUG_EXCLUDE_PATHS+=("$1") + BATS_DEBUG_EXCLUDE_PATHS+=("$1") fi } bats_setup_tracing() { - _BATS_DEBUG_EXCLUDE_PATHS=() + BATS_DEBUG_EXCLUDE_PATHS=() # exclude some paths by default bats_add_debug_exclude_path "$BATS_ROOT/lib/" bats_add_debug_exclude_path "$BATS_ROOT/libexec/" @@ -247,6 +314,7 @@ bats_setup_tracing() { done < <(find "$PWD" -type d -name bats-assert -o -name bats-support) fi + local exclude_paths path # exclude user defined libraries IFS=':' read -r exclude_paths <<< "${BATS_DEBUG_EXCLUDE_PATHS:-}" for path in "${exclude_paths[@]}"; do @@ -258,4 +326,37 @@ bats_setup_tracing() { # turn on traps after setting excludedes to avoid tracing the exclude setup trap 'bats_debug_trap "$BASH_SOURCE"' DEBUG trap 'bats_error_trap' ERR -} \ No newline at end of file +} + +bats_error_trap() { + bats_check_status_from_trap + + # If necessary, undo the most recent stack trace captured by bats_debug_trap. + # See bats_debug_trap for details. + if [[ "${BASH_LINENO[*]}" = "${BATS_DEBUG_LAST_LINENO[*]:-}" + && "${BASH_SOURCE[*]}" = "${BATS_DEBUG_LAST_SOURCE[*]:-}" + && -z "$BATS_DEBUG_LAST_STACK_TRACE_IS_VALID" ]]; then + BATS_DEBUG_LAST_STACK_TRACE=( + ${BATS_DEBUG_LASTLAST_STACK_TRACE[@]+"${BATS_DEBUG_LASTLAST_STACK_TRACE[@]}"} + ) + fi + BATS_DEBUG_LAST_STACK_TRACE_IS_VALID=1 +} + +bats_interrupt_trap() { + # mark the interruption, to handle during exit + BATS_INTERRUPTED=true + BATS_ERROR_STATUS=130 + # debug trap fires before interrupt trap but gets wrong linenumber (line 1) + # -> use last last stack trace + exit $BATS_ERROR_STATUS +} + +# this is used inside run() +bats_interrupt_trap_in_run() { + # mark the interruption, to handle during exit + BATS_INTERRUPTED=true + BATS_ERROR_STATUS=130 + BATS_DEBUG_LAST_STACK_TRACE_IS_VALID=true + exit $BATS_ERROR_STATUS +} diff --git a/vendor/bats-core/libexec/bats-core/bats b/vendor/bats-core/libexec/bats-core/bats index 20cc8e6a..abacbdb6 100755 --- a/vendor/bats-core/libexec/bats-core/bats +++ b/vendor/bats-core/libexec/bats-core/bats @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -export BATS_VERSION='1.5.0' +export BATS_VERSION='1.6.0' VALID_FORMATTERS="pretty, junit, tap, tap13" version() { @@ -29,6 +29,10 @@ HELP_TEXT_HEADER containing Bats test files (ending with ".bats") -c, --count Count test cases without running any tests + --code-quote-style