diff -Nru bats-1.9.0/bin/bats bats-1.10.0/bin/bats --- bats-1.9.0/bin/bats 2023-02-12 12:32:12.000000000 +0000 +++ bats-1.10.0/bin/bats 2023-07-15 22:00:04.000000000 +0000 @@ -54,6 +54,7 @@ BATS_PATH=$(bats_readlinkf "${BASH_SOURCE[0]}") fi +export BATS_SAVED_PATH=$PATH export BATS_ROOT=${BATS_PATH%/*/*} export -f bats_readlinkf exec env BATS_ROOT="$BATS_ROOT" "$BATS_ROOT/libexec/bats-core/bats" "$@" diff -Nru bats-1.9.0/contrib/rpm/bats.spec bats-1.10.0/contrib/rpm/bats.spec --- bats-1.9.0/contrib/rpm/bats.spec 2023-02-12 12:32:12.000000000 +0000 +++ bats-1.10.0/contrib/rpm/bats.spec 2023-07-15 22:00:04.000000000 +0000 @@ -3,7 +3,7 @@ %global repo bats-core Name: bats -Version: 1.9.0 +Version: 1.10.0 Release: 1%{?dist} Summary: Bash Automated Testing System diff -Nru bats-1.9.0/debian/changelog bats-1.10.0/debian/changelog --- bats-1.9.0/debian/changelog 2023-06-27 12:40:58.000000000 +0000 +++ bats-1.10.0/debian/changelog 2023-07-22 07:36:48.000000000 +0000 @@ -1,3 +1,10 @@ +bats (1.10.0-1) unstable; urgency=medium + + * New upstream release + * d/gbp.conf: Use `upstream/latest` as upstream branch + + -- Gioele Barabucci Sat, 22 Jul 2023 09:36:48 +0200 + bats (1.9.0-2) unstable; urgency=medium * Upload to unstable diff -Nru bats-1.9.0/debian/gbp.conf bats-1.10.0/debian/gbp.conf --- bats-1.9.0/debian/gbp.conf 2023-06-27 12:30:05.000000000 +0000 +++ bats-1.10.0/debian/gbp.conf 2023-07-22 07:31:07.000000000 +0000 @@ -1,4 +1,4 @@ [DEFAULT] -upstream-branch = master +upstream-branch = upstream/latest upstream-tag = v%(version)s debian-branch = debian/latest diff -Nru bats-1.9.0/.devcontainer/Dockerfile bats-1.10.0/.devcontainer/Dockerfile --- bats-1.9.0/.devcontainer/Dockerfile 2023-02-12 12:32:12.000000000 +0000 +++ bats-1.10.0/.devcontainer/Dockerfile 2023-07-15 22:00:04.000000000 +0000 @@ -7,7 +7,9 @@ RUN echo "@edgecomm http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \ apk update && \ apk add --no-cache parallel ncurses shellcheck@edgecomm && \ - mkdir -p ~/.parallel && touch ~/.parallel/will-cite + mkdir -p ~/.parallel && touch ~/.parallel/will-cite && \ + curl -sSfL https://github.com/shenwei356/rush/releases/download/v0.5.0/rush_linux_amd64.tar.gz | tar xzf - -C /usr/local/bin && \ + chmod +x /usr/local/bin/rush RUN ln -s /opt/bats/bin/bats /usr/sbin/bats COPY . /opt/bats/ diff -Nru bats-1.9.0/docs/CHANGELOG.md bats-1.10.0/docs/CHANGELOG.md --- bats-1.9.0/docs/CHANGELOG.md 2023-02-12 12:32:12.000000000 +0000 +++ bats-1.10.0/docs/CHANGELOG.md 2023-07-15 22:00:04.000000000 +0000 @@ -8,6 +8,38 @@ [kac]: https://keepachangelog.com/en/1.0.0/ [semver]: https://semver.org/ +## [1.10.0] - 2023-07-15 + +### Added + +* add `${BATS_TEST_TAGS[@]}` for querying the tags during a test (#705) +* print tags on failing tests (#705) +* test for negative arguments to `--jobs` (#693) +* add tests for `--formatter cat` (#710) +* test coverage in CI (#718) +* Support for [rush](https://github.com/shenwei356/rush) as alternative to GNU parallel (#729) +* add `bats_pipe` helper function for `run` that executes `\|` as pipes (#663) +* publish docker images to ghcr.io (additionally to Dockerhub) (#740) + +### Documentation + +* clarify use cases of `--formatter cat` (#710) + +### Fixed + +* fix `run` with options overwriting the value of `i` (#726, #727) +* fix `${BATS_TEST_NAMES[@]}` containing only `--tags` instead of test name since Bats v1.8.0 (#705) +* fix `run --keep-empty-lines` counting trailing `\n` as (empty) new line (#711) +* fix short flag unpacker creating bogus command lines with valued flags (#732) +* fix formatter becoming confused with retries (#734) +* fix `--gather-test-outputs-in` fails on tests with `/` (#735) +* fix overriding `date` breaks `--timing` (#736) + +#### Documentation + +* typos, minor edits (#704) +* simplified contributing.md (#718) + ## [1.9.0] - 2023-02-12 ### Added diff -Nru bats-1.9.0/docs/CONTRIBUTING.md bats-1.10.0/docs/CONTRIBUTING.md --- bats-1.9.0/docs/CONTRIBUTING.md 2023-02-12 12:32:12.000000000 +0000 +++ bats-1.10.0/docs/CONTRIBUTING.md 2023-07-15 22:00:04.000000000 +0000 @@ -2,7 +2,7 @@ ## Welcome! -Thank you for considering contributing to the development of this project's +Thank you for considering contributing to this project's development and/or documentation. Just a reminder: if you're new to this project or to OSS and want to find issues to work on, please check the following labels on issues: @@ -17,16 +17,6 @@ To see all labels and their meanings, [check this wiki page][labelswiki]. -This guide borrows **heavily** from [@mbland's go-script-bash][gsb] (with some -sections directly quoted), which in turn was -drafted with tips from [Wrangling Web Contributions: How to Build -a CONTRIBUTING.md][moz] and with some inspiration from [the Atom project's -CONTRIBUTING.md file][atom]. - -[gsb]: https://github.com/mbland/go-script-bash/blob/master/CONTRIBUTING.md -[moz]: https://mozillascience.github.io/working-open-workshop/contributing/ -[atom]: https://github.com/atom/atom/blob/master/CONTRIBUTING.md - [labelswiki]: https://github.com/bats-core/bats-core/wiki/GitHub-Issue-Labels ## Table of contents @@ -35,22 +25,18 @@ * [Welcome!](#welcome) * [Table of contents](#table-of-contents) * [Quick links](#quick-links) - * [Contributor License Agreement](#contributor-license-agreement) * [Code of conduct](#code-of-conduct) - * [Asking questions and reporting issues](#asking-questions-and-reporting-issues) + * [Asking questions](#asking-questions) * [Updating documentation](#updating-documentation) - * [Environment setup](#environment-setup) - * [Workflow](#workflow) * [Testing](#testing) * [Coding conventions](#coding-conventions) - * [Formatting](#formatting) - * [Naming](#naming) * [Function declarations](#function-declarations) * [Variable and parameter declarations](#variable-and-parameter-declarations) * [Command substitution](#command-substitution) * [Process substitution](#process-substitution) * [Conditionals and loops](#conditionals-and-loops) * [Generating output](#generating-output) + * [Signal names](#signal-names) * [Gotchas](#gotchas) * [Open Source License](#open-source-license) * [Credits](#credits) @@ -71,83 +57,18 @@ [CODE_OF_CONDUCT]: https://github.com/bats-core/bats-core/blob/master/docs/CODE_OF_CONDUCT.md [LICENSE]: https://github.com/bats-core/bats-core/blob/master/LICENSE.md -## Contributor License Agreement - -Per the [GitHub Terms of Service][gh-tos], be aware that by making a -contribution to this project, you agree: - -* to license your contribution under the same terms as [this project's - license][osmit], and -* that you have the right to license your contribution under those terms. - -See also: ["Does my project need an additional contributor agreement? Probably - not."][cla-needed] - -[gh-tos]: https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license -[osmit]: #open-source-license -[cla-needed]: https://opensource.guide/legal/#does-my-project-need-an-additional-contributor-agreement - - ## Code of conduct Harassment or rudeness of any kind will not be tolerated, period. For specifics, see the [CODE_OF_CONDUCT][] file. -## Asking questions and reporting issues - -### Asking questions +## Asking questions -Please check the [README][] or existing [issues][repoissues] first. +Please check the [documentation][documentation] or existing [discussions][] and [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) -### Reporting issues - -Before reporting an issue, please use the search feature on the [issues -page][repoissues] to see if an issue matching the one you've observed has already -been filed. - -### Updating or filing a new issue - -#### Information to include - -Try to be as specific as possible about your environment and the problem you're -observing. At a minimum, include: - -#### Installation issues - -1. State the version of Bash you're using `bash --version` -1. State your operating system and its version -1. If you're installing through homebrew, run `brew doctor`, and attach the -output of `brew info bats-core` - -#### Bugs/usage issues - -1. State the version of Bash you're using `bash --version` -1. State your operating system and its version -1. Command line steps or code snippets that reproduce the issue -1. Any apparently relevant information from the [Bash changelog][bash-changes] - -[bash-changes]: https://tiswww.case.edu/php/chet/bash/CHANGES - -Also consider using: - -- Bash's `time` builtin to collect running times -- a regression test to add to the suite -- memory usage as reported by a tool such as - [memusg](https://gist.github.com/netj/526585) - -### On existing issues - -1. DO NOT add a +1 comment: Use the reactions provided instead -1. DO add information if you're facing a similar issue to someone else, but -within a different context (e.g. different steps needed to reproduce the issue -than previous stated, different version of Bash or BATS, different OS, etc.) -You can read on how to do that here: [Information to include](#information-to-include) -1. DO remember that you can use the *Subscribe* button on the right side of the -page to receive notifications of further conversations or a resolution. - ## Updating documentation We love documentation and people who love documentation! @@ -158,95 +79,31 @@ Also: _no typo is too small to fix!_ Really. Of course, batches of fixes are preferred, but even one nit is one nit too many. -## Environment setup - -Make sure you have Bash installed per the [Environment setup in the -README][env-setup]. - -[env-setup]: https://github.com/bats-core/bats-core/blob/master/README.md#environment-setup +## Testing -## Workflow +- Continuous integration status: [![Tests](https://github.com/bats-core/bats-core/workflows/Tests/badge.svg)](https://github.com/bats-core/bats-core/actions?query=workflow%3ATests) -The basic workflow for submitting changes resembles that of the [GitHub Git -Flow][github-flow] (a.k.a. GitHub Flow), except that you will be working with -your own fork of the repository and issuing pull requests to the original. - -[github-flow]: https://guides.github.com/introduction/flow/ - -1. Fork the repo on GitHub (look for the "Fork" button) -1. Clone your forked repo to your local machine -1. Create your feature branch (`git checkout -b my-new-feature`) -1. Develop _and [test](#testing)_ your changes as necessary. -1. Commit your changes (`git commit -am 'Add some feature'`) -1. Push to the branch (`git push origin my-new-feature`) -1. Create a new [GitHub pull request][gh-pr] for your feature branch based - against the original repository's `master` branch -1. If your request is accepted, you can [delete your feature branch][rm-branch] - and pull the updated `master` branch from the original repository into your - fork. You may even [delete your fork][rm-fork] if you don't anticipate making - further changes. - -[gh-pr]: https://help.github.com/articles/using-pull-requests/ -[rm-branch]: https://help.github.com/articles/deleting-unused-branches/ -[rm-fork]: https://help.github.com/articles/deleting-a-repository/ +To run all tests: +```sh +bin/bats test +``` -## Testing +To run a single test file: +```sh +bin/bats test/file.bats +``` -- Continuous integration status: [![Tests](https://github.com/bats-core/bats-core/workflows/Tests/badge.svg)](https://github.com/bats-core/bats-core/actions?query=workflow%3ATests) +When running from a teminal, Bats uses the *pretty* formatter by default. +However, to debug Bats you might need to see the raw test output. +The **cat** formatter is intended as an internal debugging tool because +it does not process test outputs. +To use it, run Bats with the `--formatter cat` option. ## Coding conventions -- [Formatting](#formatting) -- [Naming](#naming) -- [Variable and parameter declarations](#variable-and-parameter-declarations) -- [Command substitution](#command-substitution) -- [Conditions and loops](#conditionals-and-loops) -- [Gotchas](#gotchas) - -### Formatting - -- Keep all files 80 characters wide. -- Indent using two spaces. -- Enclose all variables in double quotes when used to avoid having them - interpreted as glob patterns (unless the variable contains a glob pattern) - and to avoid word splitting when the value contains spaces. Both scenarios - can introduce errors that often prove difficult to diagnose. - - **This is especially important when the variable is used to generate a - glob pattern**, since spaces may appear in a path value. - - If the variable itself contains a glob pattern, make sure to set - `IFS=$'\n'` before using it so that the pattern itself and any matching - file names containing spaces are not split apart. - - Exceptions: Quotes are not required within math contexts, i.e. `(( ))` or - `$(( ))`, and must not be used for variables on the right side of the `=~` - operator. -- Enclose all string literals in single quotes. - - Exception: If the string contains an apostrophe, use double quotes. -- Use quotes around variables and literals even inside of `[[ ]]` conditions. - - This is because strings that contain '[' or ']' characters may fail to - compare equally when they should. - - Exception: Do not quote variables that contain regular expression patterns - appearing on the right side of the `=~` operator. -- _Only_ quote arguments to the right of `=~` if the expression is a literal - match without any metacharacters. - -The following are intended to prevent too-compact code: - -- Declare only one item per `declare`, `local`, `export`, or `readonly` call. - - _Note:_ This also helps avoid subtle bugs, as trying to initialize one - variable using the value of another declared in the same statement will - not do what you may expect. The initialization of the first variable will - not yet be complete when the second variable is declared, so the first - variable will have an empty value. -- Do not use one-line `if`, `for`, `while`, `until`, `case`, or `select` - statements. -- Do not use `&&` or `||` to avoid writing `if` statements. -- Do not write functions entirely on one line. -- For `case` statements: put each pattern on a line by itself; put each command - on a line by itself; put the `;;` terminator on a line by itself. +Use (`shfmt`)[https://github.com/mvdan/sh#shfmt] and [ShellCheck](https://www.shellcheck.net/). The CI will enforce this. -### Naming - -- Use `snake_case` for all identifiers. +Use `snake_case` for all identifiers. ### Function declarations @@ -258,9 +115,6 @@ ### Variable and parameter declarations -- _Gotcha:_ Never initialize an array on the same line as an `export` or - `declare -g` statement. See [the Gotchas section](#gotchas) below for more - details. - Declare all variables inside functions using `local`. - Declare temporary file-level variables using `declare`. Use `unset` to remove them when finished. @@ -349,38 +203,24 @@ success ``` -### Gotchas - -- If you wish to use command substitution to initialize a `local` variable, and - then check the exit status of the command substitution, you _must_ declare the - variable on one line and perform the substitution on another. If you don't, - the exit status will always indicate success, as it is the status of the - `local` declaration, not the command substitution. -- To work around a bug in some versions of Bash whereby arrays declared with - `declare -g` or `export` and initialized in the same statement eventually go - out of scope, always `export` the array name on one line and initialize it the - next line. See: - - https://lists.gnu.org/archive/html/bug-bash/2012-06/msg00068.html - - ftp://ftp.gnu.org/gnu/bash/bash-4.2-patches/bash42-025 - - http://lists.gnu.org/archive/html/help-bash/2012-03/msg00078.html -- [ShellCheck](https://www.shellcheck.net/) can help to identify many of these issues - - -## Open Source License - -This software is made available under the [MIT License][osmit]. -For the text of the license, see the [LICENSE][] file. ## Credits -- This guide was heavily written by BATS-core member [@mbland](https://github.com/mbland) -for [go-script-bash](https://github.com/mbland/go-script-bash), tweaked for [BATS-core][repohome] -- Table of Contents created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) -- The [official bash logo](https://github.com/odb/official-bash-logo) is copyrighted +The [official bash logo](https://github.com/odb/official-bash-logo) is copyrighted by the [Free Software Foundation](https://www.fsf.org/), 2016 under the [Free Art License](http://artlibre.org/licence/lal/en/) +This guide borrows **heavily** from [@mbland's go-script-bash][gsb] (with some +sections directly quoted), which in turn was +drafted with tips from [Wrangling Web Contributions: How to Build +a CONTRIBUTING.md][moz] and with some inspiration from [the Atom project's +CONTRIBUTING.md file][atom]. +[gsb]: https://github.com/mbland/go-script-bash/blob/master/CONTRIBUTING.md +[moz]: https://mozillascience.github.io/working-open-workshop/contributing/ +[atom]: https://github.com/atom/atom/blob/master/CONTRIBUTING.md +[discussions]: https://github.com/bats-core/bats-core/discussions +[documentation]: https://bats-core.readthedocs.io/ [repoprojects]: https://github.com/bats-core/bats-core/projects [repomilestones]: https://github.com/bats-core/bats-core/milestones [repoprs]: https://github.com/bats-core/bats-core/pulls diff -Nru bats-1.9.0/docs/source/writing-tests.md bats-1.10.0/docs/source/writing-tests.md --- bats-1.9.0/docs/source/writing-tests.md 2023-02-12 12:32:12.000000000 +0000 +++ bats-1.10.0/docs/source/writing-tests.md 2023-07-15 22:00:04.000000000 +0000 @@ -22,7 +22,7 @@ ```bash # bats test_tags=tag:1, tag:2, tag:3 -@test "second test" { +@test "first test" { # ... } @@ -582,6 +582,7 @@ is `setup_file()`. - `$BATS_TEST_NUMBER` is the (1-based) index of the current test case in the test file. - `$BATS_SUITE_TEST_NUMBER` is the (1-based) index of the current test case in the test suite (over all files). +- `$BATS_TEST_TAGS` the tags of the current test. - `$BATS_TMPDIR` is the base temporary directory used by bats to create its temporary files / directories. (default: `$TMPDIR`. If `$TMPDIR` is not set, `/tmp` is used.) diff -Nru bats-1.9.0/.github/ISSUE_TEMPLATE/bug_report.md bats-1.10.0/.github/ISSUE_TEMPLATE/bug_report.md --- bats-1.9.0/.github/ISSUE_TEMPLATE/bug_report.md 2023-02-12 12:32:12.000000000 +0000 +++ bats-1.10.0/.github/ISSUE_TEMPLATE/bug_report.md 2023-07-15 22:00:04.000000000 +0000 @@ -12,18 +12,19 @@ **To Reproduce** Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error + +1. Create example `file.bats` with following contents +2. run `bats --foo file.bats` +3. ... **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] + - Bats version [e.g. 1.4.0 or commit hash if applicable] + - operating system (including version): [e.g. Linux (please name your distribution!), FreeBSD, MacOS] + - `bash --version`: [e.g. 5.1] + - Install method: [e.g. git submodule, distribution package manager, npm, homebrew, ...] **Additional context** Add any other context about the problem here. diff -Nru bats-1.9.0/.github/workflows/release_dockerhub.yml bats-1.10.0/.github/workflows/release_dockerhub.yml --- bats-1.9.0/.github/workflows/release_dockerhub.yml 2023-02-12 12:32:12.000000000 +0000 +++ bats-1.10.0/.github/workflows/release_dockerhub.yml 2023-07-15 22:00:04.000000000 +0000 @@ -29,6 +29,13 @@ username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Log in to the GitHub Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v1 diff -Nru bats-1.9.0/.github/workflows/scorecard.yml bats-1.10.0/.github/workflows/scorecard.yml --- bats-1.9.0/.github/workflows/scorecard.yml 1970-01-01 00:00:00.000000000 +0000 +++ bats-1.10.0/.github/workflows/scorecard.yml 2023-07-15 22:00:04.000000000 +0000 @@ -0,0 +1,72 @@ +# This workflow uses actions that are not certified by GitHub. They are provided +# by a third-party and are governed by separate terms of service, privacy +# policy, and support documentation. + +name: Scorecard supply-chain security +on: + # For Branch-Protection check. Only the default branch is supported. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection + branch_protection_rule: + # To guarantee Maintained check is occasionally updated. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained + schedule: + - cron: '44 10 * * 6' + push: + branches: [ "master" ] + +# Declare default permissions as read only. +permissions: read-all + +jobs: + analysis: + name: Scorecard analysis + runs-on: ubuntu-latest + permissions: + # Needed to upload the results to code-scanning dashboard. + security-events: write + # Needed to publish results and get a badge (see publish_results below). + id-token: write + # Uncomment the permissions below if installing in a private repository. + # contents: read + # actions: read + + steps: + - name: "Checkout code" + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 + with: + persist-credentials: false + + - name: "Run analysis" + uses: ossf/scorecard-action@e38b1902ae4f44df626f11ba0734b14fb91f8f86 # v2.1.2 + with: + results_file: results.sarif + results_format: sarif + # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: + # - you want to enable the Branch-Protection check on a *public* repository, or + # - you are installing Scorecard on a *private* repository + # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat. + # repo_token: ${{ secrets.SCORECARD_TOKEN }} + + # Public repositories: + # - Publish results to OpenSSF REST API for easy access by consumers + # - Allows the repository to include the Scorecard badge. + # - See https://github.com/ossf/scorecard-action#publishing-results. + # For private repositories: + # - `publish_results` will always be set to `false`, regardless + # of the value entered here. + publish_results: true + + # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF + # format to the repository Actions tab. + - name: "Upload artifact" + uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0 + with: + name: SARIF file + path: results.sarif + retention-days: 5 + + # Upload the results to GitHub's code scanning dashboard. + - name: "Upload to code-scanning" + uses: github/codeql-action/upload-sarif@17573ee1cc1b9d061760f3a006fc4aac4f944fd5 # v2.2.4 + with: + sarif_file: results.sarif diff -Nru bats-1.9.0/.github/workflows/tests.yml bats-1.10.0/.github/workflows/tests.yml --- bats-1.9.0/.github/workflows/tests.yml 2023-02-12 12:32:12.000000000 +0000 +++ bats-1.10.0/.github/workflows/tests.yml 2023-07-15 22:00:04.000000000 +0000 @@ -1,13 +1,13 @@ name: Tests -# Controls when the action will run. +# Controls when the action will run. on: [push, pull_request, workflow_dispatch] jobs: changelog: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Check that PR is mentioned in Changelog run: | if ! ./.github/workflows/check_pr_label.sh "${{github.event.pull_request.number}}" "no changelog"; then @@ -18,7 +18,7 @@ shfmt: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - run: | curl https://github.com/mvdan/sh/releases/download/v3.5.1/shfmt_v3.5.1_linux_amd64 -o shfmt chmod a+x shfmt @@ -27,7 +27,7 @@ shellcheck: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Run shellcheck run: | sudo apt-get update -y @@ -42,9 +42,14 @@ - '' # 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' + - 'BATS_PARALLEL_BINARY_NAME=rush' runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - name: Install rush + run: | + curl -sSfL https://github.com/shenwei356/rush/releases/download/v0.5.0/rush_linux_amd64.tar.gz | sudo tar xzf - -C /usr/local/bin + if: contains(matrix.env_vars, 'rush') - name: Run test on OS ${{ matrix.os }} shell: 'script -q -e -c "bash {0}"' # work around tty issues env: @@ -56,7 +61,7 @@ unset_variables: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Check unset variables shell: 'script -q -e -c "bash {0}"' # work around tty issues env: @@ -70,8 +75,8 @@ os: ['ubuntu-20.04', 'ubuntu-22.04'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 - name: Run test on OS ${{ matrix.os }} shell: 'script -q -e -c "bash {0}"' # work around tty issues env: @@ -84,7 +89,7 @@ windows: runs-on: windows-2019 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - run: | bash --version bash -c "time bin/bats --print-output-on-failure --formatter tap test" @@ -95,11 +100,11 @@ os: ['windows-2019'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 - run: npm pack ./ - run: npm install -g (get-item .\bats-*.tgz).FullName - - run: bats -T --print-output-on-failure test + - run: bats -T --print-output-on-failure test macos: strategy: @@ -109,11 +114,16 @@ - '' # 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' + - 'BATS_PARALLEL_BINARY_NAME=rush' runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install unbuffer via expect run: brew install expect + - name: Install rush + run: | + curl -sSfL https://github.com/shenwei356/rush/releases/download/v0.5.0/rush_darwin_amd64.tar.gz | sudo tar xzf - -C /usr/local/bin + if: contains(matrix.env_vars, 'rush') - name: Run test on OS ${{ matrix.os }} shell: 'unbuffer bash {0}' # work around tty issues env: @@ -128,8 +138,8 @@ os: ['macos-11', 'macos-12'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 - name: Install unbuffer via expect run: brew install expect - name: Run test on OS ${{ matrix.os }} @@ -140,7 +150,7 @@ npm pack ./ # somehow there is already an installed bats version around npm install --force -g ./bats-*.tgz - bats --print-output-on-failure test + bats --print-output-on-failure test bash-version: strategy: @@ -152,7 +162,7 @@ - '-e BATS_NUMBER_OF_PARALLEL_JOBS=2' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Run test on bash version ${{ matrix.version }} shell: 'script -q -e -c "bash {0}"' # work around tty issues run: | @@ -160,12 +170,12 @@ 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 container: alpine:latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install dependencies run: apk add bash ncurses util-linux - name: Run test on bash version ${{ matrix.version }} @@ -183,7 +193,7 @@ - flock - "" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: vmactions/freebsd-vm@v0 with: prepare: pkg install -y bash parallel ${{ matrix.packages }} @@ -193,15 +203,15 @@ find_broken_symlinks: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 # list symlinks that are broken and force non-zero exit if there are any - run: "! find . -xtype l | grep ." - + rpm: runs-on: ubuntu-latest container: almalinux:8 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - run: dnf install -y rpm-build rpmdevtools - name: Build and install RPM and dependencies run: | @@ -221,13 +231,13 @@ dockerfile: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Docker Buildx id: buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 - - uses: docker/build-push-action@v2 + - uses: docker/build-push-action@v4 with: platforms: linux/amd64 tags: bats:test @@ -238,17 +248,17 @@ env: TERM: linux # fix tput for tty issue work around - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: repository: bats-core/bats-assert path: bats-assert - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: repository: bats-core/bats-support path: bats-support - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: repository: bats-core/bats-file path: bats-file @@ -262,4 +272,44 @@ docker run -itv "$PWD":/code --entrypoint bash bats:test test.sh shell: 'script -q -e -c "bash {0}"' # work around tty issues env: - TERM: linux # fix tput for tty issue work around \ No newline at end of file + TERM: linux # fix tput for tty issue work around + + coverage: + runs-on: ubuntu-20.04 + permissions: + pull-requests: write + issues: write + steps: + - uses: actions/checkout@v3 + - run: | + wget https://github.com/SimonKagstrom/kcov/releases/download/v40/kcov-amd64.tar.gz + tar -xf kcov-amd64.tar.gz + - run: | + ./usr/local/bin/kcov --exclude-path=/tmp $PWD/coverage ./bin/bats --filter-tags '!no-kcov' test/ + shell: 'script -q -e -c "bash {0}"' # work around tty issues + env: + TERM: linux # fix tput for tty issue work around + + - name: Archive code coverage results + uses: actions/upload-artifact@v3 + with: + name: code-coverage-report + path: coverage/* + + - name: Print the Total Coverage + id: coverage-percent + shell: bash + env: + minimum_coverage: 86.39 + run: | + value=$(jq '.percent_covered' + int=${value%.*} + decimals=${value#*.} + echo $int${decimals::2} + } + echo "Coverage: $value%" | tee "$GITHUB_STEP_SUMMARY" + if (( $(fixed_point $value) < $(fixed_point $expected) )); then + echo " is below required minimum coverage ($minimum_coverage%)." | tee -a "$GITHUB_STEP_SUMMARY" + exit 1 + fi diff -Nru bats-1.9.0/lib/bats-core/common.bash bats-1.10.0/lib/bats-core/common.bash --- bats-1.9.0/lib/bats-core/common.bash 2023-02-12 12:32:12.000000000 +0000 +++ bats-1.10.0/lib/bats-core/common.bash 2023-07-15 22:00:04.000000000 +0000 @@ -39,6 +39,7 @@ IFS=. read -ra version1_parts <<<"$1" IFS=. read -ra version2_parts <<<"$2" + local -i i for i in {0..2}; do if ((version1_parts[i] < version2_parts[i])); then return 0 @@ -139,6 +140,7 @@ local -i haystack_index=0 # initialize only here to continue from last search position local search_value haystack_value # just to appease shellcheck + local -i i for ((i = 1; i <= $#; ++i)); do eval "local search_value=${!i}" for (( ; haystack_index < haystack_length; ++haystack_index)); do @@ -168,6 +170,7 @@ local -i haystack_index=0 # initialize only here to continue from last search position local search_value haystack_value # just to appease shellcheck + local -i i for ((i = 1; i <= $#; ++i)); do eval "local search_value=${!i}" for (( ; haystack_index < haystack_length; ++haystack_index)); do @@ -247,3 +250,9 @@ bats_approx_realpath filename "$filename" printf -v "$output" "file://%s:%d" "$filename" "$line" } + +# execute command with backed up path +# to prevent path mocks from interfering with our internals +bats_execute() { # + PATH="${BATS_SAVED_PATH?}" "$@" +} diff -Nru bats-1.9.0/lib/bats-core/formatter.bash bats-1.10.0/lib/bats-core/formatter.bash --- bats-1.9.0/lib/bats-core/formatter.bash 2023-02-12 12:32:12.000000000 +0000 +++ bats-1.10.0/lib/bats-core/formatter.bash 2023-07-15 22:00:04.000000000 +0000 @@ -41,17 +41,25 @@ not_ok_line_regexpr="not ok ([0-9]+) (.*)" timing_expr="in ([0-9]+)ms$" - local test_name begin_index ok_index not_ok_index index scope + local test_name begin_index last_begin_index try_index ok_index not_ok_index index scope begin_index=0 + last_begin_index=-1 + try_index=0 index=0 scope=plan while IFS= read -r line; do unset BATS_FORMATTER_TEST_DURATION BATS_FORMATTER_TEST_TIMEOUT case "$line" in 'begin '*) # this might only be called in extended tap output - ((++begin_index)) scope=begin - test_name="${line#* "$begin_index" }" + begin_index=${line#begin } + begin_index=${begin_index%% *} + if [[ $begin_index == "$last_begin_index" ]]; then + (( ++try_index )) + else + try_index=0 + fi + test_name="${line#begin "$begin_index" }" bats_tap_stream_begin "$begin_index" "$test_name" ;; 'ok '*) diff -Nru bats-1.9.0/lib/bats-core/test_functions.bash bats-1.10.0/lib/bats-core/test_functions.bash --- bats-1.9.0/lib/bats-core/test_functions.bash 2023-02-12 12:32:12.000000000 +0000 +++ bats-1.10.0/lib/bats-core/test_functions.bash 2023-07-15 22:00:04.000000000 +0000 @@ -163,14 +163,17 @@ # write separate lines from into bats_separate_lines() { # - local output_array_name="$1" - local input_var_name="$2" + local -r output_array_name="$1" + local -r input_var_name="$2" + local input="${!input_var_name}" if [[ $keep_empty_lines ]]; then local bats_separate_lines_lines=() - if [[ -n "${!input_var_name}" ]]; then # avoid getting an empty line for empty input + if [[ -n "$input" ]]; then # avoid getting an empty line for empty input + # remove one trailing \n if it exists to compensate its addition by <<< + input=${input%$'\n'} while IFS= read -r line; do bats_separate_lines_lines+=("$line") - done <<<"${!input_var_name}" + done <<<"${input}" fi eval "${output_array_name}=(\"\${bats_separate_lines_lines[@]}\")" else @@ -179,6 +182,127 @@ fi } +bats_pipe() { # [-N] [--] command0 [ \| command1 [ \| command2 [...]]] + # This will run each command given, piping them appropriately. + # Meant to be used in combination with `run` helper to allow piped commands + # to be used. + # Note that `\|` must be used, not `|`. + # By default, the exit code of this command will be the last failure in the + # chain of piped commands (similar to `set -o pipefail`). + # Supplying -N (e.g. -0) will instead always use the exit code of the command + # at that position in the chain. + # --returned-status=N could be used as an alternative to -N. This also allows + # for negative values (which count from the end in reverse order). + + local pipestatus_position= + + # parse options starting with - + while [[ $# -gt 0 ]] && [[ $1 == -* ]]; do + case "$1" in + -[0-9]*) + pipestatus_position="${1#-}" + ;; + --returned-status*) + if [ "$1" = "--returned-status" ]; then + pipestatus_position="$2" + shift + elif [[ "$1" =~ ^--returned-status= ]]; then + pipestatus_position="${1#--returned-status=}" + else + printf "Usage error: unknown flag '%s'" "$1" >&2 + return 1 + fi + ;; + --) + shift # eat the -- before breaking away + break + ;; + *) + printf "Usage error: unknown flag '%s'" "$1" >&2 + return 1 + ;; + esac + shift + done + + # parse and validate arguments, escape as necessary + local -a commands_and_args=("$@") + local -a escaped_args=() + local -i pipe_count=0 + local -i previous_pipe_index=-1 + local -i index=0 + for (( index = 0; index < $#; index++ )); do + local current_command_or_arg="${commands_and_args[$index]}" + local escaped_arg="$current_command_or_arg" + if [[ "$current_command_or_arg" != '|' ]]; then + # escape args to protect them when eval'd (e.g. if they contain whitespace). + printf -v escaped_arg "%q" "$current_command_or_arg" + elif [ "$current_command_or_arg" = "|" ]; then + if [ "$index" -eq 0 ]; then + printf "Usage error: Cannot have leading \`\\|\`.\n" >&2 + return 1 + fi + if (( (previous_pipe_index + 1) >= index )); then + printf "Usage error: Cannot have consecutive \`\\|\`. Found at argument position '%s'.\n" "$index" >&2 + return 1 + fi + (( ++pipe_count )) + previous_pipe_index="$index" + fi + escaped_args+=("$escaped_arg") + done + + if (( (previous_pipe_index > 0) && (previous_pipe_index == ($# - 1)) )); then + printf "Usage error: Cannot have trailing \`\\|\`.\n" >&2 + return 1 + fi + + if (( pipe_count == 0 )); then + # Don't allow for no pipes. This might be a typo in the test, + # e.g. `run bats_pipe command0 | command1` + # instead of `run bats_pipe command0 \| command1` + # Unfortunately, we can't catch `run bats_pipe command0 \| command1 | command2`. + # But this check is better than just allowing no pipes. + printf "Usage error: No \`\\|\`s found. Is this an error?\n" >&2 + return 1 + fi + + # there will be pipe_count + 1 entries in PIPE_STATUS (pipe_count number of \|'s between each entry). + # valid indices are [-(pipe_count + 1), pipe_count] + if [ -n "$pipestatus_position" ] && (( (pipestatus_position > pipe_count) || (-pipestatus_position > (pipe_count + 1)) )); then + printf "Usage error: Too large of -N argument (or --returned-status) given. Argument value: '%s'.\n" "$pipestatus_position" >&2 + return 1 + fi + + # run commands and return appropriate pipe status + local -a __bats_pipe_eval_pipe_status=() + eval "${escaped_args[@]}" '; __bats_pipe_eval_pipe_status=(${PIPESTATUS[@]})' + + local result_status= + if [ -z "$pipestatus_position" ]; then + # if we are performing default "last failure" behavior, + # iterate backwards through pipe_status to find the last error. + result_status=0 + for index in "${!__bats_pipe_eval_pipe_status[@]}"; do + # OSX bash doesn't support negative indexing. + local backward_iter_index="$((${#__bats_pipe_eval_pipe_status[@]} - index - 1))" + local status_at_backward_iter_index="${__bats_pipe_eval_pipe_status[$backward_iter_index]}" + if (( status_at_backward_iter_index != 0 )); then + result_status="$status_at_backward_iter_index" + break; + fi + done + elif (( pipestatus_position >= 0 )); then + result_status="${__bats_pipe_eval_pipe_status[$pipestatus_position]}" + else + # Must use positive values for some bash's (like OSX). + local backward_iter_index="$((${#__bats_pipe_eval_pipe_status[@]} + pipestatus_position))" + result_status="${__bats_pipe_eval_pipe_status[$backward_iter_index]}" + fi + + return "$result_status" +} + 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, @@ -347,8 +471,17 @@ } bats_test_function() { + local tags=() + if [[ "$1" == --tags ]]; then + IFS=',' read -ra tags <<<"$2" + shift 2 + fi local test_name="$1" BATS_TEST_NAMES+=("$test_name") + if [[ "$test_name" == "$BATS_TEST_NAME" ]]; then + # shellcheck disable=SC2034 + BATS_TEST_TAGS=("${tags[@]+${tags[@]}}") + fi } # decides whether a failed test should be run again diff -Nru bats-1.9.0/libexec/bats-core/bats bats-1.10.0/libexec/bats-core/bats --- bats-1.9.0/libexec/bats-core/bats 2023-02-12 12:32:12.000000000 +0000 +++ bats-1.10.0/libexec/bats-core/bats 2023-07-15 22:00:04.000000000 +0000 @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -export BATS_VERSION='1.9.0' +export BATS_VERSION='1.10.0' VALID_FORMATTERS="pretty, junit, tap, tap13" version() { @@ -38,7 +38,7 @@ -c, --count Count test cases without running any tests --code-quote-style