From 173bfcf4eb80aecd4030ceb9fdf3c1a349998f9a Mon Sep 17 00:00:00 2001 From: donpetry-bot <281750570+donpetry-bot@users.noreply.github.com> Date: Thu, 23 Jul 2026 18:37:43 +0000 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20implement=20issue=20#892=20?= =?UTF-8?q?=E2=80=94=20dev-lead=20fix-review=20won't=20act=20on=20advisory?= =?UTF-8?q?-bot=20nitpick=20threads=20(green=20CI=20+=20CHANGES=5FREQUESTE?= =?UTF-8?q?D,=20empty=20machine=20findings=20=E2=86=92=20status=3Dno-chang?= =?UTF-8?q?es=20=E2=86=92=20PR=20stalls=20on=20human)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node_modules/.package-lock.json | 19 + node_modules/bats-assert/LICENSE | 116 ++ node_modules/bats-assert/README.md | 1038 +++++++++++++++++ node_modules/bats-assert/load.bash | 33 + node_modules/bats-assert/package.json | 49 + node_modules/bats-assert/src/assert.bash | 42 + .../bats-assert/src/assert_equal.bash | 42 + .../bats-assert/src/assert_failure.bash | 86 ++ node_modules/bats-assert/src/assert_line.bash | 298 +++++ .../bats-assert/src/assert_not_equal.bash | 42 + .../bats-assert/src/assert_output.bash | 247 ++++ .../bats-assert/src/assert_regex.bash | 54 + .../bats-assert/src/assert_success.bash | 47 + node_modules/bats-assert/src/refute.bash | 42 + node_modules/bats-assert/src/refute_line.bash | 341 ++++++ .../bats-assert/src/refute_output.bash | 243 ++++ .../bats-assert/src/refute_regex.bash | 64 + node_modules/bats-support/CHANGELOG.md | 46 + node_modules/bats-support/LICENSE | 116 ++ node_modules/bats-support/README.md | 189 +++ node_modules/bats-support/load.bash | 3 + node_modules/bats-support/package.json | 30 + node_modules/bats-support/src/error.bash | 41 + node_modules/bats-support/src/lang.bash | 73 ++ node_modules/bats-support/src/output.bash | 279 +++++ 25 files changed, 3580 insertions(+) create mode 100644 node_modules/bats-assert/LICENSE create mode 100644 node_modules/bats-assert/README.md create mode 100644 node_modules/bats-assert/load.bash create mode 100644 node_modules/bats-assert/package.json create mode 100644 node_modules/bats-assert/src/assert.bash create mode 100644 node_modules/bats-assert/src/assert_equal.bash create mode 100644 node_modules/bats-assert/src/assert_failure.bash create mode 100644 node_modules/bats-assert/src/assert_line.bash create mode 100644 node_modules/bats-assert/src/assert_not_equal.bash create mode 100644 node_modules/bats-assert/src/assert_output.bash create mode 100644 node_modules/bats-assert/src/assert_regex.bash create mode 100644 node_modules/bats-assert/src/assert_success.bash create mode 100644 node_modules/bats-assert/src/refute.bash create mode 100644 node_modules/bats-assert/src/refute_line.bash create mode 100644 node_modules/bats-assert/src/refute_output.bash create mode 100644 node_modules/bats-assert/src/refute_regex.bash create mode 100644 node_modules/bats-support/CHANGELOG.md create mode 100644 node_modules/bats-support/LICENSE create mode 100644 node_modules/bats-support/README.md create mode 100644 node_modules/bats-support/load.bash create mode 100644 node_modules/bats-support/package.json create mode 100644 node_modules/bats-support/src/error.bash create mode 100644 node_modules/bats-support/src/lang.bash create mode 100644 node_modules/bats-support/src/output.bash diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 5339ba19e..b57d6f220 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -11,6 +11,25 @@ "bin": { "bats": "bin/bats" } + }, + "node_modules/bats-assert": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/bats-assert/-/bats-assert-2.2.4.tgz", + "integrity": "sha512-EcaY4Z+Tbz1c7pnC1SrVSq0epr7tLwFpz6qt7KUW9K8uSw8V12DTfH9d2HxZWvBEATaCuMsZ7KoZMFiSQPRoXw==", + "license": "CC0-1.0", + "peerDependencies": { + "bats": "0.4 || ^1", + "bats-support": "^0.3" + } + }, + "node_modules/bats-support": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/bats-support/-/bats-support-0.3.0.tgz", + "integrity": "sha512-z+2WzXbI4OZgLnynydqH8GpI3+DcOtepO66PlK47SfEzTkiuV9hxn9eIQX+uLVFbt2Oqoc7Ky3TJ/N83lqD+cg==", + "license": "CC0-1.0", + "peerDependencies": { + "bats": "0.4 || ^1" + } } } } diff --git a/node_modules/bats-assert/LICENSE b/node_modules/bats-assert/LICENSE new file mode 100644 index 000000000..670154e35 --- /dev/null +++ b/node_modules/bats-assert/LICENSE @@ -0,0 +1,116 @@ +CC0 1.0 Universal + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator and +subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for the +purpose of contributing to a commons of creative, cultural and scientific +works ("Commons") that the public can reliably and without fear of later +claims of infringement build upon, modify, incorporate in other works, reuse +and redistribute as freely as possible in any form whatsoever and for any +purposes, including without limitation commercial purposes. These owners may +contribute to the Commons to promote the ideal of a free culture and the +further production of creative, cultural and scientific works, or to gain +reputation or greater distribution for their Work in part through the use and +efforts of others. + +For these and/or other purposes and motivations, and without any expectation +of additional consideration or compensation, the person associating CC0 with a +Work (the "Affirmer"), to the extent that he or she is an owner of Copyright +and Related Rights in the Work, voluntarily elects to apply CC0 to the Work +and publicly distribute the Work under its terms, with knowledge of his or her +Copyright and Related Rights in the Work and the meaning and intended legal +effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not limited +to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, communicate, + and translate a Work; + + ii. moral rights retained by the original author(s) and/or performer(s); + + iii. publicity and privacy rights pertaining to a person's image or likeness + depicted in a Work; + + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + + v. rights protecting the extraction, dissemination, use and reuse of data in + a Work; + + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation thereof, + including any amended or successor version of such directive); and + + vii. other similar, equivalent or corresponding rights throughout the world + based on applicable law or treaty, and any national implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention of, +applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and +unconditionally waives, abandons, and surrenders all of Affirmer's Copyright +and Related Rights and associated claims and causes of action, whether now +known or unknown (including existing as well as future claims and causes of +action), in the Work (i) in all territories worldwide, (ii) for the maximum +duration provided by applicable law or treaty (including future time +extensions), (iii) in any current or future medium and for any number of +copies, and (iv) for any purpose whatsoever, including without limitation +commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes +the Waiver for the benefit of each member of the public at large and to the +detriment of Affirmer's heirs and successors, fully intending that such Waiver +shall not be subject to revocation, rescission, cancellation, termination, or +any other legal or equitable action to disrupt the quiet enjoyment of the Work +by the public as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason be +judged legally invalid or ineffective under applicable law, then the Waiver +shall be preserved to the maximum extent permitted taking into account +Affirmer's express Statement of Purpose. In addition, to the extent the Waiver +is so judged Affirmer hereby grants to each affected person a royalty-free, +non transferable, non sublicensable, non exclusive, irrevocable and +unconditional license to exercise Affirmer's Copyright and Related Rights in +the Work (i) in all territories worldwide, (ii) for the maximum duration +provided by applicable law or treaty (including future time extensions), (iii) +in any current or future medium and for any number of copies, and (iv) for any +purpose whatsoever, including without limitation commercial, advertising or +promotional purposes (the "License"). The License shall be deemed effective as +of the date CC0 was applied by Affirmer to the Work. Should any part of the +License for any reason be judged legally invalid or ineffective under +applicable law, such partial invalidity or ineffectiveness shall not +invalidate the remainder of the License, and in such case Affirmer hereby +affirms that he or she will not (i) exercise any of his or her remaining +Copyright and Related Rights in the Work or (ii) assert any associated claims +and causes of action with respect to the Work, in either case contrary to +Affirmer's express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + + b. Affirmer offers the Work as-is and makes no representations or warranties + of any kind concerning the Work, express, implied, statutory or otherwise, + including without limitation warranties of title, merchantability, fitness + for a particular purpose, non infringement, or the absence of latent or + other defects, accuracy, or the present or absence of errors, whether or not + discoverable, all to the greatest extent permissible under applicable law. + + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without limitation + any person's Copyright and Related Rights in the Work. Further, Affirmer + disclaims responsibility for obtaining any necessary consents, permissions + or other rights required for any use of the Work. + + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to this + CC0 or use of the Work. + +For more information, please see + diff --git a/node_modules/bats-assert/README.md b/node_modules/bats-assert/README.md new file mode 100644 index 000000000..8a5fc176b --- /dev/null +++ b/node_modules/bats-assert/README.md @@ -0,0 +1,1038 @@ +# bats-assert + +[![License](https://img.shields.io/npm/l/bats-assert.svg)](https://github.com/bats-core/bats-assert/blob/master/LICENSE) +[![GitHub release](https://img.shields.io/github/release/bats-core/bats-assert.svg)](https://github.com/bats-core/bats-assert/releases/latest) +[![npm release](https://img.shields.io/npm/v/bats-assert.svg)](https://www.npmjs.com/package/bats-assert) +[![Tests](https://github.com/bats-core/bats-assert/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/bats-core/bats-assert/actions/workflows/test.yml) + +`bats-assert` is a helper library providing common assertions for [Bats][bats]. + +- [Install](#install) +- [Usage](#usage) +- [Options](#options) +- [Full Assertion API](#full-assertion-api) + +In the context of this project, an [assertion][wikipedia-assertions] is a function that perform a test and returns `1` on failure or `0` on success. +To make debugging easier, the assertion also outputs relevant information on failure. +The output is [formatted][bats-support-output] for readability. +To make assertions usable outside of `@test` blocks, the output is sent to [stderr][wikipedia-stderr]. + +The most recent invocation of Bats' `run` function is used for testing assertions on output and status code. + +[wikipedia-assertions]: https://en.wikipedia.org/wiki/Assertion_(software_development) +[wikipedia-stderr]: https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr) + +## Install + +This project has one dependency, for output formatting: [`bats-support`][bats-support] + +Read the [shared documentation][bats-docs] to learn how to install and load both libraries. + +## Usage + +This project provides the following functions: + + - [assert](#assert) / [refute](#refute) Assert a given expression evaluates to `true` or `false`. + - [assert_equal](#assert_equal) Assert two parameters are equal. + - [assert_not_equal](#assert_not_equal) Assert two parameters are not equal. + - [assert_success](#assert_success) / [assert_failure](#assert_failure) Assert exit status is `0` or `1`. + - [assert_output](#assert_output) / [refute_output](#refute_output) Assert output does (or does not) contain given content. + - [assert_line](#assert_line) / [refute_line](#refute_line) Assert a specific line of output does (or does not) contain given content. + - [assert_regex](#assert_regex) / [refute_regex](#refute_regex) Assert a parameter does (or does not) match given pattern. + - [assert_stderr](#assert_stderr) / [refute_stderr](#refute_stderr) Assert stderr does (or does not) contain given content. + - [assert_stderr_line](#assert_stderr_line) / [refute_stderr_line](#refute_stderr_line) Assert a specific line of stderr does (or does not) contain given content. + +These commands are described in more detail below. + +## Options + +For functions that have options, `--` disables option parsing for the remaining arguments to allow using arguments identical to one of the allowed options. + +```bash +assert_output -- '-p' +``` + +Specifying `--` as an argument is similarly simple. + +```bash +refute_line -- '--' +``` + + +## Full Assertion API + +### `assert` + +Fail if the given expression evaluates to false. + +> _**Note**: +> The expression must be a simple command. +> [Compound commands][bash-comp-cmd], such as `[[`, can be used only when executed with `bash -c`._ + +```bash +@test 'assert()' { + assert [ 1 -lt 0 ] +} +``` + +On failure, the failed expression is displayed. + +``` +-- assertion failed -- +expression : [ 1 -lt 0 ] +-- +``` + + +### `refute` + +Fail if the given expression evaluates to true. + +> _**Note** +> The expression must be a simple command. +> [Compound commands][bash-comp-cmd], such as `[[`, can be used only when executed with `bash -c`._ + +```bash +@test 'refute()' { + refute [ 1 -gt 0 ] +} +``` + +On failure, the successful expression is displayed. + +``` +-- assertion succeeded, but it was expected to fail -- +expression : [ 1 -gt 0 ] +-- +``` + + +### `assert_equal` + +Fail if the two parameters, actual and expected value respectively, do not equal. + +```bash +@test 'assert_equal()' { + assert_equal 'have' 'want' +} +``` + +On failure, the expected and actual values are displayed. + +``` +-- values do not equal -- +expected : want +actual : have +-- +``` + +If either value is longer than one line both are displayed in *multi-line* format. + + +### `assert_not_equal` + +Fail if the two parameters, actual and unexpected value respectively, are equal. + +```bash +@test 'assert_not_equal()' { + assert_not_equal 'foobar' 'foobar' +} +``` + +On failure, the expected and actual values are displayed. + +``` +-- values should not be equal -- +unexpected : foobar +actual : foobar +-- +``` + +If either value is longer than one line both are displayed in *multi-line* format. + + +### `assert_success` + +Fail if `$status` is not 0. + +```bash +@test 'assert_success() status only' { + run bash -c "echo 'Error!'; exit 1" + assert_success +} +``` + +On failure, `$status` and `$output` are displayed. + +``` +-- command failed -- +status : 1 +output : Error! +-- +``` + +If `$output` is longer than one line, it is displayed in *multi-line* format. + + +### `assert_failure` + +Fail if `$status` is 0. + +```bash +@test 'assert_failure() status only' { + run echo 'Success!' + assert_failure +} +``` + +On failure, `$output` is displayed. + +``` +-- command succeeded, but it was expected to fail -- +output : Success! +-- +``` + +If `$output` is longer than one line, it is displayed in *multi-line* format. + +#### Expected status + +When one parameter is specified, fail if `$status` does not equal the expected status specified by the parameter. + +```bash +@test 'assert_failure() with expected status' { + run bash -c "echo 'Error!'; exit 1" + assert_failure 2 +} +``` + +On failure, the expected and actual status, and `$output` are displayed. + +``` +-- command failed as expected, but status differs -- +expected : 2 +actual : 1 +output : Error! +-- +``` + +If `$output` is longer than one line, it is displayed in *multi-line* format. + + +### `assert_output` + +This function helps to verify that a command or function produces the correct output by checking that the specified expected output matches the actual output. +Matching can be literal (default), partial or regular expression. +This function is the logical complement of `refute_output`. + +#### Literal matching + +By default, literal matching is performed. +The assertion fails if `$output` does not equal the expected output. + +```bash +@test 'assert_output()' { + run echo 'have' + assert_output 'want' +} +``` + +On failure, the expected and actual output are displayed. + +``` +-- output differs -- +expected : want +actual : have +-- +``` + +If either value is longer than one line both are displayed in *multi-line* format. + +#### Existence + +To assert that any (non-empty) output exists at all, simply omit the matching argument. + +```bash +@test 'assert_output()' { + run echo 'have' + assert_output +} +``` + +On failure, an error message is displayed. + +``` +-- no output -- +expected non-empty output, but output was empty +-- +``` + +#### Partial matching + +Partial matching can be enabled with the `--partial` option (`-p` for short). +When used, the assertion fails if the expected *substring* is not found in `$output`. + +```bash +@test 'assert_output() partial matching' { + run echo 'ERROR: no such file or directory' + assert_output --partial 'SUCCESS' +} +``` + +On failure, the substring and the output are displayed. + +``` +-- output does not contain substring -- +substring : SUCCESS +output : ERROR: no such file or directory +-- +``` + +This option and regular expression matching (`--regexp` or `-e`) are mutually exclusive. +An error is displayed when used simultaneously. + +#### Regular expression matching + +Regular expression matching can be enabled with the `--regexp` option (`-e` for short). +When used, the assertion fails if the *[extended regular expression]* does not match `$output`. + +[extended regular expression]: https://en.wikibooks.org/wiki/Regular_Expressions/POSIX-Extended_Regular_Expressions + +> [!IMPORTANT] +> Bash [doesn't support](https://stackoverflow.com/a/48898886/5432315) certain parts of regular expressions you may be used to: +> * `\d` `\D` `\s` `\S` `\w` `\W` — these can be replaced with POSIX character class equivalents `[[:digit:]]`, `[^[:digit:]]`, `[[:space:]]`, `[^[:space:]]`, `[_[:alnum:]]`, and `[^_[:alnum:]]`, respectively. (Notice the last case, where the `[:alnum:]` POSIX character class is augmented with underscore to be exactly equivalent to the Perl `\w` shorthand.) +> * Non-greedy matching. You can sometimes replace `a.*?b` with something like `a[^ab]*b` to get a similar effect in practice, though the two are not exactly equivalent. +> * Non-capturing parentheses `(?:...)`. In the trivial case, just use capturing parentheses `(...)` instead; though of course, if you use capture groups and/or backreferences, this will renumber your capture groups. +> * Lookarounds like `(?<=before)` or `(?!after)`. (In fact anything with `(?` is a Perl extension.) There is no simple general workaround for these, though you can sometimes rephrase your problem into one where lookarounds can be avoided. + +> _**Note**: +> The anchors `^` and `$` bind to the beginning and the end of the entire output (not individual lines), respectively._ + +```bash +@test 'assert_output() regular expression matching' { + run echo 'Foobar 0.1.0' + assert_output --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' +} +``` + +On failure, the regular expression and the output are displayed. + +``` +-- regular expression does not match output -- +regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ +output : Foobar 0.1.0 +-- +``` + +An error is displayed if the specified extended regular expression is invalid. + +This option and partial matching (`--partial` or `-p`) are mutually exclusive. +An error is displayed when used simultaneously. + +#### Standard Input, HereDocs and HereStrings + +The expected output can be specified via standard input (also heredoc/herestring) with the `-`/`--stdin` option. + +```bash +@test 'assert_output() with pipe' { + run echo 'hello' + echo 'hello' | assert_output - +} + +@test 'assert_output() with herestring' { + run echo 'hello' + assert_output - <<< hello +} +``` + + +### `refute_output` + +This function helps to verify that a command or function produces the correct output by checking that the specified unexpected output does not match the actual output. +Matching can be literal (default), partial or regular expression. +This function is the logical complement of `assert_output`. + +#### Literal matching + +By default, literal matching is performed. +The assertion fails if `$output` equals the unexpected output. + +```bash +@test 'refute_output()' { + run echo 'want' + refute_output 'want' +} +``` + +On failure, the output is displayed. + +``` +-- output equals, but it was expected to differ -- +output : want +-- +``` + +If output is longer than one line it is displayed in *multi-line* format. + +#### Existence + +To assert that there is no output at all, simply omit the matching argument. + +```bash +@test 'refute_output()' { + run foo --silent + refute_output +} +``` + +On failure, an error message is displayed. + +``` +-- unexpected output -- +expected no output, but output was non-empty +-- +``` + +#### Partial matching + +Partial matching can be enabled with the `--partial` option (`-p` for short). +When used, the assertion fails if the unexpected *substring* is found in `$output`. + +```bash +@test 'refute_output() partial matching' { + run echo 'ERROR: no such file or directory' + refute_output --partial 'ERROR' +} +``` + +On failure, the substring and the output are displayed. + +``` +-- output should not contain substring -- +substring : ERROR +output : ERROR: no such file or directory +-- +``` + +This option and regular expression matching (`--regexp` or `-e`) are mutually exclusive. +An error is displayed when used simultaneously. + +#### Regular expression matching + +Regular expression matching can be enabled with the `--regexp` option (`-e` for short). +When used, the assertion fails if the *extended regular expression* matches `$output`. + +> _**Note**: +> The anchors `^` and `$` bind to the beginning and the end of the entire output (not individual lines), respectively._ + +```bash +@test 'refute_output() regular expression matching' { + run echo 'Foobar v0.1.0' + refute_output --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' +} +``` + +On failure, the regular expression and the output are displayed. + +``` +-- regular expression should not match output -- +regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ +output : Foobar v0.1.0 +-- +``` + +An error is displayed if the specified extended regular expression is invalid. + +This option and partial matching (`--partial` or `-p`) are mutually exclusive. +An error is displayed when used simultaneously. + +#### Standard Input, HereDocs and HereStrings + +The unexpected output can be specified via standard input (also heredoc/herestring) with the `-`/`--stdin` option. + +```bash +@test 'refute_output() with pipe' { + run echo 'hello' + echo 'world' | refute_output - +} + +@test 'refute_output() with herestring' { + run echo 'hello' + refute_output - <<< world +} +``` + + +### `assert_line` + +Similarly to `assert_output`, this function helps to verify that a command or function produces the correct output. +It checks that the expected line appears in the output (default) or in a specific line of it. +Matching can be literal (default), partial or regular expression. +This function is the logical complement of `refute_line`. + +> _**Warning**: +> Due to a [bug in Bats][bats-93], empty lines are discarded from `${lines[@]}`, +> causing line indices to change and preventing testing for empty lines._ + +[bats-93]: https://github.com/sstephenson/bats/pull/93 + +#### Looking for a line in the output + +By default, the entire output is searched for the expected line. +The assertion fails if the expected line is not found in `${lines[@]}`. + +```bash +@test 'assert_line() looking for line' { + run echo $'have-0\nhave-1\nhave-2' + assert_line 'want' +} +``` + +On failure, the expected line and the output are displayed. + +> _**Warning**: +> The output displayed does not contain empty lines. +> See the Warning above for more._ + +``` +-- output does not contain line -- +line : want +output (3 lines): + have-0 + have-1 + have-2 +-- +``` + +If output is not longer than one line, it is displayed in *two-column* format. + +#### Matching a specific line + +When the `--index ` option is used (`-n ` for short), the expected line is matched only against the line identified by the given index. +The assertion fails if the expected line does not equal `${lines[]}`. + +```bash +@test 'assert_line() specific line' { + run echo $'have-0\nhave-1\nhave-2' + assert_line --index 1 'want-1' +} +``` + +On failure, the index and the compared lines are displayed. + +``` +-- line differs -- +index : 1 +expected : want-1 +actual : have-1 +-- +``` + +#### Partial matching + +Partial matching can be enabled with the `--partial` option (`-p` for short). +When used, a match fails if the expected *substring* is not found in the matched line. + +```bash +@test 'assert_line() partial matching' { + run echo $'have 1\nhave 2\nhave 3' + assert_line --partial 'want' +} +``` + +On failure, the same details are displayed as for literal matching, except that the substring replaces the expected line. + +``` +-- no output line contains substring -- +substring : want +output (3 lines): + have 1 + have 2 + have 3 +-- +``` + +This option and regular expression matching (`--regexp` or `-e`) are mutually exclusive. +An error is displayed when used simultaneously. + +#### Regular expression matching + +Regular expression matching can be enabled with the `--regexp` option (`-e` for short). +When used, a match fails if the *extended regular expression* does not match the line being tested. + +> _**Note**: +> As expected, the anchors `^` and `$` bind to the beginning and the end of the matched line, respectively._ + +```bash +@test 'assert_line() regular expression matching' { + run echo $'have-0\nhave-1\nhave-2' + assert_line --index 1 --regexp '^want-[0-9]$' +} +``` + +On failure, the same details are displayed as for literal matching, except that the regular expression replaces the expected line. + +``` +-- regular expression does not match line -- +index : 1 +regexp : ^want-[0-9]$ +line : have-1 +-- +``` + +An error is displayed if the specified extended regular expression is invalid. + +This option and partial matching (`--partial` or `-p`) are mutually exclusive. +An error is displayed when used simultaneously. + + +### `refute_line` + +Similarly to `refute_output`, this function helps to verify that a command or function produces the correct output. +It checks that the unexpected line does not appear in the output (default) or in a specific line of it. +Matching can be literal (default), partial or regular expression. +This function is the logical complement of `assert_line`. + +> _**Warning**: +> Due to a [bug in Bats][bats-93], empty lines are discarded from `${lines[@]}`, +> causing line indices to change and preventing testing for empty lines._ + +[bats-93]: https://github.com/sstephenson/bats/pull/93 + +#### Looking for a line in the output + +By default, the entire output is searched for the unexpected line. +The assertion fails if the unexpected line is found in `${lines[@]}`. + +```bash +@test 'refute_line() looking for line' { + run echo $'have-0\nwant\nhave-2' + refute_line 'want' +} +``` + +On failure, the unexpected line, the index of its first match and the output with the matching line highlighted are displayed. + +> _**Warning**: +> The output displayed does not contain empty lines. +> See the Warning above for more._ + +``` +-- line should not be in output -- +line : want +index : 1 +output (3 lines): + have-0 +> want + have-2 +-- +``` + +If output is not longer than one line, it is displayed in *two-column* format. + +#### Matching a specific line + +When the `--index ` option is used (`-n ` for short), the unexpected line is matched only against the line identified by the given index. +The assertion fails if the unexpected line equals `${lines[]}`. + +```bash +@test 'refute_line() specific line' { + run echo $'have-0\nwant-1\nhave-2' + refute_line --index 1 'want-1' +} +``` + +On failure, the index and the unexpected line are displayed. + +``` +-- line should differ -- +index : 1 +line : want-1 +-- +``` + +#### Partial matching + +Partial matching can be enabled with the `--partial` option (`-p` for short). +When used, a match fails if the unexpected *substring* is found in the matched line. + +```bash +@test 'refute_line() partial matching' { + run echo $'have 1\nwant 2\nhave 3' + refute_line --partial 'want' +} +``` + +On failure, in addition to the details of literal matching, the substring is also displayed. +When used with `--index ` the substring replaces the unexpected line. + +``` +-- no line should contain substring -- +substring : want +index : 1 +output (3 lines): + have 1 +> want 2 + have 3 +-- +``` + +This option and regular expression matching (`--regexp` or `-e`) are mutually exclusive. +An error is displayed when used simultaneously. + +#### Regular expression matching + +Regular expression matching can be enabled with the `--regexp` option (`-e` for short). +When used, a match fails if the *extended regular expression* matches the line being tested. + +> _**Note**: +> As expected, the anchors `^` and `$` bind to the beginning and the end of the matched line, respectively._ + +```bash +@test 'refute_line() regular expression matching' { + run echo $'Foobar v0.1.0\nRelease date: 2015-11-29' + refute_line --index 0 --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' +} +``` + +On failure, in addition to the details of literal matching, the regular expression is also displayed. +When used with `--index ` the regular expression replaces the unexpected line. + +``` +-- regular expression should not match line -- +index : 0 +regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ +line : Foobar v0.1.0 +-- +``` + +An error is displayed if the specified extended regular expression is invalid. + +This option and partial matching (`--partial` or `-p`) are mutually exclusive. +An error is displayed when used simultaneously. + +### `assert_regex` + +This function is similar to `assert_equal` but uses pattern matching instead of +equality, by wrapping `[[ value =~ pattern ]]`. + +Fail if the value (first parameter) does not match the pattern (second +parameter). + +```bash +@test 'assert_regex()' { + assert_regex 'what' 'x$' +} +``` + +On failure, the value and the pattern are displayed. + +``` +-- values does not match regular expression -- +value : what +pattern : x$ +-- +``` + +If the value is longer than one line then it is displayed in *multi-line* +format. + +An error is displayed if the specified extended regular expression is invalid. + +For description of the matching behavior, refer to the documentation of the +`=~` operator in the [Bash manual][bash-conditional]. + +> _**Note**: +> the `BASH_REMATCH` array is available immediately after the assertion succeeds but is fragile; +> i.e. prone to being overwritten as a side effect of other actions._ + +### `refute_regex` + +This function is similar to `refute_equal` but uses pattern matching instead of +equality, by wrapping `! [[ value =~ pattern ]]`. + +Fail if the value (first parameter) matches the pattern (second parameter). + +```bash +@test 'refute_regex()' { + refute_regex 'WhatsApp' 'Threema' +} +``` + +On failure, the value, the pattern and the match are displayed. + +```bash +@test 'refute_regex()' { + refute_regex 'WhatsApp' 'What.' +} + +-- value matches regular expression -- +value : WhatsApp +pattern : What. +match : Whats +case : sensitive +-- +``` + +If the value or pattern is longer than one line then it is displayed in +*multi-line* format. + +An error is displayed if the specified extended regular expression is invalid. + +For description of the matching behavior, refer to the documentation of the +`=~` operator in the [Bash manual][bash-conditional]. + +> _**Note**: +> the `BASH_REMATCH` array is available immediately after the assertion fails but is fragile; +> i.e. prone to being overwritten as a side effect of other actions like calling `run`. +> Thus, it's good practice to avoid using `BASH_REMATCH` in conjunction with `refute_regex()`. +> The valuable information the array contains is the matching part of the value which is printed in the failing test log, as mentioned above._ + +### `assert_stderr` + +> _**Note**: +> `run` has to be called with `--separate-stderr` to separate stdout and stderr into `$output` and `$stderr`. +> If not, `$stderr` will be empty, causing `assert_stderr` to always fail. + +Similarly to `assert_output`, this function verifies that a command or function produces the expected stderr. +The stderr matching can be literal (the default), partial or by regular expression. +The expected stderr can be specified either by positional argument or read from STDIN by passing the `-`/`--stdin` flag. + +#### Literal matching + +By default, literal matching is performed. +The assertion fails if `$stderr` does not equal the expected stderr. + + ```bash + echo_err() { + echo "$@" >&2 + } + + @test 'assert_stderr()' { + run --separate-stderr echo_err 'have' + assert_stderr 'want' + } + + @test 'assert_stderr() with pipe' { + run --separate-stderr echo_err 'hello' + echo_err 'hello' | assert_stderr - + } + + @test 'assert_stderr() with herestring' { + run --separate-stderr echo_err 'hello' + assert_stderr - <<< hello + } + ``` + +On failure, the expected and actual stderr are displayed. + + ``` + -- stderr differs -- + expected : want + actual : have + -- + ``` + +#### Existence + +To assert that any stderr exists at all, omit the `expected` argument. + + ```bash + @test 'assert_stderr()' { + run --separate-stderr echo_err 'have' + assert_stderr + } + ``` + +On failure, an error message is displayed. + + ``` + -- no stderr -- + expected non-empty stderr, but stderr was empty + -- + ``` + +#### Partial matching + +Partial matching can be enabled with the `--partial` option (`-p` for short). +When used, the assertion fails if the expected _substring_ is not found in `$stderr`. + + ```bash + @test 'assert_stderr() partial matching' { + run --separate-stderr echo_err 'ERROR: no such file or directory' + assert_stderr --partial 'SUCCESS' + } + ``` + +On failure, the substring and the stderr are displayed. + + ``` + -- stderr does not contain substring -- + substring : SUCCESS + stderr : ERROR: no such file or directory + -- + ``` + +#### Regular expression matching + +Regular expression matching can be enabled with the `--regexp` option (`-e` for short). +When used, the assertion fails if the *extended regular expression* does not match `$stderr`. + +*Note: The anchors `^` and `$` bind to the beginning and the end (respectively) of the entire stderr; not individual lines.* + + ```bash + @test 'assert_stderr() regular expression matching' { + run --separate-stderr echo_err 'Foobar 0.1.0' + assert_stderr --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' + } + ``` + +On failure, the regular expression and the stderr are displayed. + + ``` + -- regular expression does not match stderr -- + regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ + stderr : Foobar 0.1.0 + -- + ``` + +### `refute_stderr` + +> _**Note**: +> `run` has to be called with `--separate-stderr` to separate stdout and stderr into `$output` and `$stderr`. +> If not, `$stderr` will be empty, causing `refute_stderr` to always pass. + +Similar to `refute_output`, this function verifies that a command or function does not produce the unexpected stderr. +(It is the logical complement of `assert_stderr`.) +The stderr matching can be literal (the default), partial or by regular expression. +The unexpected stderr can be specified either by positional argument or read from STDIN by passing the `-`/`--stdin` flag. + +### `assert_stderr_line` + +> _**Note**: +> `run` has to be called with `--separate-stderr` to separate stdout and stderr into `$output` and `$stderr`. +> If not, `$stderr` will be empty, causing `assert_stderr_line` to always fail. + +Similarly to `assert_stderr`, this function verifies that a command or function produces the expected stderr. +It checks that the expected line appears in the stderr (default) or at a specific line number. +Matching can be literal (default), partial or regular expression. +This function is the logical complement of `refute_stderr_line`. + +#### Looking for a line in the stderr + +By default, the entire stderr is searched for the expected line. +The assertion fails if the expected line is not found in `${stderr_lines[@]}`. + + ```bash + echo_err() { + echo "$@" >&2 + } + + @test 'assert_stderr_line() looking for line' { + run --separate-stderr echo_err $'have-0\nhave-1\nhave-2' + assert_stderr_line 'want' + } + ``` + +On failure, the expected line and the stderr are displayed. + + ``` + -- stderr does not contain line -- + line : want + stderr (3 lines): + have-0 + have-1 + have-2 + -- + ``` + +#### Matching a specific line + +When the `--index ` option is used (`-n ` for short), the expected line is matched only against the line identified by the given index. +The assertion fails if the expected line does not equal `${stderr_lines[]}`. + + ```bash + @test 'assert_stderr_line() specific line' { + run --separate-stderr echo_err $'have-0\nhave-1\nhave-2' + assert_stderr_line --index 1 'want-1' + } + ``` + +On failure, the index and the compared stderr_lines are displayed. + + ``` + -- line differs -- + index : 1 + expected : want-1 + actual : have-1 + -- + ``` + +#### Partial matching + +Partial matching can be enabled with the `--partial` option (`-p` for short). +When used, a match fails if the expected *substring* is not found in the matched line. + + ```bash + @test 'assert_stderr_line() partial matching' { + run --separate-stderr echo_err $'have 1\nhave 2\nhave 3' + assert_stderr_line --partial 'want' + } + ``` + +On failure, the same details are displayed as for literal matching, except that the substring replaces the expected line. + + ``` + -- no stderr line contains substring -- + substring : want + stderr (3 lines): + have 1 + have 2 + have 3 + -- + ``` + +#### Regular expression matching + +Regular expression matching can be enabled with the `--regexp` option (`-e` for short). +When used, a match fails if the *extended regular expression* does not match the line being tested. + +*Note: As expected, the anchors `^` and `$` bind to the beginning and the end (respectively) of the matched line.* + + ```bash + @test 'assert_stderr_line() regular expression matching' { + run --separate-stderr echo_err $'have-0\nhave-1\nhave-2' + assert_stderr_line --index 1 --regexp '^want-[0-9]$' + } + ``` + +On failure, the same details are displayed as for literal matching, except that the regular expression replaces the expected line. + + ``` + -- regular expression does not match line -- + index : 1 + regexp : ^want-[0-9]$ + line : have-1 + -- + ``` + +### `refute_stderr_line` + +> _**Note**: +> `run` has to be called with `--separate-stderr` to separate stdout and stderr into `$output` and `$stderr`. +> If not, `$stderr` will be empty, causing `refute_stderr_line` to always pass. + +Similarly to `refute_stderr`, this function helps to verify that a command or function produces the correct stderr. +It checks that the unexpected line does not appear in the stderr (default) or in a specific line of it. +Matching can be literal (default), partial or regular expression. +This function is the logical complement of `assert_stderr_line`. + + + +[bats]: https://github.com/bats-core/bats-core +[bash-comp-cmd]: https://www.gnu.org/software/bash/manual/bash.html#Compound-Commands +[bash-conditional]: https://www.gnu.org/software/bash/manual/bash.html#Conditional-Constructs + +[bats-docs]: https://bats-core.readthedocs.io/ +[bats-support-output]: https://github.com/bats-core/bats-support#output-formatting +[bats-support]: https://github.com/bats-core/bats-support diff --git a/node_modules/bats-assert/load.bash b/node_modules/bats-assert/load.bash new file mode 100644 index 000000000..c67d9e8b4 --- /dev/null +++ b/node_modules/bats-assert/load.bash @@ -0,0 +1,33 @@ +# bats-assert - Common assertions for Bats +# +# Written in 2016 by Zoltan Tombol +# +# To the extent possible under law, the author(s) have dedicated all +# copyright and related and neighboring rights to this software to the +# public domain worldwide. This software is distributed without any +# warranty. +# +# You should have received a copy of the CC0 Public Domain Dedication +# along with this software. If not, see +# . +# +# Assertions are functions that perform a test and output relevant +# information on failure to help debugging. They return 1 on failure +# and 0 otherwise. +# +# All output is formatted for readability using the functions of +# `output.bash' and sent to the standard error. + +# shellcheck disable=1090 +source "$(dirname "${BASH_SOURCE[0]}")/src/assert.bash" +source "$(dirname "${BASH_SOURCE[0]}")/src/refute.bash" +source "$(dirname "${BASH_SOURCE[0]}")/src/assert_equal.bash" +source "$(dirname "${BASH_SOURCE[0]}")/src/assert_not_equal.bash" +source "$(dirname "${BASH_SOURCE[0]}")/src/assert_success.bash" +source "$(dirname "${BASH_SOURCE[0]}")/src/assert_failure.bash" +source "$(dirname "${BASH_SOURCE[0]}")/src/assert_output.bash" +source "$(dirname "${BASH_SOURCE[0]}")/src/refute_output.bash" +source "$(dirname "${BASH_SOURCE[0]}")/src/assert_line.bash" +source "$(dirname "${BASH_SOURCE[0]}")/src/refute_line.bash" +source "$(dirname "${BASH_SOURCE[0]}")/src/assert_regex.bash" +source "$(dirname "${BASH_SOURCE[0]}")/src/refute_regex.bash" diff --git a/node_modules/bats-assert/package.json b/node_modules/bats-assert/package.json new file mode 100644 index 000000000..e99eab066 --- /dev/null +++ b/node_modules/bats-assert/package.json @@ -0,0 +1,49 @@ +{ + "name": "bats-assert", + "version": "2.2.4", + "description": "Common assertions for Bats", + "homepage": "https://github.com/bats-core/bats-assert", + "license": "CC0-1.0", + "author": "Zoltán Tömböl (https://github.com/ztombol)", + "contributors": [ + "Sam Stephenson (http://sstephenson.us/)", + "Jason Karns (http://jasonkarns.com)", + "Mislav Marohnić (http://mislav.net/)", + "Tim Pope (https://github.com/tpope)" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/bats-core/bats-assert.git" + }, + "bugs": "https://github.com/bats-core/bats-assert/issues", + "directories": { + "lib": "src", + "test": "test" + }, + "files": [ + "load.bash", + "src" + ], + "scripts": { + "test": "bats ${CI+-t} test", + "postversion": "git push --follow-tags" + }, + "devDependencies": { + "bats": "^1", + "bats-support": "^0.3" + }, + "peerDependencies": { + "bats": "0.4 || ^1", + "bats-support": "^0.3" + }, + "keywords": [ + "bats", + "bash", + "shell", + "test", + "unit", + "assert", + "assertion", + "helper" + ] +} diff --git a/node_modules/bats-assert/src/assert.bash b/node_modules/bats-assert/src/assert.bash new file mode 100644 index 000000000..0260ce231 --- /dev/null +++ b/node_modules/bats-assert/src/assert.bash @@ -0,0 +1,42 @@ +# assert +# ====== +# +# Summary: Fail if the given expression evaluates to false. +# +# Usage: assert + +# Options: +# The expression to evaluate for truthiness. +# *__Note:__ The expression must be a simple command. +# [Compound commands](https://www.gnu.org/software/bash/manual/bash.html#Compound-Commands), +# such as `[[`, can be used only when executed with `bash -c`.* +# +# IO: +# STDERR - the failed expression, on failure +# Globals: +# none +# Returns: +# 0 - if expression evaluates to true +# 1 - otherwise +# +# ```bash +# @test 'assert()' { +# touch '/var/log/test.log' +# assert [ -e '/var/log/test.log' ] +# } +# ``` +# +# On failure, the failed expression is displayed. +# +# ``` +# -- assertion failed -- +# expression : [ -e /var/log/test.log ] +# -- +# ``` +assert() { + if ! "$@"; then + batslib_print_kv_single 10 'expression' "$*" \ + | batslib_decorate 'assertion failed' \ + | fail + fi +} diff --git a/node_modules/bats-assert/src/assert_equal.bash b/node_modules/bats-assert/src/assert_equal.bash new file mode 100644 index 000000000..4ef1297ed --- /dev/null +++ b/node_modules/bats-assert/src/assert_equal.bash @@ -0,0 +1,42 @@ +# assert_equal +# ============ +# +# Summary: Fail if the actual and expected values are not equal. +# +# Usage: assert_equal +# +# Options: +# The value being compared. +# The value to compare against. +# +# ```bash +# @test 'assert_equal()' { +# assert_equal 'have' 'want' +# } +# ``` +# +# IO: +# STDERR - expected and actual values, on failure +# Globals: +# none +# Returns: +# 0 - if values equal +# 1 - otherwise +# +# On failure, the expected and actual values are displayed. +# +# ``` +# -- values do not equal -- +# expected : want +# actual : have +# -- +# ``` +assert_equal() { + if [[ $1 != "$2" ]]; then + batslib_print_kv_single_or_multi 8 \ + 'expected' "$2" \ + 'actual' "$1" \ + | batslib_decorate 'values do not equal' \ + | fail + fi +} diff --git a/node_modules/bats-assert/src/assert_failure.bash b/node_modules/bats-assert/src/assert_failure.bash new file mode 100644 index 000000000..268d44758 --- /dev/null +++ b/node_modules/bats-assert/src/assert_failure.bash @@ -0,0 +1,86 @@ +# assert_failure +# ============== +# +# Summary: Fail if `$status` is 0; or is not equal to the optionally provided status. +# +# Usage: assert_failure [] +# +# Options: +# The specific status code to check against. +# If not provided, simply asserts status is != 0. +# +# IO: +# STDERR - `$output`, on failure; +# - also, `$status` and `expected_status`, if provided +# Globals: +# status +# output +# Returns: +# 0 - if `$status' is 0, +# or if expected_status is provided but does not equal `$status' +# 1 - otherwise +# +# ```bash +# @test 'assert_failure() status only' { +# run echo 'Success!' +# assert_failure +# } +# ``` +# +# On failure, `$output` is displayed. +# +# ``` +# -- command succeeded, but it was expected to fail -- +# output : Success! +# -- +# ``` +# +# ## Expected status +# +# When `expected_status` is provided, fail if `$status` does not equal the `expected_status`. +# +# ```bash +# @test 'assert_failure() with expected status' { +# run bash -c "echo 'Error!'; exit 1" +# assert_failure 2 +# } +# ``` +# +# On failure, both the expected and actual statuses, and `$output` are displayed. +# +# ``` +# -- command failed as expected, but status differs -- +# expected : 2 +# actual : 1 +# output : Error! +# -- +# ``` +assert_failure() { + : "${output?}" + : "${status?}" + + (( $# > 0 )) && local -r expected="$1" + if (( status == 0 )); then + { local -ir width=6 + batslib_print_kv_single_or_multi "$width" 'output' "$output" + if [[ -n "${stderr-}" ]]; then + batslib_print_kv_single_or_multi "$width" 'stderr' "$stderr" + fi + } \ + | batslib_decorate 'command succeeded, but it was expected to fail' \ + | fail + elif (( $# > 0 )) && (( status != expected )); then + { local -ir width=8 + batslib_print_kv_single "$width" \ + 'expected' "$expected" \ + 'actual' "$status" + batslib_print_kv_single_or_multi "$width" \ + 'output' "$output" + if [[ -n "${stderr-}" ]]; then + batslib_print_kv_single_or_multi "$width" 'stderr' "$stderr" + fi + } \ + | batslib_decorate 'command failed as expected, but status differs' \ + | fail + fi +} diff --git a/node_modules/bats-assert/src/assert_line.bash b/node_modules/bats-assert/src/assert_line.bash new file mode 100644 index 000000000..0e9cf5b31 --- /dev/null +++ b/node_modules/bats-assert/src/assert_line.bash @@ -0,0 +1,298 @@ +# assert_line +# =========== +# +# Summary: Fail if the expected line is not found in the output (default) or at a specific line number. +# +# Usage: assert_line [-n index] [-p | -e] [--] +# +# Options: +# -n, --index Match the th line +# -p, --partial Match if `expected` is a substring of `$output` or line +# -e, --regexp Treat `expected` as an extended regular expression +# The expected line string, substring, or regular expression +# +# IO: +# STDERR - details, on failure +# error message, on error +# Globals: +# output +# lines +# Returns: +# 0 - if matching line found +# 1 - otherwise +# +# Similarly to `assert_output`, this function verifies that a command or function produces the expected output. +# (It is the logical complement of `refute_line`.) +# It checks that the expected line appears in the output (default) or at a specific line number. +# Matching can be literal (default), partial or regular expression. +# +# *__Warning:__ +# Due to a [bug in Bats][bats-93], empty lines are discarded from `${lines[@]}`, +# causing line indices to change and preventing testing for empty lines.* +# +# [bats-93]: https://github.com/sstephenson/bats/pull/93 +# +# ## Looking for a line in the output +# +# By default, the entire output is searched for the expected line. +# The assertion fails if the expected line is not found in `${lines[@]}`. +# +# ```bash +# @test 'assert_line() looking for line' { +# run echo $'have-0\nhave-1\nhave-2' +# assert_line 'want' +# } +# ``` +# +# On failure, the expected line and the output are displayed. +# +# ``` +# -- output does not contain line -- +# line : want +# output (3 lines): +# have-0 +# have-1 +# have-2 +# -- +# ``` +# +# ## Matching a specific line +# +# When the `--index ` option is used (`-n ` for short), the expected line is matched only against the line identified by the given index. +# The assertion fails if the expected line does not equal `${lines[]}`. +# +# ```bash +# @test 'assert_line() specific line' { +# run echo $'have-0\nhave-1\nhave-2' +# assert_line --index 1 'want-1' +# } +# ``` +# +# On failure, the index and the compared lines are displayed. +# +# ``` +# -- line differs -- +# index : 1 +# expected : want-1 +# actual : have-1 +# -- +# ``` +# +# ## Partial matching +# +# Partial matching can be enabled with the `--partial` option (`-p` for short). +# When used, a match fails if the expected *substring* is not found in the matched line. +# +# ```bash +# @test 'assert_line() partial matching' { +# run echo $'have 1\nhave 2\nhave 3' +# assert_line --partial 'want' +# } +# ``` +# +# On failure, the same details are displayed as for literal matching, except that the substring replaces the expected line. +# +# ``` +# -- no output line contains substring -- +# substring : want +# output (3 lines): +# have 1 +# have 2 +# have 3 +# -- +# ``` +# +# ## Regular expression matching +# +# Regular expression matching can be enabled with the `--regexp` option (`-e` for short). +# When used, a match fails if the *extended regular expression* does not match the line being tested. +# +# *__Note__: +# As expected, the anchors `^` and `$` bind to the beginning and the end (respectively) of the matched line.* +# +# ```bash +# @test 'assert_line() regular expression matching' { +# run echo $'have-0\nhave-1\nhave-2' +# assert_line --index 1 --regexp '^want-[0-9]$' +# } +# ``` +# +# On failure, the same details are displayed as for literal matching, except that the regular expression replaces the expected line. +# +# ``` +# -- regular expression does not match line -- +# index : 1 +# regexp : ^want-[0-9]$ +# line : have-1 +# -- +# ``` +# FIXME(ztombol): Display `${lines[@]}' instead of `$output'! +assert_line() { + __assert_line "$@" +} + +# assert_stderr_line +# =========== +# +# Summary: Fail if the expected line is not found in the stderr (default) or at a specific line number. +# +# Usage: assert_stderr_line [-n index] [-p | -e] [--] +# +# Options: +# -n, --index Match the th line +# -p, --partial Match if `expected` is a substring of `$stderr` or line +# -e, --regexp Treat `expected` as an extended regular expression +# The expected line string, substring, or regular expression +# +# IO: +# STDERR - details, on failure +# error message, on error +# Globals: +# stderr +# stderr_lines +# Returns: +# 0 - if matching line found +# 1 - otherwise +# +# Similarly to `assert_stderr`, this function verifies that a command or function produces the expected stderr. +# (It is the logical complement of `refute_stderr_line`.) +# It checks that the expected line appears in the stderr (default) or at a specific line number. +# Matching can be literal (default), partial or regular expression. +# +assert_stderr_line() { + __assert_line "$@" +} + +__assert_line() { + local -r caller=${FUNCNAME[1]} + local -i is_match_line=0 + local -i is_mode_partial=0 + local -i is_mode_regexp=0 + + if [[ "${caller}" == "assert_line" ]]; then + : "${lines?}" + local -ar stream_lines=("${lines[@]}") + local -r stream_type=output + elif [[ "${caller}" == "assert_stderr_line" ]]; then + : "${stderr_lines?}" + local -ar stream_lines=("${stderr_lines[@]}") + local -r stream_type=stderr + else + # Unknown caller + echo "Unexpected call to \`${FUNCNAME[0]}\` +Did you mean to call \`assert_line\` or \`assert_stderr_line\`?" \ + | batslib_decorate "ERROR: ${FUNCNAME[0]}" \ + | fail + return $? + fi + + # Handle options. + while (( $# > 0 )); do + case "$1" in + -n|--index) + if (( $# < 2 )) || ! [[ $2 =~ ^-?([0-9]|[1-9][0-9]+)$ ]]; then + echo "\`--index' requires an integer argument: \`$2'" \ + | batslib_decorate "ERROR: ${caller}" \ + | fail + return $? + fi + is_match_line=1 + local -ri idx="$2" + shift 2 + ;; + -p|--partial) is_mode_partial=1; shift ;; + -e|--regexp) is_mode_regexp=1; shift ;; + --) shift; break ;; + *) break ;; + esac + done + + if (( is_mode_partial )) && (( is_mode_regexp )); then + echo "\`--partial' and \`--regexp' are mutually exclusive" \ + | batslib_decorate "ERROR: ${caller}" \ + | fail + return $? + fi + + # Arguments. + local -r expected="$1" + + if (( is_mode_regexp == 1 )); then + __check_is_valid_regex "$expected" "$caller" || return 1 + fi + + # Matching. + if (( is_match_line )); then + # Specific line. + if (( is_mode_regexp )); then + if ! [[ ${stream_lines[$idx]} =~ $expected ]]; then + batslib_print_kv_single 6 \ + 'index' "$idx" \ + 'regexp' "$expected" \ + 'line' "${stream_lines[$idx]}" \ + | batslib_decorate 'regular expression does not match line' \ + | fail + fi + elif (( is_mode_partial )); then + if [[ ${stream_lines[$idx]} != *"$expected"* ]]; then + batslib_print_kv_single 9 \ + 'index' "$idx" \ + 'substring' "$expected" \ + 'line' "${stream_lines[$idx]}" \ + | batslib_decorate 'line does not contain substring' \ + | fail + fi + else + if [[ ${stream_lines[$idx]} != "$expected" ]]; then + batslib_print_kv_single 8 \ + 'index' "$idx" \ + 'expected' "$expected" \ + 'actual' "${stream_lines[$idx]}" \ + | batslib_decorate 'line differs' \ + | fail + fi + fi + else + # Contained in output/error stream. + if (( is_mode_regexp )); then + local -i idx + for (( idx = 0; idx < ${#stream_lines[@]}; ++idx )); do + [[ ${stream_lines[$idx]} =~ $expected ]] && return 0 + done + { local -ar single=( 'regexp' "$expected" ) + local -ar may_be_multi=( "${stream_type}" "${!stream_type}" ) + local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )" + batslib_print_kv_single "$width" "${single[@]}" + batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}" + } \ + | batslib_decorate "no ${stream_type} line matches regular expression" \ + | fail + elif (( is_mode_partial )); then + local -i idx + for (( idx = 0; idx < ${#stream_lines[@]}; ++idx )); do + [[ ${stream_lines[$idx]} == *"$expected"* ]] && return 0 + done + { local -ar single=( 'substring' "$expected" ) + local -ar may_be_multi=( "${stream_type}" "${!stream_type}" ) + local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )" + batslib_print_kv_single "$width" "${single[@]}" + batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}" + } \ + | batslib_decorate "no ${stream_type} line contains substring" \ + | fail + else + local -i idx + for (( idx = 0; idx < ${#stream_lines[@]}; ++idx )); do + [[ ${stream_lines[$idx]} == "$expected" ]] && return 0 + done + { local -ar single=( 'line' "$expected" ) + local -ar may_be_multi=( "${stream_type}" "${!stream_type}" ) + local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )" + batslib_print_kv_single "$width" "${single[@]}" + batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}" + } \ + | batslib_decorate "${stream_type} does not contain line" \ + | fail + fi + fi +} diff --git a/node_modules/bats-assert/src/assert_not_equal.bash b/node_modules/bats-assert/src/assert_not_equal.bash new file mode 100644 index 000000000..933bb713d --- /dev/null +++ b/node_modules/bats-assert/src/assert_not_equal.bash @@ -0,0 +1,42 @@ +# assert_not_equal +# ============ +# +# Summary: Fail if the actual and unexpected values are equal. +# +# Usage: assert_not_equal +# +# Options: +# The value being compared. +# The value to compare against. +# +# ```bash +# @test 'assert_not_equal()' { +# assert_not_equal 'foo' 'foo' +# } +# ``` +# +# IO: +# STDERR - expected and actual values, on failure +# Globals: +# none +# Returns: +# 0 - if actual does not equal unexpected +# 1 - otherwise +# +# On failure, the unexpected and actual values are displayed. +# +# ``` +# -- values should not be equal -- +# unexpected : foo +# actual : foo +# -- +# ``` +assert_not_equal() { + if [[ "$1" == "$2" ]]; then + batslib_print_kv_single_or_multi 10 \ + 'unexpected' "$2" \ + 'actual' "$1" \ + | batslib_decorate 'values should not be equal' \ + | fail + fi +} diff --git a/node_modules/bats-assert/src/assert_output.bash b/node_modules/bats-assert/src/assert_output.bash new file mode 100644 index 000000000..e654ba299 --- /dev/null +++ b/node_modules/bats-assert/src/assert_output.bash @@ -0,0 +1,247 @@ +# assert_output +# ============= +# +# Summary: Fail if `$output' does not match the expected output. +# +# Usage: assert_output [-p | -e] [- | [--] ] +# +# Options: +# -p, --partial Match if `expected` is a substring of `$output` +# -e, --regexp Treat `expected` as an extended regular expression +# -, --stdin Read `expected` value from STDIN +# The expected value, substring or regular expression +# +# IO: +# STDIN - [=$1] expected output +# STDERR - details, on failure +# error message, on error +# Globals: +# output +# Returns: +# 0 - if output matches the expected value/partial/regexp +# 1 - otherwise +# +# This function verifies that a command or function produces the expected output. +# (It is the logical complement of `refute_output`.) +# Output matching can be literal (the default), partial or by regular expression. +# The expected output can be specified either by positional argument or read from STDIN by passing the `-`/`--stdin` flag. +# +# ## Literal matching +# +# By default, literal matching is performed. +# The assertion fails if `$output` does not equal the expected output. +# +# ```bash +# @test 'assert_output()' { +# run echo 'have' +# assert_output 'want' +# } +# +# @test 'assert_output() with pipe' { +# run echo 'hello' +# echo 'hello' | assert_output - +# } +# +# @test 'assert_output() with herestring' { +# run echo 'hello' +# assert_output - <<< hello +# } +# ``` +# +# On failure, the expected and actual output are displayed. +# +# ``` +# -- output differs -- +# expected : want +# actual : have +# -- +# ``` +# +# ## Existence +# +# To assert that any output exists at all, omit the `expected` argument. +# +# ```bash +# @test 'assert_output()' { +# run echo 'have' +# assert_output +# } +# ``` +# +# On failure, an error message is displayed. +# +# ``` +# -- no output -- +# expected non-empty output, but output was empty +# -- +# ``` +# +# ## Partial matching +# +# Partial matching can be enabled with the `--partial` option (`-p` for short). +# When used, the assertion fails if the expected _substring_ is not found in `$output`. +# +# ```bash +# @test 'assert_output() partial matching' { +# run echo 'ERROR: no such file or directory' +# assert_output --partial 'SUCCESS' +# } +# ``` +# +# On failure, the substring and the output are displayed. +# +# ``` +# -- output does not contain substring -- +# substring : SUCCESS +# output : ERROR: no such file or directory +# -- +# ``` +# +# ## Regular expression matching +# +# Regular expression matching can be enabled with the `--regexp` option (`-e` for short). +# When used, the assertion fails if the *extended regular expression* does not match `$output`. +# +# *__Note__: +# The anchors `^` and `$` bind to the beginning and the end (respectively) of the entire output; +# not individual lines.* +# +# ```bash +# @test 'assert_output() regular expression matching' { +# run echo 'Foobar 0.1.0' +# assert_output --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' +# } +# ``` +# +# On failure, the regular expression and the output are displayed. +# +# ``` +# -- regular expression does not match output -- +# regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ +# output : Foobar 0.1.0 +# -- +# ``` +assert_output() { + __assert_stream "$@" +} + +# assert_stderr +# ============= +# +# Summary: Fail if `$stderr' does not match the expected stderr. +# +# Usage: assert_stderr [-p | -e] [- | [--] ] +# +# Options: +# -p, --partial Match if `expected` is a substring of `$stderr` +# -e, --regexp Treat `expected` as an extended regular expression +# -, --stdin Read `expected` value from STDIN +# The expected value, substring or regular expression +# +# IO: +# STDIN - [=$1] expected stderr +# STDERR - details, on failure +# error message, on error +# Globals: +# stderr +# Returns: +# 0 - if stderr matches the expected value/partial/regexp +# 1 - otherwise +# +# Similarly to `assert_output`, this function verifies that a command or function produces the expected stderr. +# (It is the logical complement of `refute_stderr`.) +# The stderr matching can be literal (the default), partial or by regular expression. +# The expected stderr can be specified either by positional argument or read from STDIN by passing the `-`/`--stdin` flag. +# +assert_stderr() { + __assert_stream "$@" +} + +__assert_stream() { + local -r caller=${FUNCNAME[1]} + local -r stream_type=${caller/assert_/} + local -i is_mode_partial=0 + local -i is_mode_regexp=0 + local -i is_mode_nonempty=0 + local -i use_stdin=0 + + if [[ ${stream_type} == "output" ]]; then + : "${output?}" + elif [[ ${stream_type} == "stderr" ]]; then + : "${stderr?}" + else + # Unknown caller + echo "Unexpected call to \`${FUNCNAME[0]}\` +Did you mean to call \`assert_output\` or \`assert_stderr\`?" | + batslib_decorate "ERROR: ${FUNCNAME[0]}" | + fail + return $? + fi + local -r stream="${!stream_type}" + + # Handle options. + if (( $# == 0 )); then + is_mode_nonempty=1 + fi + + while (( $# > 0 )); do + case "$1" in + -p|--partial) is_mode_partial=1; shift ;; + -e|--regexp) is_mode_regexp=1; shift ;; + -|--stdin) use_stdin=1; shift ;; + --) shift; break ;; + *) break ;; + esac + done + + if (( is_mode_partial )) && (( is_mode_regexp )); then + echo "\`--partial' and \`--regexp' are mutually exclusive" \ + | batslib_decorate "ERROR: ${caller}" \ + | fail + return $? + fi + + # Arguments. + local expected + if (( use_stdin )); then + expected="$(cat -)" + else + expected="${1-}" + fi + + # Matching. + if (( is_mode_nonempty )); then + if [ -z "$stream" ]; then + echo "expected non-empty $stream_type, but $stream_type was empty" \ + | batslib_decorate "no $stream_type" \ + | fail + fi + elif (( is_mode_regexp )); then + # shellcheck disable=2319 + if ! __check_is_valid_regex "$expected" "$caller"; then + return 1 + elif ! [[ $stream =~ $expected ]]; then + batslib_print_kv_single_or_multi 6 \ + 'regexp' "$expected" \ + "$stream_type" "$stream" \ + | batslib_decorate "regular expression does not match $stream_type" \ + | fail + fi + elif (( is_mode_partial )); then + if [[ $stream != *"$expected"* ]]; then + batslib_print_kv_single_or_multi 9 \ + 'substring' "$expected" \ + "$stream_type" "$stream" \ + | batslib_decorate "$stream_type does not contain substring" \ + | fail + fi + else + if [[ $stream != "$expected" ]]; then + batslib_print_kv_single_or_multi 8 \ + 'expected' "$expected" \ + 'actual' "$stream" \ + | batslib_decorate "$stream_type differs" \ + | fail + fi + fi +} diff --git a/node_modules/bats-assert/src/assert_regex.bash b/node_modules/bats-assert/src/assert_regex.bash new file mode 100644 index 000000000..7bc906a2e --- /dev/null +++ b/node_modules/bats-assert/src/assert_regex.bash @@ -0,0 +1,54 @@ +# `assert_regex` +# +# This function is similar to `assert_equal` but uses pattern matching instead +# of equality, by wrapping `[[ value =~ pattern ]]`. +# +# Fail if the value (first parameter) does not match the pattern (second +# parameter). +# +# ```bash +# @test 'assert_regex()' { +# assert_regex 'what' 'x$' +# } +# ``` +# +# On failure, the value and the pattern are displayed. +# +# ``` +# -- values does not match regular expression -- +# value : what +# pattern : x$ +# -- +# ``` +# +# If the value is longer than one line then it is displayed in *multi-line* +# format. +# +# An error is displayed if the specified extended regular expression is invalid. +# +# For description of the matching behavior, refer to the documentation of the +# `=~` operator in the +# [Bash manual]: https://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html. +# Note that the `BASH_REMATCH` array is available immediately after the +# assertion succeeds but is fragile, i.e. prone to being overwritten as a side +# effect of other actions. +assert_regex() { + local -r value="${1}" + local -r pattern="${2}" + + if ! __check_is_valid_regex "$pattern" assert_regex; then + return 1 + elif ! [[ "${value}" =~ ${pattern} ]]; then + if shopt -p nocasematch &>/dev/null; then + local case_sensitive=insensitive + else + local case_sensitive=sensitive + fi + batslib_print_kv_single_or_multi 8 \ + 'value' "${value}" \ + 'pattern' "${pattern}" \ + 'case' "${case_sensitive}" \ + | batslib_decorate 'value does not match regular expression' \ + | fail + fi +} diff --git a/node_modules/bats-assert/src/assert_success.bash b/node_modules/bats-assert/src/assert_success.bash new file mode 100644 index 000000000..e3f074d23 --- /dev/null +++ b/node_modules/bats-assert/src/assert_success.bash @@ -0,0 +1,47 @@ +# assert_success +# ============== +# +# Summary: Fail if `$status` is not 0. +# +# Usage: assert_success +# +# IO: +# STDERR - `$status` and `$output`, on failure +# Globals: +# status +# output +# Returns: +# 0 - if `$status' is 0 +# 1 - otherwise +# +# ```bash +# @test 'assert_success() status only' { +# run bash -c "echo 'Error!'; exit 1" +# assert_success +# } +# ``` +# +# On failure, `$status` and `$output` are displayed. +# +# ``` +# -- command failed -- +# status : 1 +# output : Error! +# -- +# ``` +assert_success() { + : "${output?}" + : "${status?}" + + if (( status != 0 )); then + { local -ir width=6 + batslib_print_kv_single "$width" 'status' "$status" + batslib_print_kv_single_or_multi "$width" 'output' "$output" + if [[ -n "${stderr-}" ]]; then + batslib_print_kv_single_or_multi "$width" 'stderr' "$stderr" + fi + } \ + | batslib_decorate 'command failed' \ + | fail + fi +} diff --git a/node_modules/bats-assert/src/refute.bash b/node_modules/bats-assert/src/refute.bash new file mode 100644 index 000000000..e7c47da82 --- /dev/null +++ b/node_modules/bats-assert/src/refute.bash @@ -0,0 +1,42 @@ +# refute +# ====== +# +# Summary: Fail if the given expression evaluates to true. +# +# Usage: refute +# +# Options: +# The expression to evaluate for falsiness. +# *__Note:__ The expression must be a simple command. +# [Compound commands](https://www.gnu.org/software/bash/manual/bash.html#Compound-Commands), +# such as `[[`, can be used only when executed with `bash -c`.* +# +# IO: +# STDERR - the successful expression, on failure +# Globals: +# none +# Returns: +# 0 - if expression evaluates to false +# 1 - otherwise +# +# ```bash +# @test 'refute()' { +# rm -f '/var/log/test.log' +# refute [ -e '/var/log/test.log' ] +# } +# ``` +# +# On failure, the successful expression is displayed. +# +# ``` +# -- assertion succeeded, but it was expected to fail -- +# expression : [ -e /var/log/test.log ] +# -- +# ``` +refute() { + if "$@"; then + batslib_print_kv_single 10 'expression' "$*" \ + | batslib_decorate 'assertion succeeded, but it was expected to fail' \ + | fail + fi +} diff --git a/node_modules/bats-assert/src/refute_line.bash b/node_modules/bats-assert/src/refute_line.bash new file mode 100644 index 000000000..06628687b --- /dev/null +++ b/node_modules/bats-assert/src/refute_line.bash @@ -0,0 +1,341 @@ +# refute_line +# =========== +# +# Summary: Fail if the unexpected line is found in the output (default) or at a specific line number. +# +# Usage: refute_line [-n index] [-p | -e] [--] +# +# Options: +# -n, --index Match the th line +# -p, --partial Match if `unexpected` is a substring of `$output` or line +# -e, --regexp Treat `unexpected` as an extended regular expression +# The unexpected line string, substring, or regular expression. +# +# IO: +# STDERR - details, on failure +# error message, on error +# Globals: +# output +# lines +# Returns: +# 0 - if match not found +# 1 - otherwise +# +# Similarly to `refute_output`, this function verifies that a command or function does not produce the unexpected output. +# (It is the logical complement of `assert_line`.) +# It checks that the unexpected line does not appear in the output (default) or at a specific line number. +# Matching can be literal (default), partial or regular expression. +# +# ## Looking for a line in the output +# +# By default, the entire output is searched for the unexpected line. +# The assertion fails if the unexpected line is found in `${lines[@]}`. +# +# ```bash +# @test 'refute_line() looking for line' { +# run echo $'have-0\nwant\nhave-2' +# refute_line 'want' +# } +# ``` +# +# On failure, the unexpected line, the index of its first match and the output with the matching line highlighted are displayed. +# +# ``` +# -- line should not be in output -- +# line : want +# index : 1 +# output (3 lines): +# have-0 +# > want +# have-2 +# -- +# ``` +# +# ## Matching a specific line +# +# When the `--index ` option is used (`-n ` for short), the unexpected line is matched only against the line identified by the given index. +# The assertion fails if the unexpected line equals `${lines[]}`. +# +# ```bash +# @test 'refute_line() specific line' { +# run echo $'have-0\nwant-1\nhave-2' +# refute_line --index 1 'want-1' +# } +# ``` +# +# On failure, the index and the unexpected line are displayed. +# +# ``` +# -- line should differ -- +# index : 1 +# line : want-1 +# -- +# ``` +# +# ## Partial matching +# +# Partial matching can be enabled with the `--partial` option (`-p` for short). +# When used, a match fails if the unexpected *substring* is found in the matched line. +# +# ```bash +# @test 'refute_line() partial matching' { +# run echo $'have 1\nwant 2\nhave 3' +# refute_line --partial 'want' +# } +# ``` +# +# On failure, in addition to the details of literal matching, the substring is also displayed. +# When used with `--index ` the substring replaces the unexpected line. +# +# ``` +# -- no line should contain substring -- +# substring : want +# index : 1 +# output (3 lines): +# have 1 +# > want 2 +# have 3 +# -- +# ``` +# +# ## Regular expression matching +# +# Regular expression matching can be enabled with the `--regexp` option (`-e` for short). +# When used, a match fails if the *extended regular expression* matches the line being tested. +# +# *__Note__: +# As expected, the anchors `^` and `$` bind to the beginning and the end (respectively) of the matched line.* +# +# ```bash +# @test 'refute_line() regular expression matching' { +# run echo $'Foobar v0.1.0\nRelease date: 2015-11-29' +# refute_line --index 0 --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' +# } +# ``` +# +# On failure, in addition to the details of literal matching, the regular expression is also displayed. +# When used with `--index ` the regular expression replaces the unexpected line. +# +# ``` +# -- regular expression should not match line -- +# index : 0 +# regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ +# line : Foobar v0.1.0 +# -- +# ``` +# FIXME(ztombol): Display `${lines[@]}' instead of `$output'! +refute_line() { + __refute_stream_line "$@" +} + +# refute_stderr_line +# ================== +# +# Summary: Fail if the unexpected line is found in the stderr (default) or at a specific line number. +# +# Usage: refute_stderr_line [-n index] [-p | -e] [--] +# +# Options: +# -n, --index Match the th line +# -p, --partial Match if `unexpected` is a substring of `$stderr` or line +# -e, --regexp Treat `unexpected` as an extended regular expression +# The unexpected line string, substring, or regular expression. +# +# IO: +# STDERR - details, on failure +# error message, on error +# Globals: +# stderr +# stderr_lines +# Returns: +# 0 - if match not found +# 1 - otherwise +# +# Similarly to `refute_stderr`, this function verifies that a command or function does not produce the unexpected stderr. +# (It is the logical complement of `assert_stderr_line`.) +# It checks that the unexpected line does not appear in the stderr (default) or at a specific line number. +# Matching can be literal (default), partial or regular expression. +# +refute_stderr_line() { + __refute_stream_line "$@" +} + +# __check_is_vvalid_regex +# ======================= +# +# Summary: checks if the regex in unexpected is valid, also prints an error message if not. +# IO: +# STDERR - details, on error +# Globals: +# caller - readonly +# Returns: +# 0 - if regex is valid +# 1 - otherwise +__check_is_valid_regex() { # + local -r regex="$1" caller="$2" + local error + error=$([[ '' =~ $regex ]] 2>&1) # capture the detailed error message on Bash >=5.3 + if [[ $? == 2 ]]; then + local err_msg="Invalid extended regular expression: \`$regex'" + if [[ $error =~ (invalid regular expression .*) ]]; then + err_msg="${BASH_REMATCH[1]}" + fi + echo "$err_msg" \ + | batslib_decorate "ERROR: ${caller}" \ + | fail + fi +} + +__refute_stream_line() { + local -r caller=${FUNCNAME[1]} + local -i is_match_line=0 + local -i is_mode_partial=0 + local -i is_mode_regexp=0 + + if [[ "${caller}" == "refute_line" ]]; then + : "${lines?}" + local -ar stream_lines=("${lines[@]}") + local -r stream_type=output + elif [[ "${caller}" == "refute_stderr_line" ]]; then + : "${stderr_lines?}" + local -ar stream_lines=("${stderr_lines[@]}") + local -r stream_type=stderr + else + # Unknown caller + echo "Unexpected call to \`${FUNCNAME[0]}\` +Did you mean to call \`refute_line\` or \`refute_stderr_line\`?" | + batslib_decorate "ERROR: ${FUNCNAME[0]}" | + fail + return $? + fi + + # Handle options. + while (( $# > 0 )); do + case "$1" in + -n|--index) + if (( $# < 2 )) || ! [[ $2 =~ ^-?([0-9]|[1-9][0-9]+)$ ]]; then + echo "\`--index' requires an integer argument: \`$2'" \ + | batslib_decorate "ERROR: ${caller}" \ + | fail + return $? + fi + is_match_line=1 + local -ri idx="$2" + shift 2 + ;; + -p|--partial) is_mode_partial=1; shift ;; + -e|--regexp) is_mode_regexp=1; shift ;; + --) shift; break ;; + *) break ;; + esac + done + + if (( is_mode_partial )) && (( is_mode_regexp )); then + echo "\`--partial' and \`--regexp' are mutually exclusive" \ + | batslib_decorate "ERROR: ${caller}" \ + | fail + return $? + fi + + # Arguments. + local -r unexpected="$1" + + if (( is_mode_regexp == 1 )); then + __check_is_valid_regex "$unexpected" "$caller" || return $? + fi + + # Matching. + if (( is_match_line )); then + # Specific line. + if (( is_mode_regexp )); then + if [[ ${stream_lines[$idx]} =~ $unexpected ]]; then + batslib_print_kv_single 6 \ + 'index' "$idx" \ + 'regexp' "$unexpected" \ + 'line' "${stream_lines[$idx]}" \ + | batslib_decorate 'regular expression should not match line' \ + | fail + fi + elif (( is_mode_partial )); then + if [[ ${stream_lines[$idx]} == *"$unexpected"* ]]; then + batslib_print_kv_single 9 \ + 'index' "$idx" \ + 'substring' "$unexpected" \ + 'line' "${stream_lines[$idx]}" \ + | batslib_decorate 'line should not contain substring' \ + | fail + fi + else + if [[ ${stream_lines[$idx]} == "$unexpected" ]]; then + batslib_print_kv_single 5 \ + 'index' "$idx" \ + 'line' "${stream_lines[$idx]}" \ + | batslib_decorate 'line should differ' \ + | fail + fi + fi + else + # Line contained in output/error stream. + if (( is_mode_regexp )); then + local -i idx + for (( idx = 0; idx < ${#stream_lines[@]}; ++idx )); do + if [[ ${stream_lines[$idx]} =~ $unexpected ]]; then + { local -ar single=( 'regexp' "$unexpected" 'index' "$idx" ) + local -a may_be_multi=( "${stream_type}" "${!stream_type}" ) + local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )" + batslib_print_kv_single "$width" "${single[@]}" + if batslib_is_single_line "${may_be_multi[1]}"; then + batslib_print_kv_single "$width" "${may_be_multi[@]}" + else + may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" | batslib_prefix | batslib_mark '>' "$idx" )" + batslib_print_kv_multi "${may_be_multi[@]}" + fi + } \ + | batslib_decorate 'no line should match the regular expression' \ + | fail + return $? + fi + done + elif (( is_mode_partial )); then + local -i idx + for (( idx = 0; idx < ${#stream_lines[@]}; ++idx )); do + if [[ ${stream_lines[$idx]} == *"$unexpected"* ]]; then + { local -ar single=( 'substring' "$unexpected" 'index' "$idx" ) + local -a may_be_multi=( "${stream_type}" "${!stream_type}" ) + local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )" + batslib_print_kv_single "$width" "${single[@]}" + if batslib_is_single_line "${may_be_multi[1]}"; then + batslib_print_kv_single "$width" "${may_be_multi[@]}" + else + may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" | batslib_prefix | batslib_mark '>' "$idx" )" + batslib_print_kv_multi "${may_be_multi[@]}" + fi + } \ + | batslib_decorate 'no line should contain substring' \ + | fail + return $? + fi + done + else + local -i idx + for (( idx = 0; idx < ${#stream_lines[@]}; ++idx )); do + if [[ ${stream_lines[$idx]} == "$unexpected" ]]; then + { local -ar single=( 'line' "$unexpected" 'index' "$idx" ) + local -a may_be_multi=( "${stream_type}" "${!stream_type}" ) + local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )" + batslib_print_kv_single "$width" "${single[@]}" + if batslib_is_single_line "${may_be_multi[1]}"; then + batslib_print_kv_single "$width" "${may_be_multi[@]}" + else + may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" | batslib_prefix | batslib_mark '>' "$idx" )" + batslib_print_kv_multi "${may_be_multi[@]}" + fi + } \ + | batslib_decorate "line should not be in ${stream_type}" \ + | fail + return $? + fi + done + fi + fi +} diff --git a/node_modules/bats-assert/src/refute_output.bash b/node_modules/bats-assert/src/refute_output.bash new file mode 100644 index 000000000..83d859ae7 --- /dev/null +++ b/node_modules/bats-assert/src/refute_output.bash @@ -0,0 +1,243 @@ +# refute_output +# ============= +# +# Summary: Fail if `$output' matches the unexpected output. +# +# Usage: refute_output [-p | -e] [- | [--] ] +# +# Options: +# -p, --partial Match if `unexpected` is a substring of `$output` +# -e, --regexp Treat `unexpected` as an extended regular expression +# -, --stdin Read `unexpected` value from STDIN +# The unexpected value, substring, or regular expression +# +# IO: +# STDIN - [=$1] unexpected output +# STDERR - details, on failure +# error message, on error +# Globals: +# output +# Returns: +# 0 - if output matches the unexpected value/partial/regexp +# 1 - otherwise +# +# This function verifies that a command or function does not produce the unexpected output. +# (It is the logical complement of `assert_output`.) +# Output matching can be literal (the default), partial or by regular expression. +# The unexpected output can be specified either by positional argument or read from STDIN by passing the `-`/`--stdin` flag. +# +# ## Literal matching +# +# By default, literal matching is performed. +# The assertion fails if `$output` equals the unexpected output. +# +# ```bash +# @test 'refute_output()' { +# run echo 'want' +# refute_output 'want' +# } +# +# @test 'refute_output() with pipe' { +# run echo 'hello' +# echo 'world' | refute_output - +# } +# +# @test 'refute_output() with herestring' { +# run echo 'hello' +# refute_output - <<< world +# } +# ``` +# +# On failure, the output is displayed. +# +# ``` +# -- output equals, but it was expected to differ -- +# output : want +# -- +# ``` +# +# ## Existence +# +# To assert that there is no output at all, omit the matching argument. +# +# ```bash +# @test 'refute_output()' { +# run foo --silent +# refute_output +# } +# ``` +# +# On failure, an error message is displayed. +# +# ``` +# -- unexpected output -- +# expected no output, but output was non-empty +# -- +# ``` +# +# ## Partial matching +# +# Partial matching can be enabled with the `--partial` option (`-p` for short). +# When used, the assertion fails if the unexpected _substring_ is found in `$output`. +# +# ```bash +# @test 'refute_output() partial matching' { +# run echo 'ERROR: no such file or directory' +# refute_output --partial 'ERROR' +# } +# ``` +# +# On failure, the substring and the output are displayed. +# +# ``` +# -- output should not contain substring -- +# substring : ERROR +# output : ERROR: no such file or directory +# -- +# ``` +# +# ## Regular expression matching +# +# Regular expression matching can be enabled with the `--regexp` option (`-e` for short). +# When used, the assertion fails if the *extended regular expression* matches `$output`. +# +# *__Note__: +# The anchors `^` and `$` bind to the beginning and the end (respectively) of the entire output; +# not individual lines.* +# +# ```bash +# @test 'refute_output() regular expression matching' { +# run echo 'Foobar v0.1.0' +# refute_output --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' +# } +# ``` +# +# On failure, the regular expression and the output are displayed. +# +# ``` +# -- regular expression should not match output -- +# regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ +# output : Foobar v0.1.0 +# -- +# ``` +refute_output() { + __refute_stream "$@" +} + +# refute_stderr +# ============= +# +# Summary: Fail if `$stderr' matches the unexpected output. +# +# Usage: refute_stderr [-p | -e] [- | [--] ] +# +# Options: +# -p, --partial Match if `unexpected` is a substring of `$stderr` +# -e, --regexp Treat `unexpected` as an extended regular expression +# -, --stdin Read `unexpected` value from STDIN +# The unexpected value, substring, or regular expression +# +# IO: +# STDIN - [=$1] unexpected stderr +# STDERR - details, on failure +# error message, on error +# Globals: +# stderr +# Returns: +# 0 - if stderr matches the unexpected value/partial/regexp +# 1 - otherwise +# +# Similar to `refute_output`, this function verifies that a command or function does not produce the unexpected stderr. +# (It is the logical complement of `assert_stderr`.) +# The stderr matching can be literal (the default), partial or by regular expression. +# The unexpected stderr can be specified either by positional argument or read from STDIN by passing the `-`/`--stdin` flag. +# +refute_stderr() { + __refute_stream "$@" +} + +__refute_stream() { + local -r caller=${FUNCNAME[1]} + local -r stream_type=${caller/refute_/} + local -i is_mode_partial=0 + local -i is_mode_regexp=0 + local -i is_mode_empty=0 + local -i use_stdin=0 + + if [[ ${stream_type} == "output" ]]; then + : "${output?}" + elif [[ ${stream_type} == "stderr" ]]; then + : "${stderr?}" + else + # Not reachable: should be either output or stderr + : + fi + local -r stream="${!stream_type}" + + # Handle options. + if (( $# == 0 )); then + is_mode_empty=1 + fi + + while (( $# > 0 )); do + case "$1" in + -p|--partial) is_mode_partial=1; shift ;; + -e|--regexp) is_mode_regexp=1; shift ;; + -|--stdin) use_stdin=1; shift ;; + --) shift; break ;; + *) break ;; + esac + done + + if (( is_mode_partial )) && (( is_mode_regexp )); then + echo "\`--partial' and \`--regexp' are mutually exclusive" \ + | batslib_decorate "ERROR: ${caller}" \ + | fail + return $? + fi + + # Arguments. + local unexpected + if (( use_stdin )); then + unexpected="$(cat -)" + else + unexpected="${1-}" + fi + + if (( is_mode_regexp == 1 )); then + __check_is_valid_regex "$unexpected" "$caller" || return 1 + fi + + # Matching. + if (( is_mode_empty )); then + if [ -n "${stream}" ]; then + batslib_print_kv_single_or_multi 6 \ + "${stream_type}" "${stream}" \ + | batslib_decorate "${stream_type} non-empty, but expected no ${stream_type}" \ + | fail + fi + elif (( is_mode_regexp )); then + if [[ ${stream} =~ $unexpected ]]; then + batslib_print_kv_single_or_multi 6 \ + 'regexp' "$unexpected" \ + "${stream_type}" "${stream}" \ + | batslib_decorate "regular expression should not match ${stream_type}" \ + | fail + fi + elif (( is_mode_partial )); then + if [[ ${stream} == *"$unexpected"* ]]; then + batslib_print_kv_single_or_multi 9 \ + 'substring' "$unexpected" \ + "${stream_type}" "${stream}" \ + | batslib_decorate "${stream_type} should not contain substring" \ + | fail + fi + else + if [[ ${stream} == "$unexpected" ]]; then + batslib_print_kv_single_or_multi 6 \ + "${stream_type}" "${stream}" \ + | batslib_decorate "${stream_type} equals, but it was expected to differ" \ + | fail + fi + fi +} diff --git a/node_modules/bats-assert/src/refute_regex.bash b/node_modules/bats-assert/src/refute_regex.bash new file mode 100644 index 000000000..f998cc416 --- /dev/null +++ b/node_modules/bats-assert/src/refute_regex.bash @@ -0,0 +1,64 @@ +# `refute_regex` +# +# This function is similar to `refute_equal` but uses pattern matching instead +# of equality, by wrapping `! [[ value =~ pattern ]]`. +# +# Fail if the value (first parameter) matches the pattern (second parameter). +# +# ```bash +# @test 'refute_regex()' { +# refute_regex 'WhatsApp' 'Threema' +# } +# ``` +# +# On failure, the value, the pattern and the match are displayed. +# +# ``` +# @test 'refute_regex()' { +# refute_regex 'WhatsApp' 'What.' +# } +# +# -- value matches regular expression -- +# value : WhatsApp +# pattern : What. +# match : Whats +# case : sensitive +# -- +# ``` +# +# If the value or pattern is longer than one line then it is displayed in +# *multi-line* format. +# +# An error is displayed if the specified extended regular expression is invalid. +# +# For description of the matching behavior, refer to the documentation of the +# `=~` operator in the +# [Bash manual]: https://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html. +# +# Note that the `BASH_REMATCH` array is available immediately after the +# assertion fails but is fragile, i.e. prone to being overwritten as a side +# effect of other actions like calling `run`. Thus, it's good practice to avoid +# using `BASH_REMATCH` in conjunction with `refute_regex()`. The valuable +# information the array contains is the matching part of the value which is +# printed in the failing test log, as mentioned above. +refute_regex() { + local -r value="${1}" + local -r pattern="${2}" + + if ! __check_is_valid_regex "${pattern}" "${FUNCNAME[0]}"; then + return 1 + elif [[ "${value}" =~ ${pattern} ]]; then + if shopt -p nocasematch &>/dev/null; then + local case_sensitive=insensitive + else + local case_sensitive=sensitive + fi + batslib_print_kv_single_or_multi 8 \ + 'value' "${value}" \ + 'pattern' "${pattern}" \ + 'match' "${BASH_REMATCH[0]}" \ + 'case' "${case_sensitive}" \ + | batslib_decorate 'value matches regular expression' \ + | fail + fi +} diff --git a/node_modules/bats-support/CHANGELOG.md b/node_modules/bats-support/CHANGELOG.md new file mode 100644 index 000000000..324d247a7 --- /dev/null +++ b/node_modules/bats-support/CHANGELOG.md @@ -0,0 +1,46 @@ +# Change Log + +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + + +## [0.3.0] - 2016-11-29 + +### Added + +- Restricting invocation to specific locations with + `batslib_is_caller()` + + +## [0.2.0] - 2016-03-22 + +### Added + +- `npm` support +- Reporting arbitrary failures with `fail()` (moved from `bats-assert`) + +### Changed + +- Library renamed to `bats-support` + + +## 0.1.0 - 2016-02-16 + +### Added + +- Two-column key-value formatting with `batslib_print_kv_single()` +- Multi-line key-value formatting with `batslib_print_kv_multi()` +- Mixed formatting with `batslib_print_kv_single_or_multi()` +- Header and footer decoration with `batslib_decorate()` +- Prefixing lines with `batslib_prefix()` +- Marking lines with `batslib_mark()` +- Common output function `batslib_err()` +- Line counting with `batslib_count_lines()` +- Checking whether a text is one line long with + `batslib_is_single_line()` +- Determining key width for two-column and mixed formatting with + `batslib_get_max_single_line_key_width()` + + +[0.3.0]: https://github.com/ztombol/bats-support/compare/v0.2.0...v0.3.0 +[0.2.0]: https://github.com/ztombol/bats-support/compare/v0.1.0...v0.2.0 diff --git a/node_modules/bats-support/LICENSE b/node_modules/bats-support/LICENSE new file mode 100644 index 000000000..670154e35 --- /dev/null +++ b/node_modules/bats-support/LICENSE @@ -0,0 +1,116 @@ +CC0 1.0 Universal + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator and +subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for the +purpose of contributing to a commons of creative, cultural and scientific +works ("Commons") that the public can reliably and without fear of later +claims of infringement build upon, modify, incorporate in other works, reuse +and redistribute as freely as possible in any form whatsoever and for any +purposes, including without limitation commercial purposes. These owners may +contribute to the Commons to promote the ideal of a free culture and the +further production of creative, cultural and scientific works, or to gain +reputation or greater distribution for their Work in part through the use and +efforts of others. + +For these and/or other purposes and motivations, and without any expectation +of additional consideration or compensation, the person associating CC0 with a +Work (the "Affirmer"), to the extent that he or she is an owner of Copyright +and Related Rights in the Work, voluntarily elects to apply CC0 to the Work +and publicly distribute the Work under its terms, with knowledge of his or her +Copyright and Related Rights in the Work and the meaning and intended legal +effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not limited +to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, communicate, + and translate a Work; + + ii. moral rights retained by the original author(s) and/or performer(s); + + iii. publicity and privacy rights pertaining to a person's image or likeness + depicted in a Work; + + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + + v. rights protecting the extraction, dissemination, use and reuse of data in + a Work; + + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation thereof, + including any amended or successor version of such directive); and + + vii. other similar, equivalent or corresponding rights throughout the world + based on applicable law or treaty, and any national implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention of, +applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and +unconditionally waives, abandons, and surrenders all of Affirmer's Copyright +and Related Rights and associated claims and causes of action, whether now +known or unknown (including existing as well as future claims and causes of +action), in the Work (i) in all territories worldwide, (ii) for the maximum +duration provided by applicable law or treaty (including future time +extensions), (iii) in any current or future medium and for any number of +copies, and (iv) for any purpose whatsoever, including without limitation +commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes +the Waiver for the benefit of each member of the public at large and to the +detriment of Affirmer's heirs and successors, fully intending that such Waiver +shall not be subject to revocation, rescission, cancellation, termination, or +any other legal or equitable action to disrupt the quiet enjoyment of the Work +by the public as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason be +judged legally invalid or ineffective under applicable law, then the Waiver +shall be preserved to the maximum extent permitted taking into account +Affirmer's express Statement of Purpose. In addition, to the extent the Waiver +is so judged Affirmer hereby grants to each affected person a royalty-free, +non transferable, non sublicensable, non exclusive, irrevocable and +unconditional license to exercise Affirmer's Copyright and Related Rights in +the Work (i) in all territories worldwide, (ii) for the maximum duration +provided by applicable law or treaty (including future time extensions), (iii) +in any current or future medium and for any number of copies, and (iv) for any +purpose whatsoever, including without limitation commercial, advertising or +promotional purposes (the "License"). The License shall be deemed effective as +of the date CC0 was applied by Affirmer to the Work. Should any part of the +License for any reason be judged legally invalid or ineffective under +applicable law, such partial invalidity or ineffectiveness shall not +invalidate the remainder of the License, and in such case Affirmer hereby +affirms that he or she will not (i) exercise any of his or her remaining +Copyright and Related Rights in the Work or (ii) assert any associated claims +and causes of action with respect to the Work, in either case contrary to +Affirmer's express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + + b. Affirmer offers the Work as-is and makes no representations or warranties + of any kind concerning the Work, express, implied, statutory or otherwise, + including without limitation warranties of title, merchantability, fitness + for a particular purpose, non infringement, or the absence of latent or + other defects, accuracy, or the present or absence of errors, whether or not + discoverable, all to the greatest extent permissible under applicable law. + + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without limitation + any person's Copyright and Related Rights in the Work. Further, Affirmer + disclaims responsibility for obtaining any necessary consents, permissions + or other rights required for any use of the Work. + + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to this + CC0 or use of the Work. + +For more information, please see + diff --git a/node_modules/bats-support/README.md b/node_modules/bats-support/README.md new file mode 100644 index 000000000..71c02ba9c --- /dev/null +++ b/node_modules/bats-support/README.md @@ -0,0 +1,189 @@ +*__Important:__ `bats-core` has been renamed to `bats-support`. GitHub +automatically redirects all references, e.g. submodules and clones will +continue to work, but you are encouraged to [update][github-rename] +them. Version numbering continues where `bats-core` left off.* + +[github-rename]: https://help.github.com/articles/renaming-a-repository/ + +- - - - - + +# bats-support + +[![GitHub license](https://img.shields.io/badge/license-CC0-blue.svg)](https://raw.githubusercontent.com/ztombol/bats-support/master/LICENSE) +[![GitHub release](https://img.shields.io/github/release/ztombol/bats-support.svg)](https://github.com/ztombol/bats-support/releases/latest) +[![Build Status](https://travis-ci.org/ztombol/bats-support.svg?branch=master)](https://travis-ci.org/ztombol/bats-support) + +`bats-support` is a supporting library providing common functions to +test helper libraries written for [Bats][bats]. + +Features: +- [error reporting](#error-reporting) +- [output formatting](#output-formatting) +- [language tools](#language-and-execution) + +See the [shared documentation][bats-docs] to learn how to install and +load this library. + +If you want to use this library in your own helpers or just want to +learn about its internals see the developer documentation in the [source +files](src). + + +## Error reporting + +### `fail` + +Display an error message and fail. This function provides a convenient +way to report failure in arbitrary situations. You can use it to +implement your own helpers when the ones available do not meet your +needs. Other functions use it internally as well. + +```bash +@test 'fail()' { + fail 'this test always fails' +} +``` + +The message can also be specified on the standard input. + +```bash +@test 'fail() with pipe' { + echo 'this test always fails' | fail +} +``` + +This function always fails and simply outputs the given message. + +``` +this test always fails +``` + + +## Output formatting + +Many test helpers need to produce human readable output. This library +provides a simple way to format simple messages and key value pairs, and +display them on the standard error. + + +### Simple message + +Simple messages without structure, e.g. one-line error messages, are +simply wrapped in a header and a footer to help them stand out. + +``` +-- ERROR: assert_output -- +`--partial' and `--regexp' are mutually exclusive +-- +``` + + +### Key-Value pairs + +Some helpers, e.g. [assertions][bats-assert], structure output as +key-value pairs. This library provides two ways to format them. + +When the value is one line long, a pair can be displayed in a columnar +fashion called ***two-column*** format. + +``` +-- output differs -- +expected : want +actual : have +-- +``` + +When the value is longer than one line, the key and value must be +displayed on separate lines. First, the key is displayed along with the +number of lines in the value. Then, the value, indented by two spaces +for added readability, starting on the next line. This is called +***multi-line*** format. + +``` +-- command failed -- +status : 1 +output (2 lines): + Error! Something went terribly wrong! + Our engineers are panicing... \`>`;/ +-- +``` + +Sometimes, for clarity, it is a good idea to display related values also +in this format, even if they are just one line long. + +``` +-- output differs -- +expected (1 lines): + want +actual (3 lines): + have 1 + have 2 + have 3 +-- +``` + +## Language and Execution + +### Restricting invocation to specific locations + +Sometimes a helper may work properly only when called from a certain +location. Because it depends on variables to be set or some other side +effect. + +A good example is cleaning up temporary files only if the test has +succeeded. The outcome of a test is only available in `teardown`. Thus, +to avoid programming mistakes, it makes sense to restrict such a +clean-up helper to that function. + +`batslib_is_caller` checks the call stack and returns `0` if the caller +was invoked from a given function, and `1` otherwise. This function +becomes really useful with the `--indirect` option, which allows calls +through intermediate functions, e.g. the calling function may be called +from a function that was called from the given function. + +Staying with the example above, the following code snippet implements a +helper that is restricted to `teardown` or any function called +indirectly from it. + +```shell +clean_up() { + # Check caller. + if batslib_is_caller --indirect 'teardown'; then + echo "Must be called from \`teardown'" \ + | batslib_decorate 'ERROR: clean_up' \ + | fail + return $? + fi + + # Body goes here... +} +``` + +In some cases a helper may be called from multiple locations. For +example, a logging function that uses the test name, description or +number, information only available in `setup`, `@test` or `teardown`, to +distinguish entries. The following snippet implements this restriction. + +```shell +log_test() { + # Check caller. + if ! ( batslib_is_caller --indirect 'setup' \ + || batslib_is_caller --indirect "$BATS_TEST_NAME" \ + || batslib_is_caller --indirect 'teardown' ) + then + echo "Must be called from \`setup', \`@test' or \`teardown'" \ + | batslib_decorate 'ERROR: log_test' \ + | fail + return $? + fi + + # Body goes here... +} +``` + + + + +[bats]: https://github.com/sstephenson/bats +[bats-docs]: https://github.com/ztombol/bats-docs +[bats-assert]: https://github.com/ztombol/bats-assert diff --git a/node_modules/bats-support/load.bash b/node_modules/bats-support/load.bash new file mode 100644 index 000000000..0727aebae --- /dev/null +++ b/node_modules/bats-support/load.bash @@ -0,0 +1,3 @@ +source "$(dirname "${BASH_SOURCE[0]}")/src/output.bash" +source "$(dirname "${BASH_SOURCE[0]}")/src/error.bash" +source "$(dirname "${BASH_SOURCE[0]}")/src/lang.bash" diff --git a/node_modules/bats-support/package.json b/node_modules/bats-support/package.json new file mode 100644 index 000000000..501568770 --- /dev/null +++ b/node_modules/bats-support/package.json @@ -0,0 +1,30 @@ +{ + "name": "bats-support", + "version": "0.3.0", + "description": "Supporting library for Bats test helpers", + "homepage": "https://github.com/jasonkarns/bats-support", + "license": "CC0-1.0", + "author": "Zoltán Tömböl (https://github.com/ztombol)", + "contributors": [ + "Jason Karns (http://jason.karns.name)" + ], + "repository": "github:jasonkarns/bats-support", + "bugs": "https://github.com/jasonkarns/bats-support/issues", + "directories": { + "lib": "src", + "test": "test" + }, + "files": [ + "load.bash", + "src" + ], + "scripts": { + "test": "bats ${CI+-t} test" + }, + "devDependencies": { + "bats": "^1" + }, + "peerDependencies": { + "bats": "0.4 || ^1" + } +} diff --git a/node_modules/bats-support/src/error.bash b/node_modules/bats-support/src/error.bash new file mode 100644 index 000000000..e5d97912e --- /dev/null +++ b/node_modules/bats-support/src/error.bash @@ -0,0 +1,41 @@ +# +# bats-support - Supporting library for Bats test helpers +# +# Written in 2016 by Zoltan Tombol +# +# To the extent possible under law, the author(s) have dedicated all +# copyright and related and neighboring rights to this software to the +# public domain worldwide. This software is distributed without any +# warranty. +# +# You should have received a copy of the CC0 Public Domain Dedication +# along with this software. If not, see +# . +# + +# +# error.bash +# ---------- +# +# Functions implementing error reporting. Used by public helper +# functions or test suits directly. +# + +# Fail and display a message. When no parameters are specified, the +# message is read from the standard input. Other functions use this to +# report failure. +# +# Globals: +# none +# Arguments: +# $@ - [=STDIN] message +# Returns: +# 1 - always +# Inputs: +# STDIN - [=$@] message +# Outputs: +# STDERR - message +fail() { + (( $# == 0 )) && batslib_err || batslib_err "$@" + return 1 +} diff --git a/node_modules/bats-support/src/lang.bash b/node_modules/bats-support/src/lang.bash new file mode 100644 index 000000000..c57e299c6 --- /dev/null +++ b/node_modules/bats-support/src/lang.bash @@ -0,0 +1,73 @@ +# +# bats-util - Various auxiliary functions for Bats +# +# Written in 2016 by Zoltan Tombol +# +# To the extent possible under law, the author(s) have dedicated all +# copyright and related and neighboring rights to this software to the +# public domain worldwide. This software is distributed without any +# warranty. +# +# You should have received a copy of the CC0 Public Domain Dedication +# along with this software. If not, see +# . +# + +# +# lang.bash +# --------- +# +# Bash language and execution related functions. Used by public helper +# functions. +# + +# Check whether the calling function was called from a given function. +# +# By default, direct invocation is checked. The function succeeds if the +# calling function was called directly from the given function. In other +# words, if the given function is the next element on the call stack. +# +# When `--indirect' is specified, indirect invocation is checked. The +# function succeeds if the calling function was called from the given +# function with any number of intermediate calls. In other words, if the +# given function can be found somewhere on the call stack. +# +# Direct invocation is a form of indirect invocation with zero +# intermediate calls. +# +# Globals: +# FUNCNAME +# Options: +# -i, --indirect - check indirect invocation +# Arguments: +# $1 - calling function's name +# Returns: +# 0 - current function was called from the given function +# 1 - otherwise +batslib_is_caller() { + local -i is_mode_direct=1 + + # Handle options. + while (( $# > 0 )); do + case "$1" in + -i|--indirect) is_mode_direct=0; shift ;; + --) shift; break ;; + *) break ;; + esac + done + + # Arguments. + local -r func="$1" + + # Check call stack. + if (( is_mode_direct )); then + [[ $func == "${FUNCNAME[2]}" ]] && return 0 + else + local -i depth + for (( depth=2; depth<${#FUNCNAME[@]}; ++depth )); do + [[ $func == "${FUNCNAME[$depth]}" ]] && return 0 + done + fi + + return 1 +} diff --git a/node_modules/bats-support/src/output.bash b/node_modules/bats-support/src/output.bash new file mode 100644 index 000000000..c6cf6a6b8 --- /dev/null +++ b/node_modules/bats-support/src/output.bash @@ -0,0 +1,279 @@ +# +# bats-support - Supporting library for Bats test helpers +# +# Written in 2016 by Zoltan Tombol +# +# To the extent possible under law, the author(s) have dedicated all +# copyright and related and neighboring rights to this software to the +# public domain worldwide. This software is distributed without any +# warranty. +# +# You should have received a copy of the CC0 Public Domain Dedication +# along with this software. If not, see +# . +# + +# +# output.bash +# ----------- +# +# Private functions implementing output formatting. Used by public +# helper functions. +# + +# Print a message to the standard error. When no parameters are +# specified, the message is read from the standard input. +# +# Globals: +# none +# Arguments: +# $@ - [=STDIN] message +# Returns: +# none +# Inputs: +# STDIN - [=$@] message +# Outputs: +# STDERR - message +batslib_err() { + { if (( $# > 0 )); then + echo "$@" + else + cat - + fi + } >&2 +} + +# Count the number of lines in the given string. +# +# TODO(ztombol): Fix tests and remove this note after #93 is resolved! +# NOTE: Due to a bug in Bats, `batslib_count_lines "$output"' does not +# give the same result as `${#lines[@]}' when the output contains +# empty lines. +# See PR #93 (https://github.com/sstephenson/bats/pull/93). +# +# Globals: +# none +# Arguments: +# $1 - string +# Returns: +# none +# Outputs: +# STDOUT - number of lines +batslib_count_lines() { + local -i n_lines=0 + local line + while IFS='' read -r line || [[ -n $line ]]; do + (( ++n_lines )) + done < <(printf '%s' "$1") + echo "$n_lines" +} + +# Determine whether all strings are single-line. +# +# Globals: +# none +# Arguments: +# $@ - strings +# Returns: +# 0 - all strings are single-line +# 1 - otherwise +batslib_is_single_line() { + for string in "$@"; do + (( $(batslib_count_lines "$string") > 1 )) && return 1 + done + return 0 +} + +# Determine the length of the longest key that has a single-line value. +# +# This function is useful in determining the correct width of the key +# column in two-column format when some keys may have multi-line values +# and thus should be excluded. +# +# Globals: +# none +# Arguments: +# $odd - key +# $even - value of the previous key +# Returns: +# none +# Outputs: +# STDOUT - length of longest key +batslib_get_max_single_line_key_width() { + local -i max_len=-1 + while (( $# != 0 )); do + local -i key_len="${#1}" + batslib_is_single_line "$2" && (( key_len > max_len )) && max_len="$key_len" + shift 2 + done + echo "$max_len" +} + +# Print key-value pairs in two-column format. +# +# Keys are displayed in the first column, and their corresponding values +# in the second. To evenly line up values, the key column is fixed-width +# and its width is specified with the first parameter (possibly computed +# using `batslib_get_max_single_line_key_width'). +# +# Globals: +# none +# Arguments: +# $1 - width of key column +# $even - key +# $odd - value of the previous key +# Returns: +# none +# Outputs: +# STDOUT - formatted key-value pairs +batslib_print_kv_single() { + local -ir col_width="$1"; shift + while (( $# != 0 )); do + printf '%-*s : %s\n' "$col_width" "$1" "$2" + shift 2 + done +} + +# Print key-value pairs in multi-line format. +# +# The key is displayed first with the number of lines of its +# corresponding value in parenthesis. Next, starting on the next line, +# the value is displayed. For better readability, it is recommended to +# indent values using `batslib_prefix'. +# +# Globals: +# none +# Arguments: +# $odd - key +# $even - value of the previous key +# Returns: +# none +# Outputs: +# STDOUT - formatted key-value pairs +batslib_print_kv_multi() { + while (( $# != 0 )); do + printf '%s (%d lines):\n' "$1" "$( batslib_count_lines "$2" )" + printf '%s\n' "$2" + shift 2 + done +} + +# Print all key-value pairs in either two-column or multi-line format +# depending on whether all values are single-line. +# +# If all values are single-line, print all pairs in two-column format +# with the specified key column width (identical to using +# `batslib_print_kv_single'). +# +# Otherwise, print all pairs in multi-line format after indenting values +# with two spaces for readability (identical to using `batslib_prefix' +# and `batslib_print_kv_multi') +# +# Globals: +# none +# Arguments: +# $1 - width of key column (for two-column format) +# $even - key +# $odd - value of the previous key +# Returns: +# none +# Outputs: +# STDOUT - formatted key-value pairs +batslib_print_kv_single_or_multi() { + local -ir width="$1"; shift + local -a pairs=( "$@" ) + + local -a values=() + local -i i + for (( i=1; i < ${#pairs[@]}; i+=2 )); do + values+=( "${pairs[$i]}" ) + done + + if batslib_is_single_line "${values[@]}"; then + batslib_print_kv_single "$width" "${pairs[@]}" + else + local -i i + for (( i=1; i < ${#pairs[@]}; i+=2 )); do + pairs[$i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )" + done + batslib_print_kv_multi "${pairs[@]}" + fi +} + +# Prefix each line read from the standard input with the given string. +# +# Globals: +# none +# Arguments: +# $1 - [= ] prefix string +# Returns: +# none +# Inputs: +# STDIN - lines +# Outputs: +# STDOUT - prefixed lines +batslib_prefix() { + local -r prefix="${1:- }" + local line + while IFS='' read -r line || [[ -n $line ]]; do + printf '%s%s\n' "$prefix" "$line" + done +} + +# Mark select lines of the text read from the standard input by +# overwriting their beginning with the given string. +# +# Usually the input is indented by a few spaces using `batslib_prefix' +# first. +# +# Globals: +# none +# Arguments: +# $1 - marking string +# $@ - indices (zero-based) of lines to mark +# Returns: +# none +# Inputs: +# STDIN - lines +# Outputs: +# STDOUT - lines after marking +batslib_mark() { + local -r symbol="$1"; shift + # Sort line numbers. + set -- $( sort -nu <<< "$( printf '%d\n' "$@" )" ) + + local line + local -i idx=0 + while IFS='' read -r line || [[ -n $line ]]; do + if (( ${1:--1} == idx )); then + printf '%s\n' "${symbol}${line:${#symbol}}" + shift + else + printf '%s\n' "$line" + fi + (( ++idx )) + done +} + +# Enclose the input text in header and footer lines. +# +# The header contains the given string as title. The output is preceded +# and followed by an additional newline to make it stand out more. +# +# Globals: +# none +# Arguments: +# $1 - title +# Returns: +# none +# Inputs: +# STDIN - text +# Outputs: +# STDOUT - decorated text +batslib_decorate() { + echo + echo "-- $1 --" + cat - + echo '--' + echo +} From 4610c887b16d5eda89aec803cc36ab6dd8880580 Mon Sep 17 00:00:00 2001 From: donpetry-bot <281750570+donpetry-bot@users.noreply.github.com> Date: Thu, 23 Jul 2026 18:53:55 +0000 Subject: [PATCH 2/6] chore: dev-lead update (review-changes) [skip ci-relay] --- .../scripts/pr-auto-review/lib/ready-check.sh | 25 +++++-- .github/workflows/pr-auto-review-reusable.yml | 2 +- .../pr-auto-review/blocking-threads.bats | 65 +++++++++++++++++++ 3 files changed, 86 insertions(+), 6 deletions(-) diff --git a/.github/scripts/pr-auto-review/lib/ready-check.sh b/.github/scripts/pr-auto-review/lib/ready-check.sh index d3f83614a..9ac3999fa 100644 --- a/.github/scripts/pr-auto-review/lib/ready-check.sh +++ b/.github/scripts/pr-auto-review/lib/ready-check.sh @@ -96,9 +96,10 @@ pr_auto_review_checks_ready() { # pr_auto_review_blocking_thread_count # Reads a review-threads GraphQL response on stdin — the payload of -# `reviewThreads(first:100){nodes{isResolved isOutdated}}` under +# `reviewThreads(first:100){nodes{isResolved isOutdated comments(first:1){nodes{author{__typename}}}}}` under # .data.repository.pullRequest — and prints the count of threads that should -# BLOCK auto-dispatch: those that are unresolved AND not outdated. +# BLOCK auto-dispatch: those that are unresolved AND not outdated AND not +# posted exclusively by advisory bots. # # Why isOutdated (issue #806): dev-lead's fix-review cycle often addresses an # advisory finding in a follow-up commit but never marks the thread resolved, @@ -110,15 +111,29 @@ pr_auto_review_checks_ready() { # unresolved-but-outdated thread as non-blocking clears the stall without the # producer having to resolve the thread first. # +# Why advisory-bot exclusion (issue #892): threads whose comments are all +# from advisory bots (author.__typename == "Bot") represent automated +# nitpick feedback, not human review requests. When CI is green and the only +# unresolved threads are advisory-bot posts, the PR should still be eligible +# for dispatch — otherwise the gate stalls on a human to resolve bot threads +# that dev-lead's fix-review correctly returns no-changes for (empty machine +# findings). A thread is advisory-bot-only when comments.nodes is non-empty +# and every author in that set has __typename == "Bot". +# # Fail-safe: only an explicit isOutdated == true makes a thread non-blocking; # a null / absent isOutdated on an unresolved thread still blocks, so a thread -# whose staleness we cannot confirm is never silently dropped. A GraphQL error -# body (no data / null nodes) yields 0. +# whose staleness we cannot confirm is never silently dropped. Similarly, a +# thread with absent or empty comments (cannot confirm all-bot) still blocks. +# A GraphQL error body (no data / null nodes) yields 0. pr_auto_review_blocking_thread_count() { jq -r ' + def is_advisory_bot_thread: + (.comments?.nodes? // []) as $c + | ($c | length) > 0 and ([$c[] | .author?.__typename? == "Bot"] | all); + [ (.data.repository.pullRequest.reviewThreads.nodes[]? | - select((.isResolved == false) and (.isOutdated != true)))? + select((.isResolved == false) and (.isOutdated != true) and (is_advisory_bot_thread | not)))? ] | length ' } diff --git a/.github/workflows/pr-auto-review-reusable.yml b/.github/workflows/pr-auto-review-reusable.yml index 16bad0271..3271ad48b 100644 --- a/.github/workflows/pr-auto-review-reusable.yml +++ b/.github/workflows/pr-auto-review-reusable.yml @@ -211,7 +211,7 @@ jobs: # silently reporting 0 blocking threads and dispatching. The pure # function only has to tolerate a well-formed-but-empty payload. # shellcheck disable=SC2016 # $owner/$repo/$number are GraphQL variable refs, not shell vars - _GQL='query($owner:String!,$repo:String!,$number:Int!){repository(owner:$owner,name:$repo){pullRequest(number:$number){reviewThreads(first:100){nodes{isResolved isOutdated}}}}}' + _GQL='query($owner:String!,$repo:String!,$number:Int!){repository(owner:$owner,name:$repo){pullRequest(number:$number){reviewThreads(first:100){nodes{isResolved isOutdated comments(first:1){nodes{author{__typename}}}}}}}}' THREADS_JSON=$(gh api graphql \ -f "query=$_GQL" \ -f owner="${REPO%%/*}" \ diff --git a/test/workflows/pr-auto-review/blocking-threads.bats b/test/workflows/pr-auto-review/blocking-threads.bats index 4349fc09a..39ab6c23a 100644 --- a/test/workflows/pr-auto-review/blocking-threads.bats +++ b/test/workflows/pr-auto-review/blocking-threads.bats @@ -150,3 +150,68 @@ resp() { [ "$status" -eq 0 ] [ "$output" = "0" ] } + +# ── issue #892: advisory-bot-only threads are non-blocking ─────────────────── +# A thread whose comments are exclusively from bots (author.__typename == "Bot") +# is advisory feedback, not a human review request. It should not block +# dispatch — otherwise the gate stalls on a human to resolve bot threads that +# dev-lead fix-review correctly returns no-changes for (empty machine findings). + +@test "blocking count: unresolved thread with all-bot comments → 0 (advisory bot, non-blocking)" { + run pr_auto_review_blocking_thread_count <<<"$(resp '[{ + "isResolved":false,"isOutdated":false, + "comments":{"nodes":[{"author":{"__typename":"Bot"}}]} + }]')" + [ "$status" -eq 0 ] + [ "$output" = "0" ] +} + +@test "blocking count: unresolved thread with User comment → 1 (human thread, still blocks)" { + run pr_auto_review_blocking_thread_count <<<"$(resp '[{ + "isResolved":false,"isOutdated":false, + "comments":{"nodes":[{"author":{"__typename":"User"}}]} + }]')" + [ "$status" -eq 0 ] + [ "$output" = "1" ] +} + +@test "blocking count: absent comments field → 1 (fail-safe: cannot confirm bot-only, still blocks)" { + run pr_auto_review_blocking_thread_count <<<"$(resp '[{"isResolved":false,"isOutdated":false}]')" + [ "$status" -eq 0 ] + [ "$output" = "1" ] +} + +@test "blocking count: empty comments nodes → 1 (fail-safe: no authors to confirm bot-only)" { + run pr_auto_review_blocking_thread_count <<<"$(resp '[{ + "isResolved":false,"isOutdated":false, + "comments":{"nodes":[]} + }]')" + [ "$status" -eq 0 ] + [ "$output" = "1" ] +} + +@test "blocking count: mixed bot and human threads — only human thread blocks" { + run pr_auto_review_blocking_thread_count <<<"$(resp '[ + {"isResolved":false,"isOutdated":false,"comments":{"nodes":[{"author":{"__typename":"Bot"}}]}}, + {"isResolved":false,"isOutdated":false,"comments":{"nodes":[{"author":{"__typename":"User"}}]}}, + {"isResolved":false,"isOutdated":false,"comments":{"nodes":[{"author":{"__typename":"Bot"}}]}} + ]')" + [ "$status" -eq 0 ] + [ "$output" = "1" ] +} + +@test "blocking count: the #892 scenario — multiple advisory bot threads (gemini + codeant) → 0" { + # Scenario: CI green, CHANGES_REQUESTED from advisory bots (gemini-code-assist, + # codeant-ai), all 13 threads unresolved and not outdated. Without the fix, + # the gate counts 13 blocking threads and stalls dispatch even though every + # thread is advisory-bot feedback with no machine findings. + run pr_auto_review_blocking_thread_count <<<"$(resp '[ + {"isResolved":false,"isOutdated":false,"comments":{"nodes":[{"author":{"__typename":"Bot"}}]}}, + {"isResolved":false,"isOutdated":false,"comments":{"nodes":[{"author":{"__typename":"Bot"}}]}}, + {"isResolved":false,"isOutdated":false,"comments":{"nodes":[{"author":{"__typename":"Bot"}}]}}, + {"isResolved":false,"isOutdated":false,"comments":{"nodes":[{"author":{"__typename":"Bot"}}]}}, + {"isResolved":false,"isOutdated":false,"comments":{"nodes":[{"author":{"__typename":"Bot"}}]}} + ]')" + [ "$status" -eq 0 ] + [ "$output" = "0" ] +} From 0d108b3e4de15e2b5984351b5ded87cd6dd4df99 Mon Sep 17 00:00:00 2001 From: donpetry-bot <281750570+donpetry-bot@users.noreply.github.com> Date: Thu, 23 Jul 2026 19:00:19 +0000 Subject: [PATCH 3/6] chore: dev-lead update (review-changes) [skip ci-relay] --- .github/workflows/pr-auto-review-reusable.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-auto-review-reusable.yml b/.github/workflows/pr-auto-review-reusable.yml index 3271ad48b..3e0371c58 100644 --- a/.github/workflows/pr-auto-review-reusable.yml +++ b/.github/workflows/pr-auto-review-reusable.yml @@ -211,7 +211,9 @@ jobs: # silently reporting 0 blocking threads and dispatching. The pure # function only has to tolerate a well-formed-but-empty payload. # shellcheck disable=SC2016 # $owner/$repo/$number are GraphQL variable refs, not shell vars - _GQL='query($owner:String!,$repo:String!,$number:Int!){repository(owner:$owner,name:$repo){pullRequest(number:$number){reviewThreads(first:100){nodes{isResolved isOutdated comments(first:1){nodes{author{__typename}}}}}}}}' + _GQL='query($owner:String!,$repo:String!,$number:Int!){repository(owner:$owner,name:$repo)' + _GQL+='{pullRequest(number:$number){reviewThreads(first:100){nodes{isResolved isOutdated' + _GQL+=' comments(first:1){nodes{author{__typename}}}}}}}}' THREADS_JSON=$(gh api graphql \ -f "query=$_GQL" \ -f owner="${REPO%%/*}" \ From 6a8987c8b62597bc28334dc0a586be2180a99f68 Mon Sep 17 00:00:00 2001 From: donpetry-bot <281750570+donpetry-bot@users.noreply.github.com> Date: Thu, 23 Jul 2026 19:13:38 +0000 Subject: [PATCH 4/6] chore: dev-lead update (review-changes) [skip ci-relay] --- .../scripts/pr-auto-review/sweep-dispatch.sh | 5 ++++- .github/workflows/pr-auto-review-reusable.yml | 3 ++- .../pr-auto-review/blocking-threads.bats | 20 +++++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/scripts/pr-auto-review/sweep-dispatch.sh b/.github/scripts/pr-auto-review/sweep-dispatch.sh index 2310c0bed..4843cfc81 100644 --- a/.github/scripts/pr-auto-review/sweep-dispatch.sh +++ b/.github/scripts/pr-auto-review/sweep-dispatch.sh @@ -104,7 +104,10 @@ evaluate_pr() { if [ -z "${required_json}" ]; then required_json="[]"; fi # shellcheck disable=SC2016 # $owner/$repo/$number are GraphQL variable refs, not shell vars - local gql='query($owner:String!,$repo:String!,$number:Int!){repository(owner:$owner,name:$repo){pullRequest(number:$number){reviewThreads(first:100){nodes{isResolved isOutdated}}}}}' + local gql='query($owner:String!,$repo:String!,$number:Int!){repository(owner:$owner,name:$repo)' + # shellcheck disable=SC2016 + gql+='{pullRequest(number:$number){reviewThreads(first:100){nodes{isResolved isOutdated' + gql+=' comments(first:100){nodes{author{__typename}}}}}}}}' threads_json=$(gh api graphql \ -f "query=$gql" \ -f owner="${repo%%/*}" \ diff --git a/.github/workflows/pr-auto-review-reusable.yml b/.github/workflows/pr-auto-review-reusable.yml index 3e0371c58..f6cda2fb3 100644 --- a/.github/workflows/pr-auto-review-reusable.yml +++ b/.github/workflows/pr-auto-review-reusable.yml @@ -212,8 +212,9 @@ jobs: # function only has to tolerate a well-formed-but-empty payload. # shellcheck disable=SC2016 # $owner/$repo/$number are GraphQL variable refs, not shell vars _GQL='query($owner:String!,$repo:String!,$number:Int!){repository(owner:$owner,name:$repo)' + # shellcheck disable=SC2016 _GQL+='{pullRequest(number:$number){reviewThreads(first:100){nodes{isResolved isOutdated' - _GQL+=' comments(first:1){nodes{author{__typename}}}}}}}}' + _GQL+=' comments(first:100){nodes{author{__typename}}}}}}}}' THREADS_JSON=$(gh api graphql \ -f "query=$_GQL" \ -f owner="${REPO%%/*}" \ diff --git a/test/workflows/pr-auto-review/blocking-threads.bats b/test/workflows/pr-auto-review/blocking-threads.bats index 39ab6c23a..17be93ad8 100644 --- a/test/workflows/pr-auto-review/blocking-threads.bats +++ b/test/workflows/pr-auto-review/blocking-threads.bats @@ -200,10 +200,26 @@ resp() { [ "$output" = "1" ] } +@test "blocking count: thread with bot first comment and human reply → 1 (not purely advisory-bot)" { + # A thread opened by a bot but with a human follow-up must block. + # This pins the requirement that comments(first:100) is used in the GQL query + # rather than comments(first:1) — a first:1 query would only see the Bot + # comment and incorrectly classify the thread as advisory-bot-only. + run pr_auto_review_blocking_thread_count <<<"$(resp '[{ + "isResolved":false,"isOutdated":false, + "comments":{"nodes":[ + {"author":{"__typename":"Bot"}}, + {"author":{"__typename":"User"}} + ]} + }]')" + [ "$status" -eq 0 ] + [ "$output" = "1" ] +} + @test "blocking count: the #892 scenario — multiple advisory bot threads (gemini + codeant) → 0" { # Scenario: CI green, CHANGES_REQUESTED from advisory bots (gemini-code-assist, - # codeant-ai), all 13 threads unresolved and not outdated. Without the fix, - # the gate counts 13 blocking threads and stalls dispatch even though every + # codeant-ai), all 5 threads unresolved and not outdated. Without the fix, + # the gate counts 5 blocking threads and stalls dispatch even though every # thread is advisory-bot feedback with no machine findings. run pr_auto_review_blocking_thread_count <<<"$(resp '[ {"isResolved":false,"isOutdated":false,"comments":{"nodes":[{"author":{"__typename":"Bot"}}]}}, From 1e280c86443b0c53b5162ec8c17c37c0e5340d9a Mon Sep 17 00:00:00 2001 From: donpetry-bot <281750570+donpetry-bot@users.noreply.github.com> Date: Fri, 24 Jul 2026 09:41:22 +0000 Subject: [PATCH 5/6] chore: dev-lead update (review-changes) [skip ci-relay] --- .github/scripts/pr-auto-review/README.md | 2 +- .github/scripts/pr-auto-review/lib/ready-check.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/pr-auto-review/README.md b/.github/scripts/pr-auto-review/README.md index 106902768..b023632c4 100644 --- a/.github/scripts/pr-auto-review/README.md +++ b/.github/scripts/pr-auto-review/README.md @@ -19,7 +19,7 @@ Pure, side-effect-free helpers. Source the file, then call: |----------|-------|---------| | `pr_auto_review_required_contexts` | branch-rules JSON on stdin (`GET /repos/{owner}/{repo}/rules/branches/{branch}`) | prints a compact JSON array of required status-check context names (`[]` if none / non-array) | | `pr_auto_review_checks_ready REQUIRED_JSON SELF_NAME` | checks JSON on stdin (`gh pr checks --json bucket,name`) | prints a one-line reason; `0` ready, `1` not ready | -| `pr_auto_review_blocking_thread_count` | review-threads JSON on stdin (`reviewThreads(first:100){nodes{isResolved isOutdated}}`) | prints the count of **blocking** threads — unresolved AND not outdated | +| `pr_auto_review_blocking_thread_count` | review-threads JSON on stdin (`reviewThreads(first:100){nodes{isResolved isOutdated comments(first:100){nodes{author{__typename}}}}}`) | prints the count of **blocking** threads — unresolved AND not outdated AND not posted exclusively by advisory bots | | `pr_auto_review_ready STATE IS_DRAFT CHECKS_JSON REQUIRED_JSON SELF_NAME REVIEW_DECISION BLOCKING_THREAD_COUNT` | the PR facts the workflow gathers (all as arguments — no stdin) | prints the **decision class** on stdout; `0` ready, `1` not ready | ## `lib/sweep.sh` diff --git a/.github/scripts/pr-auto-review/lib/ready-check.sh b/.github/scripts/pr-auto-review/lib/ready-check.sh index 9ac3999fa..172392224 100644 --- a/.github/scripts/pr-auto-review/lib/ready-check.sh +++ b/.github/scripts/pr-auto-review/lib/ready-check.sh @@ -96,7 +96,7 @@ pr_auto_review_checks_ready() { # pr_auto_review_blocking_thread_count # Reads a review-threads GraphQL response on stdin — the payload of -# `reviewThreads(first:100){nodes{isResolved isOutdated comments(first:1){nodes{author{__typename}}}}}` under +# `reviewThreads(first:100){nodes{isResolved isOutdated comments(first:100){nodes{author{__typename}}}}}` under # .data.repository.pullRequest — and prints the count of threads that should # BLOCK auto-dispatch: those that are unresolved AND not outdated AND not # posted exclusively by advisory bots. From 574bde588a9f9ee93b3e05a85a80c4df668c73ae Mon Sep 17 00:00:00 2001 From: donpetry-bot <281750570+donpetry-bot@users.noreply.github.com> Date: Fri, 24 Jul 2026 14:22:22 +0000 Subject: [PATCH 6/6] chore: dev-lead update (review-changes) [skip ci-relay] --- node_modules/.package-lock.json | 21 +- node_modules/bats-assert/LICENSE | 116 -- node_modules/bats-assert/README.md | 1038 ----------------- node_modules/bats-assert/load.bash | 33 - node_modules/bats-assert/package.json | 49 - node_modules/bats-assert/src/assert.bash | 42 - .../bats-assert/src/assert_equal.bash | 42 - .../bats-assert/src/assert_failure.bash | 86 -- node_modules/bats-assert/src/assert_line.bash | 298 ----- .../bats-assert/src/assert_not_equal.bash | 42 - .../bats-assert/src/assert_output.bash | 247 ---- .../bats-assert/src/assert_regex.bash | 54 - .../bats-assert/src/assert_success.bash | 47 - node_modules/bats-assert/src/refute.bash | 42 - node_modules/bats-assert/src/refute_line.bash | 341 ------ .../bats-assert/src/refute_output.bash | 243 ---- .../bats-assert/src/refute_regex.bash | 64 - node_modules/bats-support/CHANGELOG.md | 46 - node_modules/bats-support/LICENSE | 116 -- node_modules/bats-support/README.md | 189 --- node_modules/bats-support/load.bash | 3 - node_modules/bats-support/package.json | 30 - node_modules/bats-support/src/error.bash | 41 - node_modules/bats-support/src/lang.bash | 73 -- node_modules/bats-support/src/output.bash | 279 ----- package-lock.json | 2 +- 26 files changed, 2 insertions(+), 3582 deletions(-) delete mode 100644 node_modules/bats-assert/LICENSE delete mode 100644 node_modules/bats-assert/README.md delete mode 100644 node_modules/bats-assert/load.bash delete mode 100644 node_modules/bats-assert/package.json delete mode 100644 node_modules/bats-assert/src/assert.bash delete mode 100644 node_modules/bats-assert/src/assert_equal.bash delete mode 100644 node_modules/bats-assert/src/assert_failure.bash delete mode 100644 node_modules/bats-assert/src/assert_line.bash delete mode 100644 node_modules/bats-assert/src/assert_not_equal.bash delete mode 100644 node_modules/bats-assert/src/assert_output.bash delete mode 100644 node_modules/bats-assert/src/assert_regex.bash delete mode 100644 node_modules/bats-assert/src/assert_success.bash delete mode 100644 node_modules/bats-assert/src/refute.bash delete mode 100644 node_modules/bats-assert/src/refute_line.bash delete mode 100644 node_modules/bats-assert/src/refute_output.bash delete mode 100644 node_modules/bats-assert/src/refute_regex.bash delete mode 100644 node_modules/bats-support/CHANGELOG.md delete mode 100644 node_modules/bats-support/LICENSE delete mode 100644 node_modules/bats-support/README.md delete mode 100644 node_modules/bats-support/load.bash delete mode 100644 node_modules/bats-support/package.json delete mode 100644 node_modules/bats-support/src/error.bash delete mode 100644 node_modules/bats-support/src/lang.bash delete mode 100644 node_modules/bats-support/src/output.bash diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index b57d6f220..a80f4c2fb 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -1,5 +1,5 @@ { - "name": "pr-840", + "name": "pr-893", "lockfileVersion": 3, "requires": true, "packages": { @@ -11,25 +11,6 @@ "bin": { "bats": "bin/bats" } - }, - "node_modules/bats-assert": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/bats-assert/-/bats-assert-2.2.4.tgz", - "integrity": "sha512-EcaY4Z+Tbz1c7pnC1SrVSq0epr7tLwFpz6qt7KUW9K8uSw8V12DTfH9d2HxZWvBEATaCuMsZ7KoZMFiSQPRoXw==", - "license": "CC0-1.0", - "peerDependencies": { - "bats": "0.4 || ^1", - "bats-support": "^0.3" - } - }, - "node_modules/bats-support": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/bats-support/-/bats-support-0.3.0.tgz", - "integrity": "sha512-z+2WzXbI4OZgLnynydqH8GpI3+DcOtepO66PlK47SfEzTkiuV9hxn9eIQX+uLVFbt2Oqoc7Ky3TJ/N83lqD+cg==", - "license": "CC0-1.0", - "peerDependencies": { - "bats": "0.4 || ^1" - } } } } diff --git a/node_modules/bats-assert/LICENSE b/node_modules/bats-assert/LICENSE deleted file mode 100644 index 670154e35..000000000 --- a/node_modules/bats-assert/LICENSE +++ /dev/null @@ -1,116 +0,0 @@ -CC0 1.0 Universal - -Statement of Purpose - -The laws of most jurisdictions throughout the world automatically confer -exclusive Copyright and Related Rights (defined below) upon the creator and -subsequent owner(s) (each and all, an "owner") of an original work of -authorship and/or a database (each, a "Work"). - -Certain owners wish to permanently relinquish those rights to a Work for the -purpose of contributing to a commons of creative, cultural and scientific -works ("Commons") that the public can reliably and without fear of later -claims of infringement build upon, modify, incorporate in other works, reuse -and redistribute as freely as possible in any form whatsoever and for any -purposes, including without limitation commercial purposes. These owners may -contribute to the Commons to promote the ideal of a free culture and the -further production of creative, cultural and scientific works, or to gain -reputation or greater distribution for their Work in part through the use and -efforts of others. - -For these and/or other purposes and motivations, and without any expectation -of additional consideration or compensation, the person associating CC0 with a -Work (the "Affirmer"), to the extent that he or she is an owner of Copyright -and Related Rights in the Work, voluntarily elects to apply CC0 to the Work -and publicly distribute the Work under its terms, with knowledge of his or her -Copyright and Related Rights in the Work and the meaning and intended legal -effect of CC0 on those rights. - -1. Copyright and Related Rights. A Work made available under CC0 may be -protected by copyright and related or neighboring rights ("Copyright and -Related Rights"). Copyright and Related Rights include, but are not limited -to, the following: - - i. the right to reproduce, adapt, distribute, perform, display, communicate, - and translate a Work; - - ii. moral rights retained by the original author(s) and/or performer(s); - - iii. publicity and privacy rights pertaining to a person's image or likeness - depicted in a Work; - - iv. rights protecting against unfair competition in regards to a Work, - subject to the limitations in paragraph 4(a), below; - - v. rights protecting the extraction, dissemination, use and reuse of data in - a Work; - - vi. database rights (such as those arising under Directive 96/9/EC of the - European Parliament and of the Council of 11 March 1996 on the legal - protection of databases, and under any national implementation thereof, - including any amended or successor version of such directive); and - - vii. other similar, equivalent or corresponding rights throughout the world - based on applicable law or treaty, and any national implementations thereof. - -2. Waiver. To the greatest extent permitted by, but not in contravention of, -applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and -unconditionally waives, abandons, and surrenders all of Affirmer's Copyright -and Related Rights and associated claims and causes of action, whether now -known or unknown (including existing as well as future claims and causes of -action), in the Work (i) in all territories worldwide, (ii) for the maximum -duration provided by applicable law or treaty (including future time -extensions), (iii) in any current or future medium and for any number of -copies, and (iv) for any purpose whatsoever, including without limitation -commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes -the Waiver for the benefit of each member of the public at large and to the -detriment of Affirmer's heirs and successors, fully intending that such Waiver -shall not be subject to revocation, rescission, cancellation, termination, or -any other legal or equitable action to disrupt the quiet enjoyment of the Work -by the public as contemplated by Affirmer's express Statement of Purpose. - -3. Public License Fallback. Should any part of the Waiver for any reason be -judged legally invalid or ineffective under applicable law, then the Waiver -shall be preserved to the maximum extent permitted taking into account -Affirmer's express Statement of Purpose. In addition, to the extent the Waiver -is so judged Affirmer hereby grants to each affected person a royalty-free, -non transferable, non sublicensable, non exclusive, irrevocable and -unconditional license to exercise Affirmer's Copyright and Related Rights in -the Work (i) in all territories worldwide, (ii) for the maximum duration -provided by applicable law or treaty (including future time extensions), (iii) -in any current or future medium and for any number of copies, and (iv) for any -purpose whatsoever, including without limitation commercial, advertising or -promotional purposes (the "License"). The License shall be deemed effective as -of the date CC0 was applied by Affirmer to the Work. Should any part of the -License for any reason be judged legally invalid or ineffective under -applicable law, such partial invalidity or ineffectiveness shall not -invalidate the remainder of the License, and in such case Affirmer hereby -affirms that he or she will not (i) exercise any of his or her remaining -Copyright and Related Rights in the Work or (ii) assert any associated claims -and causes of action with respect to the Work, in either case contrary to -Affirmer's express Statement of Purpose. - -4. Limitations and Disclaimers. - - a. No trademark or patent rights held by Affirmer are waived, abandoned, - surrendered, licensed or otherwise affected by this document. - - b. Affirmer offers the Work as-is and makes no representations or warranties - of any kind concerning the Work, express, implied, statutory or otherwise, - including without limitation warranties of title, merchantability, fitness - for a particular purpose, non infringement, or the absence of latent or - other defects, accuracy, or the present or absence of errors, whether or not - discoverable, all to the greatest extent permissible under applicable law. - - c. Affirmer disclaims responsibility for clearing rights of other persons - that may apply to the Work or any use thereof, including without limitation - any person's Copyright and Related Rights in the Work. Further, Affirmer - disclaims responsibility for obtaining any necessary consents, permissions - or other rights required for any use of the Work. - - d. Affirmer understands and acknowledges that Creative Commons is not a - party to this document and has no duty or obligation with respect to this - CC0 or use of the Work. - -For more information, please see - diff --git a/node_modules/bats-assert/README.md b/node_modules/bats-assert/README.md deleted file mode 100644 index 8a5fc176b..000000000 --- a/node_modules/bats-assert/README.md +++ /dev/null @@ -1,1038 +0,0 @@ -# bats-assert - -[![License](https://img.shields.io/npm/l/bats-assert.svg)](https://github.com/bats-core/bats-assert/blob/master/LICENSE) -[![GitHub release](https://img.shields.io/github/release/bats-core/bats-assert.svg)](https://github.com/bats-core/bats-assert/releases/latest) -[![npm release](https://img.shields.io/npm/v/bats-assert.svg)](https://www.npmjs.com/package/bats-assert) -[![Tests](https://github.com/bats-core/bats-assert/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/bats-core/bats-assert/actions/workflows/test.yml) - -`bats-assert` is a helper library providing common assertions for [Bats][bats]. - -- [Install](#install) -- [Usage](#usage) -- [Options](#options) -- [Full Assertion API](#full-assertion-api) - -In the context of this project, an [assertion][wikipedia-assertions] is a function that perform a test and returns `1` on failure or `0` on success. -To make debugging easier, the assertion also outputs relevant information on failure. -The output is [formatted][bats-support-output] for readability. -To make assertions usable outside of `@test` blocks, the output is sent to [stderr][wikipedia-stderr]. - -The most recent invocation of Bats' `run` function is used for testing assertions on output and status code. - -[wikipedia-assertions]: https://en.wikipedia.org/wiki/Assertion_(software_development) -[wikipedia-stderr]: https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr) - -## Install - -This project has one dependency, for output formatting: [`bats-support`][bats-support] - -Read the [shared documentation][bats-docs] to learn how to install and load both libraries. - -## Usage - -This project provides the following functions: - - - [assert](#assert) / [refute](#refute) Assert a given expression evaluates to `true` or `false`. - - [assert_equal](#assert_equal) Assert two parameters are equal. - - [assert_not_equal](#assert_not_equal) Assert two parameters are not equal. - - [assert_success](#assert_success) / [assert_failure](#assert_failure) Assert exit status is `0` or `1`. - - [assert_output](#assert_output) / [refute_output](#refute_output) Assert output does (or does not) contain given content. - - [assert_line](#assert_line) / [refute_line](#refute_line) Assert a specific line of output does (or does not) contain given content. - - [assert_regex](#assert_regex) / [refute_regex](#refute_regex) Assert a parameter does (or does not) match given pattern. - - [assert_stderr](#assert_stderr) / [refute_stderr](#refute_stderr) Assert stderr does (or does not) contain given content. - - [assert_stderr_line](#assert_stderr_line) / [refute_stderr_line](#refute_stderr_line) Assert a specific line of stderr does (or does not) contain given content. - -These commands are described in more detail below. - -## Options - -For functions that have options, `--` disables option parsing for the remaining arguments to allow using arguments identical to one of the allowed options. - -```bash -assert_output -- '-p' -``` - -Specifying `--` as an argument is similarly simple. - -```bash -refute_line -- '--' -``` - - -## Full Assertion API - -### `assert` - -Fail if the given expression evaluates to false. - -> _**Note**: -> The expression must be a simple command. -> [Compound commands][bash-comp-cmd], such as `[[`, can be used only when executed with `bash -c`._ - -```bash -@test 'assert()' { - assert [ 1 -lt 0 ] -} -``` - -On failure, the failed expression is displayed. - -``` --- assertion failed -- -expression : [ 1 -lt 0 ] --- -``` - - -### `refute` - -Fail if the given expression evaluates to true. - -> _**Note** -> The expression must be a simple command. -> [Compound commands][bash-comp-cmd], such as `[[`, can be used only when executed with `bash -c`._ - -```bash -@test 'refute()' { - refute [ 1 -gt 0 ] -} -``` - -On failure, the successful expression is displayed. - -``` --- assertion succeeded, but it was expected to fail -- -expression : [ 1 -gt 0 ] --- -``` - - -### `assert_equal` - -Fail if the two parameters, actual and expected value respectively, do not equal. - -```bash -@test 'assert_equal()' { - assert_equal 'have' 'want' -} -``` - -On failure, the expected and actual values are displayed. - -``` --- values do not equal -- -expected : want -actual : have --- -``` - -If either value is longer than one line both are displayed in *multi-line* format. - - -### `assert_not_equal` - -Fail if the two parameters, actual and unexpected value respectively, are equal. - -```bash -@test 'assert_not_equal()' { - assert_not_equal 'foobar' 'foobar' -} -``` - -On failure, the expected and actual values are displayed. - -``` --- values should not be equal -- -unexpected : foobar -actual : foobar --- -``` - -If either value is longer than one line both are displayed in *multi-line* format. - - -### `assert_success` - -Fail if `$status` is not 0. - -```bash -@test 'assert_success() status only' { - run bash -c "echo 'Error!'; exit 1" - assert_success -} -``` - -On failure, `$status` and `$output` are displayed. - -``` --- command failed -- -status : 1 -output : Error! --- -``` - -If `$output` is longer than one line, it is displayed in *multi-line* format. - - -### `assert_failure` - -Fail if `$status` is 0. - -```bash -@test 'assert_failure() status only' { - run echo 'Success!' - assert_failure -} -``` - -On failure, `$output` is displayed. - -``` --- command succeeded, but it was expected to fail -- -output : Success! --- -``` - -If `$output` is longer than one line, it is displayed in *multi-line* format. - -#### Expected status - -When one parameter is specified, fail if `$status` does not equal the expected status specified by the parameter. - -```bash -@test 'assert_failure() with expected status' { - run bash -c "echo 'Error!'; exit 1" - assert_failure 2 -} -``` - -On failure, the expected and actual status, and `$output` are displayed. - -``` --- command failed as expected, but status differs -- -expected : 2 -actual : 1 -output : Error! --- -``` - -If `$output` is longer than one line, it is displayed in *multi-line* format. - - -### `assert_output` - -This function helps to verify that a command or function produces the correct output by checking that the specified expected output matches the actual output. -Matching can be literal (default), partial or regular expression. -This function is the logical complement of `refute_output`. - -#### Literal matching - -By default, literal matching is performed. -The assertion fails if `$output` does not equal the expected output. - -```bash -@test 'assert_output()' { - run echo 'have' - assert_output 'want' -} -``` - -On failure, the expected and actual output are displayed. - -``` --- output differs -- -expected : want -actual : have --- -``` - -If either value is longer than one line both are displayed in *multi-line* format. - -#### Existence - -To assert that any (non-empty) output exists at all, simply omit the matching argument. - -```bash -@test 'assert_output()' { - run echo 'have' - assert_output -} -``` - -On failure, an error message is displayed. - -``` --- no output -- -expected non-empty output, but output was empty --- -``` - -#### Partial matching - -Partial matching can be enabled with the `--partial` option (`-p` for short). -When used, the assertion fails if the expected *substring* is not found in `$output`. - -```bash -@test 'assert_output() partial matching' { - run echo 'ERROR: no such file or directory' - assert_output --partial 'SUCCESS' -} -``` - -On failure, the substring and the output are displayed. - -``` --- output does not contain substring -- -substring : SUCCESS -output : ERROR: no such file or directory --- -``` - -This option and regular expression matching (`--regexp` or `-e`) are mutually exclusive. -An error is displayed when used simultaneously. - -#### Regular expression matching - -Regular expression matching can be enabled with the `--regexp` option (`-e` for short). -When used, the assertion fails if the *[extended regular expression]* does not match `$output`. - -[extended regular expression]: https://en.wikibooks.org/wiki/Regular_Expressions/POSIX-Extended_Regular_Expressions - -> [!IMPORTANT] -> Bash [doesn't support](https://stackoverflow.com/a/48898886/5432315) certain parts of regular expressions you may be used to: -> * `\d` `\D` `\s` `\S` `\w` `\W` — these can be replaced with POSIX character class equivalents `[[:digit:]]`, `[^[:digit:]]`, `[[:space:]]`, `[^[:space:]]`, `[_[:alnum:]]`, and `[^_[:alnum:]]`, respectively. (Notice the last case, where the `[:alnum:]` POSIX character class is augmented with underscore to be exactly equivalent to the Perl `\w` shorthand.) -> * Non-greedy matching. You can sometimes replace `a.*?b` with something like `a[^ab]*b` to get a similar effect in practice, though the two are not exactly equivalent. -> * Non-capturing parentheses `(?:...)`. In the trivial case, just use capturing parentheses `(...)` instead; though of course, if you use capture groups and/or backreferences, this will renumber your capture groups. -> * Lookarounds like `(?<=before)` or `(?!after)`. (In fact anything with `(?` is a Perl extension.) There is no simple general workaround for these, though you can sometimes rephrase your problem into one where lookarounds can be avoided. - -> _**Note**: -> The anchors `^` and `$` bind to the beginning and the end of the entire output (not individual lines), respectively._ - -```bash -@test 'assert_output() regular expression matching' { - run echo 'Foobar 0.1.0' - assert_output --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' -} -``` - -On failure, the regular expression and the output are displayed. - -``` --- regular expression does not match output -- -regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ -output : Foobar 0.1.0 --- -``` - -An error is displayed if the specified extended regular expression is invalid. - -This option and partial matching (`--partial` or `-p`) are mutually exclusive. -An error is displayed when used simultaneously. - -#### Standard Input, HereDocs and HereStrings - -The expected output can be specified via standard input (also heredoc/herestring) with the `-`/`--stdin` option. - -```bash -@test 'assert_output() with pipe' { - run echo 'hello' - echo 'hello' | assert_output - -} - -@test 'assert_output() with herestring' { - run echo 'hello' - assert_output - <<< hello -} -``` - - -### `refute_output` - -This function helps to verify that a command or function produces the correct output by checking that the specified unexpected output does not match the actual output. -Matching can be literal (default), partial or regular expression. -This function is the logical complement of `assert_output`. - -#### Literal matching - -By default, literal matching is performed. -The assertion fails if `$output` equals the unexpected output. - -```bash -@test 'refute_output()' { - run echo 'want' - refute_output 'want' -} -``` - -On failure, the output is displayed. - -``` --- output equals, but it was expected to differ -- -output : want --- -``` - -If output is longer than one line it is displayed in *multi-line* format. - -#### Existence - -To assert that there is no output at all, simply omit the matching argument. - -```bash -@test 'refute_output()' { - run foo --silent - refute_output -} -``` - -On failure, an error message is displayed. - -``` --- unexpected output -- -expected no output, but output was non-empty --- -``` - -#### Partial matching - -Partial matching can be enabled with the `--partial` option (`-p` for short). -When used, the assertion fails if the unexpected *substring* is found in `$output`. - -```bash -@test 'refute_output() partial matching' { - run echo 'ERROR: no such file or directory' - refute_output --partial 'ERROR' -} -``` - -On failure, the substring and the output are displayed. - -``` --- output should not contain substring -- -substring : ERROR -output : ERROR: no such file or directory --- -``` - -This option and regular expression matching (`--regexp` or `-e`) are mutually exclusive. -An error is displayed when used simultaneously. - -#### Regular expression matching - -Regular expression matching can be enabled with the `--regexp` option (`-e` for short). -When used, the assertion fails if the *extended regular expression* matches `$output`. - -> _**Note**: -> The anchors `^` and `$` bind to the beginning and the end of the entire output (not individual lines), respectively._ - -```bash -@test 'refute_output() regular expression matching' { - run echo 'Foobar v0.1.0' - refute_output --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' -} -``` - -On failure, the regular expression and the output are displayed. - -``` --- regular expression should not match output -- -regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ -output : Foobar v0.1.0 --- -``` - -An error is displayed if the specified extended regular expression is invalid. - -This option and partial matching (`--partial` or `-p`) are mutually exclusive. -An error is displayed when used simultaneously. - -#### Standard Input, HereDocs and HereStrings - -The unexpected output can be specified via standard input (also heredoc/herestring) with the `-`/`--stdin` option. - -```bash -@test 'refute_output() with pipe' { - run echo 'hello' - echo 'world' | refute_output - -} - -@test 'refute_output() with herestring' { - run echo 'hello' - refute_output - <<< world -} -``` - - -### `assert_line` - -Similarly to `assert_output`, this function helps to verify that a command or function produces the correct output. -It checks that the expected line appears in the output (default) or in a specific line of it. -Matching can be literal (default), partial or regular expression. -This function is the logical complement of `refute_line`. - -> _**Warning**: -> Due to a [bug in Bats][bats-93], empty lines are discarded from `${lines[@]}`, -> causing line indices to change and preventing testing for empty lines._ - -[bats-93]: https://github.com/sstephenson/bats/pull/93 - -#### Looking for a line in the output - -By default, the entire output is searched for the expected line. -The assertion fails if the expected line is not found in `${lines[@]}`. - -```bash -@test 'assert_line() looking for line' { - run echo $'have-0\nhave-1\nhave-2' - assert_line 'want' -} -``` - -On failure, the expected line and the output are displayed. - -> _**Warning**: -> The output displayed does not contain empty lines. -> See the Warning above for more._ - -``` --- output does not contain line -- -line : want -output (3 lines): - have-0 - have-1 - have-2 --- -``` - -If output is not longer than one line, it is displayed in *two-column* format. - -#### Matching a specific line - -When the `--index ` option is used (`-n ` for short), the expected line is matched only against the line identified by the given index. -The assertion fails if the expected line does not equal `${lines[]}`. - -```bash -@test 'assert_line() specific line' { - run echo $'have-0\nhave-1\nhave-2' - assert_line --index 1 'want-1' -} -``` - -On failure, the index and the compared lines are displayed. - -``` --- line differs -- -index : 1 -expected : want-1 -actual : have-1 --- -``` - -#### Partial matching - -Partial matching can be enabled with the `--partial` option (`-p` for short). -When used, a match fails if the expected *substring* is not found in the matched line. - -```bash -@test 'assert_line() partial matching' { - run echo $'have 1\nhave 2\nhave 3' - assert_line --partial 'want' -} -``` - -On failure, the same details are displayed as for literal matching, except that the substring replaces the expected line. - -``` --- no output line contains substring -- -substring : want -output (3 lines): - have 1 - have 2 - have 3 --- -``` - -This option and regular expression matching (`--regexp` or `-e`) are mutually exclusive. -An error is displayed when used simultaneously. - -#### Regular expression matching - -Regular expression matching can be enabled with the `--regexp` option (`-e` for short). -When used, a match fails if the *extended regular expression* does not match the line being tested. - -> _**Note**: -> As expected, the anchors `^` and `$` bind to the beginning and the end of the matched line, respectively._ - -```bash -@test 'assert_line() regular expression matching' { - run echo $'have-0\nhave-1\nhave-2' - assert_line --index 1 --regexp '^want-[0-9]$' -} -``` - -On failure, the same details are displayed as for literal matching, except that the regular expression replaces the expected line. - -``` --- regular expression does not match line -- -index : 1 -regexp : ^want-[0-9]$ -line : have-1 --- -``` - -An error is displayed if the specified extended regular expression is invalid. - -This option and partial matching (`--partial` or `-p`) are mutually exclusive. -An error is displayed when used simultaneously. - - -### `refute_line` - -Similarly to `refute_output`, this function helps to verify that a command or function produces the correct output. -It checks that the unexpected line does not appear in the output (default) or in a specific line of it. -Matching can be literal (default), partial or regular expression. -This function is the logical complement of `assert_line`. - -> _**Warning**: -> Due to a [bug in Bats][bats-93], empty lines are discarded from `${lines[@]}`, -> causing line indices to change and preventing testing for empty lines._ - -[bats-93]: https://github.com/sstephenson/bats/pull/93 - -#### Looking for a line in the output - -By default, the entire output is searched for the unexpected line. -The assertion fails if the unexpected line is found in `${lines[@]}`. - -```bash -@test 'refute_line() looking for line' { - run echo $'have-0\nwant\nhave-2' - refute_line 'want' -} -``` - -On failure, the unexpected line, the index of its first match and the output with the matching line highlighted are displayed. - -> _**Warning**: -> The output displayed does not contain empty lines. -> See the Warning above for more._ - -``` --- line should not be in output -- -line : want -index : 1 -output (3 lines): - have-0 -> want - have-2 --- -``` - -If output is not longer than one line, it is displayed in *two-column* format. - -#### Matching a specific line - -When the `--index ` option is used (`-n ` for short), the unexpected line is matched only against the line identified by the given index. -The assertion fails if the unexpected line equals `${lines[]}`. - -```bash -@test 'refute_line() specific line' { - run echo $'have-0\nwant-1\nhave-2' - refute_line --index 1 'want-1' -} -``` - -On failure, the index and the unexpected line are displayed. - -``` --- line should differ -- -index : 1 -line : want-1 --- -``` - -#### Partial matching - -Partial matching can be enabled with the `--partial` option (`-p` for short). -When used, a match fails if the unexpected *substring* is found in the matched line. - -```bash -@test 'refute_line() partial matching' { - run echo $'have 1\nwant 2\nhave 3' - refute_line --partial 'want' -} -``` - -On failure, in addition to the details of literal matching, the substring is also displayed. -When used with `--index ` the substring replaces the unexpected line. - -``` --- no line should contain substring -- -substring : want -index : 1 -output (3 lines): - have 1 -> want 2 - have 3 --- -``` - -This option and regular expression matching (`--regexp` or `-e`) are mutually exclusive. -An error is displayed when used simultaneously. - -#### Regular expression matching - -Regular expression matching can be enabled with the `--regexp` option (`-e` for short). -When used, a match fails if the *extended regular expression* matches the line being tested. - -> _**Note**: -> As expected, the anchors `^` and `$` bind to the beginning and the end of the matched line, respectively._ - -```bash -@test 'refute_line() regular expression matching' { - run echo $'Foobar v0.1.0\nRelease date: 2015-11-29' - refute_line --index 0 --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' -} -``` - -On failure, in addition to the details of literal matching, the regular expression is also displayed. -When used with `--index ` the regular expression replaces the unexpected line. - -``` --- regular expression should not match line -- -index : 0 -regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ -line : Foobar v0.1.0 --- -``` - -An error is displayed if the specified extended regular expression is invalid. - -This option and partial matching (`--partial` or `-p`) are mutually exclusive. -An error is displayed when used simultaneously. - -### `assert_regex` - -This function is similar to `assert_equal` but uses pattern matching instead of -equality, by wrapping `[[ value =~ pattern ]]`. - -Fail if the value (first parameter) does not match the pattern (second -parameter). - -```bash -@test 'assert_regex()' { - assert_regex 'what' 'x$' -} -``` - -On failure, the value and the pattern are displayed. - -``` --- values does not match regular expression -- -value : what -pattern : x$ --- -``` - -If the value is longer than one line then it is displayed in *multi-line* -format. - -An error is displayed if the specified extended regular expression is invalid. - -For description of the matching behavior, refer to the documentation of the -`=~` operator in the [Bash manual][bash-conditional]. - -> _**Note**: -> the `BASH_REMATCH` array is available immediately after the assertion succeeds but is fragile; -> i.e. prone to being overwritten as a side effect of other actions._ - -### `refute_regex` - -This function is similar to `refute_equal` but uses pattern matching instead of -equality, by wrapping `! [[ value =~ pattern ]]`. - -Fail if the value (first parameter) matches the pattern (second parameter). - -```bash -@test 'refute_regex()' { - refute_regex 'WhatsApp' 'Threema' -} -``` - -On failure, the value, the pattern and the match are displayed. - -```bash -@test 'refute_regex()' { - refute_regex 'WhatsApp' 'What.' -} - --- value matches regular expression -- -value : WhatsApp -pattern : What. -match : Whats -case : sensitive --- -``` - -If the value or pattern is longer than one line then it is displayed in -*multi-line* format. - -An error is displayed if the specified extended regular expression is invalid. - -For description of the matching behavior, refer to the documentation of the -`=~` operator in the [Bash manual][bash-conditional]. - -> _**Note**: -> the `BASH_REMATCH` array is available immediately after the assertion fails but is fragile; -> i.e. prone to being overwritten as a side effect of other actions like calling `run`. -> Thus, it's good practice to avoid using `BASH_REMATCH` in conjunction with `refute_regex()`. -> The valuable information the array contains is the matching part of the value which is printed in the failing test log, as mentioned above._ - -### `assert_stderr` - -> _**Note**: -> `run` has to be called with `--separate-stderr` to separate stdout and stderr into `$output` and `$stderr`. -> If not, `$stderr` will be empty, causing `assert_stderr` to always fail. - -Similarly to `assert_output`, this function verifies that a command or function produces the expected stderr. -The stderr matching can be literal (the default), partial or by regular expression. -The expected stderr can be specified either by positional argument or read from STDIN by passing the `-`/`--stdin` flag. - -#### Literal matching - -By default, literal matching is performed. -The assertion fails if `$stderr` does not equal the expected stderr. - - ```bash - echo_err() { - echo "$@" >&2 - } - - @test 'assert_stderr()' { - run --separate-stderr echo_err 'have' - assert_stderr 'want' - } - - @test 'assert_stderr() with pipe' { - run --separate-stderr echo_err 'hello' - echo_err 'hello' | assert_stderr - - } - - @test 'assert_stderr() with herestring' { - run --separate-stderr echo_err 'hello' - assert_stderr - <<< hello - } - ``` - -On failure, the expected and actual stderr are displayed. - - ``` - -- stderr differs -- - expected : want - actual : have - -- - ``` - -#### Existence - -To assert that any stderr exists at all, omit the `expected` argument. - - ```bash - @test 'assert_stderr()' { - run --separate-stderr echo_err 'have' - assert_stderr - } - ``` - -On failure, an error message is displayed. - - ``` - -- no stderr -- - expected non-empty stderr, but stderr was empty - -- - ``` - -#### Partial matching - -Partial matching can be enabled with the `--partial` option (`-p` for short). -When used, the assertion fails if the expected _substring_ is not found in `$stderr`. - - ```bash - @test 'assert_stderr() partial matching' { - run --separate-stderr echo_err 'ERROR: no such file or directory' - assert_stderr --partial 'SUCCESS' - } - ``` - -On failure, the substring and the stderr are displayed. - - ``` - -- stderr does not contain substring -- - substring : SUCCESS - stderr : ERROR: no such file or directory - -- - ``` - -#### Regular expression matching - -Regular expression matching can be enabled with the `--regexp` option (`-e` for short). -When used, the assertion fails if the *extended regular expression* does not match `$stderr`. - -*Note: The anchors `^` and `$` bind to the beginning and the end (respectively) of the entire stderr; not individual lines.* - - ```bash - @test 'assert_stderr() regular expression matching' { - run --separate-stderr echo_err 'Foobar 0.1.0' - assert_stderr --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' - } - ``` - -On failure, the regular expression and the stderr are displayed. - - ``` - -- regular expression does not match stderr -- - regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ - stderr : Foobar 0.1.0 - -- - ``` - -### `refute_stderr` - -> _**Note**: -> `run` has to be called with `--separate-stderr` to separate stdout and stderr into `$output` and `$stderr`. -> If not, `$stderr` will be empty, causing `refute_stderr` to always pass. - -Similar to `refute_output`, this function verifies that a command or function does not produce the unexpected stderr. -(It is the logical complement of `assert_stderr`.) -The stderr matching can be literal (the default), partial or by regular expression. -The unexpected stderr can be specified either by positional argument or read from STDIN by passing the `-`/`--stdin` flag. - -### `assert_stderr_line` - -> _**Note**: -> `run` has to be called with `--separate-stderr` to separate stdout and stderr into `$output` and `$stderr`. -> If not, `$stderr` will be empty, causing `assert_stderr_line` to always fail. - -Similarly to `assert_stderr`, this function verifies that a command or function produces the expected stderr. -It checks that the expected line appears in the stderr (default) or at a specific line number. -Matching can be literal (default), partial or regular expression. -This function is the logical complement of `refute_stderr_line`. - -#### Looking for a line in the stderr - -By default, the entire stderr is searched for the expected line. -The assertion fails if the expected line is not found in `${stderr_lines[@]}`. - - ```bash - echo_err() { - echo "$@" >&2 - } - - @test 'assert_stderr_line() looking for line' { - run --separate-stderr echo_err $'have-0\nhave-1\nhave-2' - assert_stderr_line 'want' - } - ``` - -On failure, the expected line and the stderr are displayed. - - ``` - -- stderr does not contain line -- - line : want - stderr (3 lines): - have-0 - have-1 - have-2 - -- - ``` - -#### Matching a specific line - -When the `--index ` option is used (`-n ` for short), the expected line is matched only against the line identified by the given index. -The assertion fails if the expected line does not equal `${stderr_lines[]}`. - - ```bash - @test 'assert_stderr_line() specific line' { - run --separate-stderr echo_err $'have-0\nhave-1\nhave-2' - assert_stderr_line --index 1 'want-1' - } - ``` - -On failure, the index and the compared stderr_lines are displayed. - - ``` - -- line differs -- - index : 1 - expected : want-1 - actual : have-1 - -- - ``` - -#### Partial matching - -Partial matching can be enabled with the `--partial` option (`-p` for short). -When used, a match fails if the expected *substring* is not found in the matched line. - - ```bash - @test 'assert_stderr_line() partial matching' { - run --separate-stderr echo_err $'have 1\nhave 2\nhave 3' - assert_stderr_line --partial 'want' - } - ``` - -On failure, the same details are displayed as for literal matching, except that the substring replaces the expected line. - - ``` - -- no stderr line contains substring -- - substring : want - stderr (3 lines): - have 1 - have 2 - have 3 - -- - ``` - -#### Regular expression matching - -Regular expression matching can be enabled with the `--regexp` option (`-e` for short). -When used, a match fails if the *extended regular expression* does not match the line being tested. - -*Note: As expected, the anchors `^` and `$` bind to the beginning and the end (respectively) of the matched line.* - - ```bash - @test 'assert_stderr_line() regular expression matching' { - run --separate-stderr echo_err $'have-0\nhave-1\nhave-2' - assert_stderr_line --index 1 --regexp '^want-[0-9]$' - } - ``` - -On failure, the same details are displayed as for literal matching, except that the regular expression replaces the expected line. - - ``` - -- regular expression does not match line -- - index : 1 - regexp : ^want-[0-9]$ - line : have-1 - -- - ``` - -### `refute_stderr_line` - -> _**Note**: -> `run` has to be called with `--separate-stderr` to separate stdout and stderr into `$output` and `$stderr`. -> If not, `$stderr` will be empty, causing `refute_stderr_line` to always pass. - -Similarly to `refute_stderr`, this function helps to verify that a command or function produces the correct stderr. -It checks that the unexpected line does not appear in the stderr (default) or in a specific line of it. -Matching can be literal (default), partial or regular expression. -This function is the logical complement of `assert_stderr_line`. - - - -[bats]: https://github.com/bats-core/bats-core -[bash-comp-cmd]: https://www.gnu.org/software/bash/manual/bash.html#Compound-Commands -[bash-conditional]: https://www.gnu.org/software/bash/manual/bash.html#Conditional-Constructs - -[bats-docs]: https://bats-core.readthedocs.io/ -[bats-support-output]: https://github.com/bats-core/bats-support#output-formatting -[bats-support]: https://github.com/bats-core/bats-support diff --git a/node_modules/bats-assert/load.bash b/node_modules/bats-assert/load.bash deleted file mode 100644 index c67d9e8b4..000000000 --- a/node_modules/bats-assert/load.bash +++ /dev/null @@ -1,33 +0,0 @@ -# bats-assert - Common assertions for Bats -# -# Written in 2016 by Zoltan Tombol -# -# To the extent possible under law, the author(s) have dedicated all -# copyright and related and neighboring rights to this software to the -# public domain worldwide. This software is distributed without any -# warranty. -# -# You should have received a copy of the CC0 Public Domain Dedication -# along with this software. If not, see -# . -# -# Assertions are functions that perform a test and output relevant -# information on failure to help debugging. They return 1 on failure -# and 0 otherwise. -# -# All output is formatted for readability using the functions of -# `output.bash' and sent to the standard error. - -# shellcheck disable=1090 -source "$(dirname "${BASH_SOURCE[0]}")/src/assert.bash" -source "$(dirname "${BASH_SOURCE[0]}")/src/refute.bash" -source "$(dirname "${BASH_SOURCE[0]}")/src/assert_equal.bash" -source "$(dirname "${BASH_SOURCE[0]}")/src/assert_not_equal.bash" -source "$(dirname "${BASH_SOURCE[0]}")/src/assert_success.bash" -source "$(dirname "${BASH_SOURCE[0]}")/src/assert_failure.bash" -source "$(dirname "${BASH_SOURCE[0]}")/src/assert_output.bash" -source "$(dirname "${BASH_SOURCE[0]}")/src/refute_output.bash" -source "$(dirname "${BASH_SOURCE[0]}")/src/assert_line.bash" -source "$(dirname "${BASH_SOURCE[0]}")/src/refute_line.bash" -source "$(dirname "${BASH_SOURCE[0]}")/src/assert_regex.bash" -source "$(dirname "${BASH_SOURCE[0]}")/src/refute_regex.bash" diff --git a/node_modules/bats-assert/package.json b/node_modules/bats-assert/package.json deleted file mode 100644 index e99eab066..000000000 --- a/node_modules/bats-assert/package.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "name": "bats-assert", - "version": "2.2.4", - "description": "Common assertions for Bats", - "homepage": "https://github.com/bats-core/bats-assert", - "license": "CC0-1.0", - "author": "Zoltán Tömböl (https://github.com/ztombol)", - "contributors": [ - "Sam Stephenson (http://sstephenson.us/)", - "Jason Karns (http://jasonkarns.com)", - "Mislav Marohnić (http://mislav.net/)", - "Tim Pope (https://github.com/tpope)" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/bats-core/bats-assert.git" - }, - "bugs": "https://github.com/bats-core/bats-assert/issues", - "directories": { - "lib": "src", - "test": "test" - }, - "files": [ - "load.bash", - "src" - ], - "scripts": { - "test": "bats ${CI+-t} test", - "postversion": "git push --follow-tags" - }, - "devDependencies": { - "bats": "^1", - "bats-support": "^0.3" - }, - "peerDependencies": { - "bats": "0.4 || ^1", - "bats-support": "^0.3" - }, - "keywords": [ - "bats", - "bash", - "shell", - "test", - "unit", - "assert", - "assertion", - "helper" - ] -} diff --git a/node_modules/bats-assert/src/assert.bash b/node_modules/bats-assert/src/assert.bash deleted file mode 100644 index 0260ce231..000000000 --- a/node_modules/bats-assert/src/assert.bash +++ /dev/null @@ -1,42 +0,0 @@ -# assert -# ====== -# -# Summary: Fail if the given expression evaluates to false. -# -# Usage: assert - -# Options: -# The expression to evaluate for truthiness. -# *__Note:__ The expression must be a simple command. -# [Compound commands](https://www.gnu.org/software/bash/manual/bash.html#Compound-Commands), -# such as `[[`, can be used only when executed with `bash -c`.* -# -# IO: -# STDERR - the failed expression, on failure -# Globals: -# none -# Returns: -# 0 - if expression evaluates to true -# 1 - otherwise -# -# ```bash -# @test 'assert()' { -# touch '/var/log/test.log' -# assert [ -e '/var/log/test.log' ] -# } -# ``` -# -# On failure, the failed expression is displayed. -# -# ``` -# -- assertion failed -- -# expression : [ -e /var/log/test.log ] -# -- -# ``` -assert() { - if ! "$@"; then - batslib_print_kv_single 10 'expression' "$*" \ - | batslib_decorate 'assertion failed' \ - | fail - fi -} diff --git a/node_modules/bats-assert/src/assert_equal.bash b/node_modules/bats-assert/src/assert_equal.bash deleted file mode 100644 index 4ef1297ed..000000000 --- a/node_modules/bats-assert/src/assert_equal.bash +++ /dev/null @@ -1,42 +0,0 @@ -# assert_equal -# ============ -# -# Summary: Fail if the actual and expected values are not equal. -# -# Usage: assert_equal -# -# Options: -# The value being compared. -# The value to compare against. -# -# ```bash -# @test 'assert_equal()' { -# assert_equal 'have' 'want' -# } -# ``` -# -# IO: -# STDERR - expected and actual values, on failure -# Globals: -# none -# Returns: -# 0 - if values equal -# 1 - otherwise -# -# On failure, the expected and actual values are displayed. -# -# ``` -# -- values do not equal -- -# expected : want -# actual : have -# -- -# ``` -assert_equal() { - if [[ $1 != "$2" ]]; then - batslib_print_kv_single_or_multi 8 \ - 'expected' "$2" \ - 'actual' "$1" \ - | batslib_decorate 'values do not equal' \ - | fail - fi -} diff --git a/node_modules/bats-assert/src/assert_failure.bash b/node_modules/bats-assert/src/assert_failure.bash deleted file mode 100644 index 268d44758..000000000 --- a/node_modules/bats-assert/src/assert_failure.bash +++ /dev/null @@ -1,86 +0,0 @@ -# assert_failure -# ============== -# -# Summary: Fail if `$status` is 0; or is not equal to the optionally provided status. -# -# Usage: assert_failure [] -# -# Options: -# The specific status code to check against. -# If not provided, simply asserts status is != 0. -# -# IO: -# STDERR - `$output`, on failure; -# - also, `$status` and `expected_status`, if provided -# Globals: -# status -# output -# Returns: -# 0 - if `$status' is 0, -# or if expected_status is provided but does not equal `$status' -# 1 - otherwise -# -# ```bash -# @test 'assert_failure() status only' { -# run echo 'Success!' -# assert_failure -# } -# ``` -# -# On failure, `$output` is displayed. -# -# ``` -# -- command succeeded, but it was expected to fail -- -# output : Success! -# -- -# ``` -# -# ## Expected status -# -# When `expected_status` is provided, fail if `$status` does not equal the `expected_status`. -# -# ```bash -# @test 'assert_failure() with expected status' { -# run bash -c "echo 'Error!'; exit 1" -# assert_failure 2 -# } -# ``` -# -# On failure, both the expected and actual statuses, and `$output` are displayed. -# -# ``` -# -- command failed as expected, but status differs -- -# expected : 2 -# actual : 1 -# output : Error! -# -- -# ``` -assert_failure() { - : "${output?}" - : "${status?}" - - (( $# > 0 )) && local -r expected="$1" - if (( status == 0 )); then - { local -ir width=6 - batslib_print_kv_single_or_multi "$width" 'output' "$output" - if [[ -n "${stderr-}" ]]; then - batslib_print_kv_single_or_multi "$width" 'stderr' "$stderr" - fi - } \ - | batslib_decorate 'command succeeded, but it was expected to fail' \ - | fail - elif (( $# > 0 )) && (( status != expected )); then - { local -ir width=8 - batslib_print_kv_single "$width" \ - 'expected' "$expected" \ - 'actual' "$status" - batslib_print_kv_single_or_multi "$width" \ - 'output' "$output" - if [[ -n "${stderr-}" ]]; then - batslib_print_kv_single_or_multi "$width" 'stderr' "$stderr" - fi - } \ - | batslib_decorate 'command failed as expected, but status differs' \ - | fail - fi -} diff --git a/node_modules/bats-assert/src/assert_line.bash b/node_modules/bats-assert/src/assert_line.bash deleted file mode 100644 index 0e9cf5b31..000000000 --- a/node_modules/bats-assert/src/assert_line.bash +++ /dev/null @@ -1,298 +0,0 @@ -# assert_line -# =========== -# -# Summary: Fail if the expected line is not found in the output (default) or at a specific line number. -# -# Usage: assert_line [-n index] [-p | -e] [--] -# -# Options: -# -n, --index Match the th line -# -p, --partial Match if `expected` is a substring of `$output` or line -# -e, --regexp Treat `expected` as an extended regular expression -# The expected line string, substring, or regular expression -# -# IO: -# STDERR - details, on failure -# error message, on error -# Globals: -# output -# lines -# Returns: -# 0 - if matching line found -# 1 - otherwise -# -# Similarly to `assert_output`, this function verifies that a command or function produces the expected output. -# (It is the logical complement of `refute_line`.) -# It checks that the expected line appears in the output (default) or at a specific line number. -# Matching can be literal (default), partial or regular expression. -# -# *__Warning:__ -# Due to a [bug in Bats][bats-93], empty lines are discarded from `${lines[@]}`, -# causing line indices to change and preventing testing for empty lines.* -# -# [bats-93]: https://github.com/sstephenson/bats/pull/93 -# -# ## Looking for a line in the output -# -# By default, the entire output is searched for the expected line. -# The assertion fails if the expected line is not found in `${lines[@]}`. -# -# ```bash -# @test 'assert_line() looking for line' { -# run echo $'have-0\nhave-1\nhave-2' -# assert_line 'want' -# } -# ``` -# -# On failure, the expected line and the output are displayed. -# -# ``` -# -- output does not contain line -- -# line : want -# output (3 lines): -# have-0 -# have-1 -# have-2 -# -- -# ``` -# -# ## Matching a specific line -# -# When the `--index ` option is used (`-n ` for short), the expected line is matched only against the line identified by the given index. -# The assertion fails if the expected line does not equal `${lines[]}`. -# -# ```bash -# @test 'assert_line() specific line' { -# run echo $'have-0\nhave-1\nhave-2' -# assert_line --index 1 'want-1' -# } -# ``` -# -# On failure, the index and the compared lines are displayed. -# -# ``` -# -- line differs -- -# index : 1 -# expected : want-1 -# actual : have-1 -# -- -# ``` -# -# ## Partial matching -# -# Partial matching can be enabled with the `--partial` option (`-p` for short). -# When used, a match fails if the expected *substring* is not found in the matched line. -# -# ```bash -# @test 'assert_line() partial matching' { -# run echo $'have 1\nhave 2\nhave 3' -# assert_line --partial 'want' -# } -# ``` -# -# On failure, the same details are displayed as for literal matching, except that the substring replaces the expected line. -# -# ``` -# -- no output line contains substring -- -# substring : want -# output (3 lines): -# have 1 -# have 2 -# have 3 -# -- -# ``` -# -# ## Regular expression matching -# -# Regular expression matching can be enabled with the `--regexp` option (`-e` for short). -# When used, a match fails if the *extended regular expression* does not match the line being tested. -# -# *__Note__: -# As expected, the anchors `^` and `$` bind to the beginning and the end (respectively) of the matched line.* -# -# ```bash -# @test 'assert_line() regular expression matching' { -# run echo $'have-0\nhave-1\nhave-2' -# assert_line --index 1 --regexp '^want-[0-9]$' -# } -# ``` -# -# On failure, the same details are displayed as for literal matching, except that the regular expression replaces the expected line. -# -# ``` -# -- regular expression does not match line -- -# index : 1 -# regexp : ^want-[0-9]$ -# line : have-1 -# -- -# ``` -# FIXME(ztombol): Display `${lines[@]}' instead of `$output'! -assert_line() { - __assert_line "$@" -} - -# assert_stderr_line -# =========== -# -# Summary: Fail if the expected line is not found in the stderr (default) or at a specific line number. -# -# Usage: assert_stderr_line [-n index] [-p | -e] [--] -# -# Options: -# -n, --index Match the th line -# -p, --partial Match if `expected` is a substring of `$stderr` or line -# -e, --regexp Treat `expected` as an extended regular expression -# The expected line string, substring, or regular expression -# -# IO: -# STDERR - details, on failure -# error message, on error -# Globals: -# stderr -# stderr_lines -# Returns: -# 0 - if matching line found -# 1 - otherwise -# -# Similarly to `assert_stderr`, this function verifies that a command or function produces the expected stderr. -# (It is the logical complement of `refute_stderr_line`.) -# It checks that the expected line appears in the stderr (default) or at a specific line number. -# Matching can be literal (default), partial or regular expression. -# -assert_stderr_line() { - __assert_line "$@" -} - -__assert_line() { - local -r caller=${FUNCNAME[1]} - local -i is_match_line=0 - local -i is_mode_partial=0 - local -i is_mode_regexp=0 - - if [[ "${caller}" == "assert_line" ]]; then - : "${lines?}" - local -ar stream_lines=("${lines[@]}") - local -r stream_type=output - elif [[ "${caller}" == "assert_stderr_line" ]]; then - : "${stderr_lines?}" - local -ar stream_lines=("${stderr_lines[@]}") - local -r stream_type=stderr - else - # Unknown caller - echo "Unexpected call to \`${FUNCNAME[0]}\` -Did you mean to call \`assert_line\` or \`assert_stderr_line\`?" \ - | batslib_decorate "ERROR: ${FUNCNAME[0]}" \ - | fail - return $? - fi - - # Handle options. - while (( $# > 0 )); do - case "$1" in - -n|--index) - if (( $# < 2 )) || ! [[ $2 =~ ^-?([0-9]|[1-9][0-9]+)$ ]]; then - echo "\`--index' requires an integer argument: \`$2'" \ - | batslib_decorate "ERROR: ${caller}" \ - | fail - return $? - fi - is_match_line=1 - local -ri idx="$2" - shift 2 - ;; - -p|--partial) is_mode_partial=1; shift ;; - -e|--regexp) is_mode_regexp=1; shift ;; - --) shift; break ;; - *) break ;; - esac - done - - if (( is_mode_partial )) && (( is_mode_regexp )); then - echo "\`--partial' and \`--regexp' are mutually exclusive" \ - | batslib_decorate "ERROR: ${caller}" \ - | fail - return $? - fi - - # Arguments. - local -r expected="$1" - - if (( is_mode_regexp == 1 )); then - __check_is_valid_regex "$expected" "$caller" || return 1 - fi - - # Matching. - if (( is_match_line )); then - # Specific line. - if (( is_mode_regexp )); then - if ! [[ ${stream_lines[$idx]} =~ $expected ]]; then - batslib_print_kv_single 6 \ - 'index' "$idx" \ - 'regexp' "$expected" \ - 'line' "${stream_lines[$idx]}" \ - | batslib_decorate 'regular expression does not match line' \ - | fail - fi - elif (( is_mode_partial )); then - if [[ ${stream_lines[$idx]} != *"$expected"* ]]; then - batslib_print_kv_single 9 \ - 'index' "$idx" \ - 'substring' "$expected" \ - 'line' "${stream_lines[$idx]}" \ - | batslib_decorate 'line does not contain substring' \ - | fail - fi - else - if [[ ${stream_lines[$idx]} != "$expected" ]]; then - batslib_print_kv_single 8 \ - 'index' "$idx" \ - 'expected' "$expected" \ - 'actual' "${stream_lines[$idx]}" \ - | batslib_decorate 'line differs' \ - | fail - fi - fi - else - # Contained in output/error stream. - if (( is_mode_regexp )); then - local -i idx - for (( idx = 0; idx < ${#stream_lines[@]}; ++idx )); do - [[ ${stream_lines[$idx]} =~ $expected ]] && return 0 - done - { local -ar single=( 'regexp' "$expected" ) - local -ar may_be_multi=( "${stream_type}" "${!stream_type}" ) - local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )" - batslib_print_kv_single "$width" "${single[@]}" - batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}" - } \ - | batslib_decorate "no ${stream_type} line matches regular expression" \ - | fail - elif (( is_mode_partial )); then - local -i idx - for (( idx = 0; idx < ${#stream_lines[@]}; ++idx )); do - [[ ${stream_lines[$idx]} == *"$expected"* ]] && return 0 - done - { local -ar single=( 'substring' "$expected" ) - local -ar may_be_multi=( "${stream_type}" "${!stream_type}" ) - local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )" - batslib_print_kv_single "$width" "${single[@]}" - batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}" - } \ - | batslib_decorate "no ${stream_type} line contains substring" \ - | fail - else - local -i idx - for (( idx = 0; idx < ${#stream_lines[@]}; ++idx )); do - [[ ${stream_lines[$idx]} == "$expected" ]] && return 0 - done - { local -ar single=( 'line' "$expected" ) - local -ar may_be_multi=( "${stream_type}" "${!stream_type}" ) - local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )" - batslib_print_kv_single "$width" "${single[@]}" - batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}" - } \ - | batslib_decorate "${stream_type} does not contain line" \ - | fail - fi - fi -} diff --git a/node_modules/bats-assert/src/assert_not_equal.bash b/node_modules/bats-assert/src/assert_not_equal.bash deleted file mode 100644 index 933bb713d..000000000 --- a/node_modules/bats-assert/src/assert_not_equal.bash +++ /dev/null @@ -1,42 +0,0 @@ -# assert_not_equal -# ============ -# -# Summary: Fail if the actual and unexpected values are equal. -# -# Usage: assert_not_equal -# -# Options: -# The value being compared. -# The value to compare against. -# -# ```bash -# @test 'assert_not_equal()' { -# assert_not_equal 'foo' 'foo' -# } -# ``` -# -# IO: -# STDERR - expected and actual values, on failure -# Globals: -# none -# Returns: -# 0 - if actual does not equal unexpected -# 1 - otherwise -# -# On failure, the unexpected and actual values are displayed. -# -# ``` -# -- values should not be equal -- -# unexpected : foo -# actual : foo -# -- -# ``` -assert_not_equal() { - if [[ "$1" == "$2" ]]; then - batslib_print_kv_single_or_multi 10 \ - 'unexpected' "$2" \ - 'actual' "$1" \ - | batslib_decorate 'values should not be equal' \ - | fail - fi -} diff --git a/node_modules/bats-assert/src/assert_output.bash b/node_modules/bats-assert/src/assert_output.bash deleted file mode 100644 index e654ba299..000000000 --- a/node_modules/bats-assert/src/assert_output.bash +++ /dev/null @@ -1,247 +0,0 @@ -# assert_output -# ============= -# -# Summary: Fail if `$output' does not match the expected output. -# -# Usage: assert_output [-p | -e] [- | [--] ] -# -# Options: -# -p, --partial Match if `expected` is a substring of `$output` -# -e, --regexp Treat `expected` as an extended regular expression -# -, --stdin Read `expected` value from STDIN -# The expected value, substring or regular expression -# -# IO: -# STDIN - [=$1] expected output -# STDERR - details, on failure -# error message, on error -# Globals: -# output -# Returns: -# 0 - if output matches the expected value/partial/regexp -# 1 - otherwise -# -# This function verifies that a command or function produces the expected output. -# (It is the logical complement of `refute_output`.) -# Output matching can be literal (the default), partial or by regular expression. -# The expected output can be specified either by positional argument or read from STDIN by passing the `-`/`--stdin` flag. -# -# ## Literal matching -# -# By default, literal matching is performed. -# The assertion fails if `$output` does not equal the expected output. -# -# ```bash -# @test 'assert_output()' { -# run echo 'have' -# assert_output 'want' -# } -# -# @test 'assert_output() with pipe' { -# run echo 'hello' -# echo 'hello' | assert_output - -# } -# -# @test 'assert_output() with herestring' { -# run echo 'hello' -# assert_output - <<< hello -# } -# ``` -# -# On failure, the expected and actual output are displayed. -# -# ``` -# -- output differs -- -# expected : want -# actual : have -# -- -# ``` -# -# ## Existence -# -# To assert that any output exists at all, omit the `expected` argument. -# -# ```bash -# @test 'assert_output()' { -# run echo 'have' -# assert_output -# } -# ``` -# -# On failure, an error message is displayed. -# -# ``` -# -- no output -- -# expected non-empty output, but output was empty -# -- -# ``` -# -# ## Partial matching -# -# Partial matching can be enabled with the `--partial` option (`-p` for short). -# When used, the assertion fails if the expected _substring_ is not found in `$output`. -# -# ```bash -# @test 'assert_output() partial matching' { -# run echo 'ERROR: no such file or directory' -# assert_output --partial 'SUCCESS' -# } -# ``` -# -# On failure, the substring and the output are displayed. -# -# ``` -# -- output does not contain substring -- -# substring : SUCCESS -# output : ERROR: no such file or directory -# -- -# ``` -# -# ## Regular expression matching -# -# Regular expression matching can be enabled with the `--regexp` option (`-e` for short). -# When used, the assertion fails if the *extended regular expression* does not match `$output`. -# -# *__Note__: -# The anchors `^` and `$` bind to the beginning and the end (respectively) of the entire output; -# not individual lines.* -# -# ```bash -# @test 'assert_output() regular expression matching' { -# run echo 'Foobar 0.1.0' -# assert_output --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' -# } -# ``` -# -# On failure, the regular expression and the output are displayed. -# -# ``` -# -- regular expression does not match output -- -# regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ -# output : Foobar 0.1.0 -# -- -# ``` -assert_output() { - __assert_stream "$@" -} - -# assert_stderr -# ============= -# -# Summary: Fail if `$stderr' does not match the expected stderr. -# -# Usage: assert_stderr [-p | -e] [- | [--] ] -# -# Options: -# -p, --partial Match if `expected` is a substring of `$stderr` -# -e, --regexp Treat `expected` as an extended regular expression -# -, --stdin Read `expected` value from STDIN -# The expected value, substring or regular expression -# -# IO: -# STDIN - [=$1] expected stderr -# STDERR - details, on failure -# error message, on error -# Globals: -# stderr -# Returns: -# 0 - if stderr matches the expected value/partial/regexp -# 1 - otherwise -# -# Similarly to `assert_output`, this function verifies that a command or function produces the expected stderr. -# (It is the logical complement of `refute_stderr`.) -# The stderr matching can be literal (the default), partial or by regular expression. -# The expected stderr can be specified either by positional argument or read from STDIN by passing the `-`/`--stdin` flag. -# -assert_stderr() { - __assert_stream "$@" -} - -__assert_stream() { - local -r caller=${FUNCNAME[1]} - local -r stream_type=${caller/assert_/} - local -i is_mode_partial=0 - local -i is_mode_regexp=0 - local -i is_mode_nonempty=0 - local -i use_stdin=0 - - if [[ ${stream_type} == "output" ]]; then - : "${output?}" - elif [[ ${stream_type} == "stderr" ]]; then - : "${stderr?}" - else - # Unknown caller - echo "Unexpected call to \`${FUNCNAME[0]}\` -Did you mean to call \`assert_output\` or \`assert_stderr\`?" | - batslib_decorate "ERROR: ${FUNCNAME[0]}" | - fail - return $? - fi - local -r stream="${!stream_type}" - - # Handle options. - if (( $# == 0 )); then - is_mode_nonempty=1 - fi - - while (( $# > 0 )); do - case "$1" in - -p|--partial) is_mode_partial=1; shift ;; - -e|--regexp) is_mode_regexp=1; shift ;; - -|--stdin) use_stdin=1; shift ;; - --) shift; break ;; - *) break ;; - esac - done - - if (( is_mode_partial )) && (( is_mode_regexp )); then - echo "\`--partial' and \`--regexp' are mutually exclusive" \ - | batslib_decorate "ERROR: ${caller}" \ - | fail - return $? - fi - - # Arguments. - local expected - if (( use_stdin )); then - expected="$(cat -)" - else - expected="${1-}" - fi - - # Matching. - if (( is_mode_nonempty )); then - if [ -z "$stream" ]; then - echo "expected non-empty $stream_type, but $stream_type was empty" \ - | batslib_decorate "no $stream_type" \ - | fail - fi - elif (( is_mode_regexp )); then - # shellcheck disable=2319 - if ! __check_is_valid_regex "$expected" "$caller"; then - return 1 - elif ! [[ $stream =~ $expected ]]; then - batslib_print_kv_single_or_multi 6 \ - 'regexp' "$expected" \ - "$stream_type" "$stream" \ - | batslib_decorate "regular expression does not match $stream_type" \ - | fail - fi - elif (( is_mode_partial )); then - if [[ $stream != *"$expected"* ]]; then - batslib_print_kv_single_or_multi 9 \ - 'substring' "$expected" \ - "$stream_type" "$stream" \ - | batslib_decorate "$stream_type does not contain substring" \ - | fail - fi - else - if [[ $stream != "$expected" ]]; then - batslib_print_kv_single_or_multi 8 \ - 'expected' "$expected" \ - 'actual' "$stream" \ - | batslib_decorate "$stream_type differs" \ - | fail - fi - fi -} diff --git a/node_modules/bats-assert/src/assert_regex.bash b/node_modules/bats-assert/src/assert_regex.bash deleted file mode 100644 index 7bc906a2e..000000000 --- a/node_modules/bats-assert/src/assert_regex.bash +++ /dev/null @@ -1,54 +0,0 @@ -# `assert_regex` -# -# This function is similar to `assert_equal` but uses pattern matching instead -# of equality, by wrapping `[[ value =~ pattern ]]`. -# -# Fail if the value (first parameter) does not match the pattern (second -# parameter). -# -# ```bash -# @test 'assert_regex()' { -# assert_regex 'what' 'x$' -# } -# ``` -# -# On failure, the value and the pattern are displayed. -# -# ``` -# -- values does not match regular expression -- -# value : what -# pattern : x$ -# -- -# ``` -# -# If the value is longer than one line then it is displayed in *multi-line* -# format. -# -# An error is displayed if the specified extended regular expression is invalid. -# -# For description of the matching behavior, refer to the documentation of the -# `=~` operator in the -# [Bash manual]: https://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html. -# Note that the `BASH_REMATCH` array is available immediately after the -# assertion succeeds but is fragile, i.e. prone to being overwritten as a side -# effect of other actions. -assert_regex() { - local -r value="${1}" - local -r pattern="${2}" - - if ! __check_is_valid_regex "$pattern" assert_regex; then - return 1 - elif ! [[ "${value}" =~ ${pattern} ]]; then - if shopt -p nocasematch &>/dev/null; then - local case_sensitive=insensitive - else - local case_sensitive=sensitive - fi - batslib_print_kv_single_or_multi 8 \ - 'value' "${value}" \ - 'pattern' "${pattern}" \ - 'case' "${case_sensitive}" \ - | batslib_decorate 'value does not match regular expression' \ - | fail - fi -} diff --git a/node_modules/bats-assert/src/assert_success.bash b/node_modules/bats-assert/src/assert_success.bash deleted file mode 100644 index e3f074d23..000000000 --- a/node_modules/bats-assert/src/assert_success.bash +++ /dev/null @@ -1,47 +0,0 @@ -# assert_success -# ============== -# -# Summary: Fail if `$status` is not 0. -# -# Usage: assert_success -# -# IO: -# STDERR - `$status` and `$output`, on failure -# Globals: -# status -# output -# Returns: -# 0 - if `$status' is 0 -# 1 - otherwise -# -# ```bash -# @test 'assert_success() status only' { -# run bash -c "echo 'Error!'; exit 1" -# assert_success -# } -# ``` -# -# On failure, `$status` and `$output` are displayed. -# -# ``` -# -- command failed -- -# status : 1 -# output : Error! -# -- -# ``` -assert_success() { - : "${output?}" - : "${status?}" - - if (( status != 0 )); then - { local -ir width=6 - batslib_print_kv_single "$width" 'status' "$status" - batslib_print_kv_single_or_multi "$width" 'output' "$output" - if [[ -n "${stderr-}" ]]; then - batslib_print_kv_single_or_multi "$width" 'stderr' "$stderr" - fi - } \ - | batslib_decorate 'command failed' \ - | fail - fi -} diff --git a/node_modules/bats-assert/src/refute.bash b/node_modules/bats-assert/src/refute.bash deleted file mode 100644 index e7c47da82..000000000 --- a/node_modules/bats-assert/src/refute.bash +++ /dev/null @@ -1,42 +0,0 @@ -# refute -# ====== -# -# Summary: Fail if the given expression evaluates to true. -# -# Usage: refute -# -# Options: -# The expression to evaluate for falsiness. -# *__Note:__ The expression must be a simple command. -# [Compound commands](https://www.gnu.org/software/bash/manual/bash.html#Compound-Commands), -# such as `[[`, can be used only when executed with `bash -c`.* -# -# IO: -# STDERR - the successful expression, on failure -# Globals: -# none -# Returns: -# 0 - if expression evaluates to false -# 1 - otherwise -# -# ```bash -# @test 'refute()' { -# rm -f '/var/log/test.log' -# refute [ -e '/var/log/test.log' ] -# } -# ``` -# -# On failure, the successful expression is displayed. -# -# ``` -# -- assertion succeeded, but it was expected to fail -- -# expression : [ -e /var/log/test.log ] -# -- -# ``` -refute() { - if "$@"; then - batslib_print_kv_single 10 'expression' "$*" \ - | batslib_decorate 'assertion succeeded, but it was expected to fail' \ - | fail - fi -} diff --git a/node_modules/bats-assert/src/refute_line.bash b/node_modules/bats-assert/src/refute_line.bash deleted file mode 100644 index 06628687b..000000000 --- a/node_modules/bats-assert/src/refute_line.bash +++ /dev/null @@ -1,341 +0,0 @@ -# refute_line -# =========== -# -# Summary: Fail if the unexpected line is found in the output (default) or at a specific line number. -# -# Usage: refute_line [-n index] [-p | -e] [--] -# -# Options: -# -n, --index Match the th line -# -p, --partial Match if `unexpected` is a substring of `$output` or line -# -e, --regexp Treat `unexpected` as an extended regular expression -# The unexpected line string, substring, or regular expression. -# -# IO: -# STDERR - details, on failure -# error message, on error -# Globals: -# output -# lines -# Returns: -# 0 - if match not found -# 1 - otherwise -# -# Similarly to `refute_output`, this function verifies that a command or function does not produce the unexpected output. -# (It is the logical complement of `assert_line`.) -# It checks that the unexpected line does not appear in the output (default) or at a specific line number. -# Matching can be literal (default), partial or regular expression. -# -# ## Looking for a line in the output -# -# By default, the entire output is searched for the unexpected line. -# The assertion fails if the unexpected line is found in `${lines[@]}`. -# -# ```bash -# @test 'refute_line() looking for line' { -# run echo $'have-0\nwant\nhave-2' -# refute_line 'want' -# } -# ``` -# -# On failure, the unexpected line, the index of its first match and the output with the matching line highlighted are displayed. -# -# ``` -# -- line should not be in output -- -# line : want -# index : 1 -# output (3 lines): -# have-0 -# > want -# have-2 -# -- -# ``` -# -# ## Matching a specific line -# -# When the `--index ` option is used (`-n ` for short), the unexpected line is matched only against the line identified by the given index. -# The assertion fails if the unexpected line equals `${lines[]}`. -# -# ```bash -# @test 'refute_line() specific line' { -# run echo $'have-0\nwant-1\nhave-2' -# refute_line --index 1 'want-1' -# } -# ``` -# -# On failure, the index and the unexpected line are displayed. -# -# ``` -# -- line should differ -- -# index : 1 -# line : want-1 -# -- -# ``` -# -# ## Partial matching -# -# Partial matching can be enabled with the `--partial` option (`-p` for short). -# When used, a match fails if the unexpected *substring* is found in the matched line. -# -# ```bash -# @test 'refute_line() partial matching' { -# run echo $'have 1\nwant 2\nhave 3' -# refute_line --partial 'want' -# } -# ``` -# -# On failure, in addition to the details of literal matching, the substring is also displayed. -# When used with `--index ` the substring replaces the unexpected line. -# -# ``` -# -- no line should contain substring -- -# substring : want -# index : 1 -# output (3 lines): -# have 1 -# > want 2 -# have 3 -# -- -# ``` -# -# ## Regular expression matching -# -# Regular expression matching can be enabled with the `--regexp` option (`-e` for short). -# When used, a match fails if the *extended regular expression* matches the line being tested. -# -# *__Note__: -# As expected, the anchors `^` and `$` bind to the beginning and the end (respectively) of the matched line.* -# -# ```bash -# @test 'refute_line() regular expression matching' { -# run echo $'Foobar v0.1.0\nRelease date: 2015-11-29' -# refute_line --index 0 --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' -# } -# ``` -# -# On failure, in addition to the details of literal matching, the regular expression is also displayed. -# When used with `--index ` the regular expression replaces the unexpected line. -# -# ``` -# -- regular expression should not match line -- -# index : 0 -# regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ -# line : Foobar v0.1.0 -# -- -# ``` -# FIXME(ztombol): Display `${lines[@]}' instead of `$output'! -refute_line() { - __refute_stream_line "$@" -} - -# refute_stderr_line -# ================== -# -# Summary: Fail if the unexpected line is found in the stderr (default) or at a specific line number. -# -# Usage: refute_stderr_line [-n index] [-p | -e] [--] -# -# Options: -# -n, --index Match the th line -# -p, --partial Match if `unexpected` is a substring of `$stderr` or line -# -e, --regexp Treat `unexpected` as an extended regular expression -# The unexpected line string, substring, or regular expression. -# -# IO: -# STDERR - details, on failure -# error message, on error -# Globals: -# stderr -# stderr_lines -# Returns: -# 0 - if match not found -# 1 - otherwise -# -# Similarly to `refute_stderr`, this function verifies that a command or function does not produce the unexpected stderr. -# (It is the logical complement of `assert_stderr_line`.) -# It checks that the unexpected line does not appear in the stderr (default) or at a specific line number. -# Matching can be literal (default), partial or regular expression. -# -refute_stderr_line() { - __refute_stream_line "$@" -} - -# __check_is_vvalid_regex -# ======================= -# -# Summary: checks if the regex in unexpected is valid, also prints an error message if not. -# IO: -# STDERR - details, on error -# Globals: -# caller - readonly -# Returns: -# 0 - if regex is valid -# 1 - otherwise -__check_is_valid_regex() { # - local -r regex="$1" caller="$2" - local error - error=$([[ '' =~ $regex ]] 2>&1) # capture the detailed error message on Bash >=5.3 - if [[ $? == 2 ]]; then - local err_msg="Invalid extended regular expression: \`$regex'" - if [[ $error =~ (invalid regular expression .*) ]]; then - err_msg="${BASH_REMATCH[1]}" - fi - echo "$err_msg" \ - | batslib_decorate "ERROR: ${caller}" \ - | fail - fi -} - -__refute_stream_line() { - local -r caller=${FUNCNAME[1]} - local -i is_match_line=0 - local -i is_mode_partial=0 - local -i is_mode_regexp=0 - - if [[ "${caller}" == "refute_line" ]]; then - : "${lines?}" - local -ar stream_lines=("${lines[@]}") - local -r stream_type=output - elif [[ "${caller}" == "refute_stderr_line" ]]; then - : "${stderr_lines?}" - local -ar stream_lines=("${stderr_lines[@]}") - local -r stream_type=stderr - else - # Unknown caller - echo "Unexpected call to \`${FUNCNAME[0]}\` -Did you mean to call \`refute_line\` or \`refute_stderr_line\`?" | - batslib_decorate "ERROR: ${FUNCNAME[0]}" | - fail - return $? - fi - - # Handle options. - while (( $# > 0 )); do - case "$1" in - -n|--index) - if (( $# < 2 )) || ! [[ $2 =~ ^-?([0-9]|[1-9][0-9]+)$ ]]; then - echo "\`--index' requires an integer argument: \`$2'" \ - | batslib_decorate "ERROR: ${caller}" \ - | fail - return $? - fi - is_match_line=1 - local -ri idx="$2" - shift 2 - ;; - -p|--partial) is_mode_partial=1; shift ;; - -e|--regexp) is_mode_regexp=1; shift ;; - --) shift; break ;; - *) break ;; - esac - done - - if (( is_mode_partial )) && (( is_mode_regexp )); then - echo "\`--partial' and \`--regexp' are mutually exclusive" \ - | batslib_decorate "ERROR: ${caller}" \ - | fail - return $? - fi - - # Arguments. - local -r unexpected="$1" - - if (( is_mode_regexp == 1 )); then - __check_is_valid_regex "$unexpected" "$caller" || return $? - fi - - # Matching. - if (( is_match_line )); then - # Specific line. - if (( is_mode_regexp )); then - if [[ ${stream_lines[$idx]} =~ $unexpected ]]; then - batslib_print_kv_single 6 \ - 'index' "$idx" \ - 'regexp' "$unexpected" \ - 'line' "${stream_lines[$idx]}" \ - | batslib_decorate 'regular expression should not match line' \ - | fail - fi - elif (( is_mode_partial )); then - if [[ ${stream_lines[$idx]} == *"$unexpected"* ]]; then - batslib_print_kv_single 9 \ - 'index' "$idx" \ - 'substring' "$unexpected" \ - 'line' "${stream_lines[$idx]}" \ - | batslib_decorate 'line should not contain substring' \ - | fail - fi - else - if [[ ${stream_lines[$idx]} == "$unexpected" ]]; then - batslib_print_kv_single 5 \ - 'index' "$idx" \ - 'line' "${stream_lines[$idx]}" \ - | batslib_decorate 'line should differ' \ - | fail - fi - fi - else - # Line contained in output/error stream. - if (( is_mode_regexp )); then - local -i idx - for (( idx = 0; idx < ${#stream_lines[@]}; ++idx )); do - if [[ ${stream_lines[$idx]} =~ $unexpected ]]; then - { local -ar single=( 'regexp' "$unexpected" 'index' "$idx" ) - local -a may_be_multi=( "${stream_type}" "${!stream_type}" ) - local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )" - batslib_print_kv_single "$width" "${single[@]}" - if batslib_is_single_line "${may_be_multi[1]}"; then - batslib_print_kv_single "$width" "${may_be_multi[@]}" - else - may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" | batslib_prefix | batslib_mark '>' "$idx" )" - batslib_print_kv_multi "${may_be_multi[@]}" - fi - } \ - | batslib_decorate 'no line should match the regular expression' \ - | fail - return $? - fi - done - elif (( is_mode_partial )); then - local -i idx - for (( idx = 0; idx < ${#stream_lines[@]}; ++idx )); do - if [[ ${stream_lines[$idx]} == *"$unexpected"* ]]; then - { local -ar single=( 'substring' "$unexpected" 'index' "$idx" ) - local -a may_be_multi=( "${stream_type}" "${!stream_type}" ) - local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )" - batslib_print_kv_single "$width" "${single[@]}" - if batslib_is_single_line "${may_be_multi[1]}"; then - batslib_print_kv_single "$width" "${may_be_multi[@]}" - else - may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" | batslib_prefix | batslib_mark '>' "$idx" )" - batslib_print_kv_multi "${may_be_multi[@]}" - fi - } \ - | batslib_decorate 'no line should contain substring' \ - | fail - return $? - fi - done - else - local -i idx - for (( idx = 0; idx < ${#stream_lines[@]}; ++idx )); do - if [[ ${stream_lines[$idx]} == "$unexpected" ]]; then - { local -ar single=( 'line' "$unexpected" 'index' "$idx" ) - local -a may_be_multi=( "${stream_type}" "${!stream_type}" ) - local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )" - batslib_print_kv_single "$width" "${single[@]}" - if batslib_is_single_line "${may_be_multi[1]}"; then - batslib_print_kv_single "$width" "${may_be_multi[@]}" - else - may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" | batslib_prefix | batslib_mark '>' "$idx" )" - batslib_print_kv_multi "${may_be_multi[@]}" - fi - } \ - | batslib_decorate "line should not be in ${stream_type}" \ - | fail - return $? - fi - done - fi - fi -} diff --git a/node_modules/bats-assert/src/refute_output.bash b/node_modules/bats-assert/src/refute_output.bash deleted file mode 100644 index 83d859ae7..000000000 --- a/node_modules/bats-assert/src/refute_output.bash +++ /dev/null @@ -1,243 +0,0 @@ -# refute_output -# ============= -# -# Summary: Fail if `$output' matches the unexpected output. -# -# Usage: refute_output [-p | -e] [- | [--] ] -# -# Options: -# -p, --partial Match if `unexpected` is a substring of `$output` -# -e, --regexp Treat `unexpected` as an extended regular expression -# -, --stdin Read `unexpected` value from STDIN -# The unexpected value, substring, or regular expression -# -# IO: -# STDIN - [=$1] unexpected output -# STDERR - details, on failure -# error message, on error -# Globals: -# output -# Returns: -# 0 - if output matches the unexpected value/partial/regexp -# 1 - otherwise -# -# This function verifies that a command or function does not produce the unexpected output. -# (It is the logical complement of `assert_output`.) -# Output matching can be literal (the default), partial or by regular expression. -# The unexpected output can be specified either by positional argument or read from STDIN by passing the `-`/`--stdin` flag. -# -# ## Literal matching -# -# By default, literal matching is performed. -# The assertion fails if `$output` equals the unexpected output. -# -# ```bash -# @test 'refute_output()' { -# run echo 'want' -# refute_output 'want' -# } -# -# @test 'refute_output() with pipe' { -# run echo 'hello' -# echo 'world' | refute_output - -# } -# -# @test 'refute_output() with herestring' { -# run echo 'hello' -# refute_output - <<< world -# } -# ``` -# -# On failure, the output is displayed. -# -# ``` -# -- output equals, but it was expected to differ -- -# output : want -# -- -# ``` -# -# ## Existence -# -# To assert that there is no output at all, omit the matching argument. -# -# ```bash -# @test 'refute_output()' { -# run foo --silent -# refute_output -# } -# ``` -# -# On failure, an error message is displayed. -# -# ``` -# -- unexpected output -- -# expected no output, but output was non-empty -# -- -# ``` -# -# ## Partial matching -# -# Partial matching can be enabled with the `--partial` option (`-p` for short). -# When used, the assertion fails if the unexpected _substring_ is found in `$output`. -# -# ```bash -# @test 'refute_output() partial matching' { -# run echo 'ERROR: no such file or directory' -# refute_output --partial 'ERROR' -# } -# ``` -# -# On failure, the substring and the output are displayed. -# -# ``` -# -- output should not contain substring -- -# substring : ERROR -# output : ERROR: no such file or directory -# -- -# ``` -# -# ## Regular expression matching -# -# Regular expression matching can be enabled with the `--regexp` option (`-e` for short). -# When used, the assertion fails if the *extended regular expression* matches `$output`. -# -# *__Note__: -# The anchors `^` and `$` bind to the beginning and the end (respectively) of the entire output; -# not individual lines.* -# -# ```bash -# @test 'refute_output() regular expression matching' { -# run echo 'Foobar v0.1.0' -# refute_output --regexp '^Foobar v[0-9]+\.[0-9]+\.[0-9]$' -# } -# ``` -# -# On failure, the regular expression and the output are displayed. -# -# ``` -# -- regular expression should not match output -- -# regexp : ^Foobar v[0-9]+\.[0-9]+\.[0-9]$ -# output : Foobar v0.1.0 -# -- -# ``` -refute_output() { - __refute_stream "$@" -} - -# refute_stderr -# ============= -# -# Summary: Fail if `$stderr' matches the unexpected output. -# -# Usage: refute_stderr [-p | -e] [- | [--] ] -# -# Options: -# -p, --partial Match if `unexpected` is a substring of `$stderr` -# -e, --regexp Treat `unexpected` as an extended regular expression -# -, --stdin Read `unexpected` value from STDIN -# The unexpected value, substring, or regular expression -# -# IO: -# STDIN - [=$1] unexpected stderr -# STDERR - details, on failure -# error message, on error -# Globals: -# stderr -# Returns: -# 0 - if stderr matches the unexpected value/partial/regexp -# 1 - otherwise -# -# Similar to `refute_output`, this function verifies that a command or function does not produce the unexpected stderr. -# (It is the logical complement of `assert_stderr`.) -# The stderr matching can be literal (the default), partial or by regular expression. -# The unexpected stderr can be specified either by positional argument or read from STDIN by passing the `-`/`--stdin` flag. -# -refute_stderr() { - __refute_stream "$@" -} - -__refute_stream() { - local -r caller=${FUNCNAME[1]} - local -r stream_type=${caller/refute_/} - local -i is_mode_partial=0 - local -i is_mode_regexp=0 - local -i is_mode_empty=0 - local -i use_stdin=0 - - if [[ ${stream_type} == "output" ]]; then - : "${output?}" - elif [[ ${stream_type} == "stderr" ]]; then - : "${stderr?}" - else - # Not reachable: should be either output or stderr - : - fi - local -r stream="${!stream_type}" - - # Handle options. - if (( $# == 0 )); then - is_mode_empty=1 - fi - - while (( $# > 0 )); do - case "$1" in - -p|--partial) is_mode_partial=1; shift ;; - -e|--regexp) is_mode_regexp=1; shift ;; - -|--stdin) use_stdin=1; shift ;; - --) shift; break ;; - *) break ;; - esac - done - - if (( is_mode_partial )) && (( is_mode_regexp )); then - echo "\`--partial' and \`--regexp' are mutually exclusive" \ - | batslib_decorate "ERROR: ${caller}" \ - | fail - return $? - fi - - # Arguments. - local unexpected - if (( use_stdin )); then - unexpected="$(cat -)" - else - unexpected="${1-}" - fi - - if (( is_mode_regexp == 1 )); then - __check_is_valid_regex "$unexpected" "$caller" || return 1 - fi - - # Matching. - if (( is_mode_empty )); then - if [ -n "${stream}" ]; then - batslib_print_kv_single_or_multi 6 \ - "${stream_type}" "${stream}" \ - | batslib_decorate "${stream_type} non-empty, but expected no ${stream_type}" \ - | fail - fi - elif (( is_mode_regexp )); then - if [[ ${stream} =~ $unexpected ]]; then - batslib_print_kv_single_or_multi 6 \ - 'regexp' "$unexpected" \ - "${stream_type}" "${stream}" \ - | batslib_decorate "regular expression should not match ${stream_type}" \ - | fail - fi - elif (( is_mode_partial )); then - if [[ ${stream} == *"$unexpected"* ]]; then - batslib_print_kv_single_or_multi 9 \ - 'substring' "$unexpected" \ - "${stream_type}" "${stream}" \ - | batslib_decorate "${stream_type} should not contain substring" \ - | fail - fi - else - if [[ ${stream} == "$unexpected" ]]; then - batslib_print_kv_single_or_multi 6 \ - "${stream_type}" "${stream}" \ - | batslib_decorate "${stream_type} equals, but it was expected to differ" \ - | fail - fi - fi -} diff --git a/node_modules/bats-assert/src/refute_regex.bash b/node_modules/bats-assert/src/refute_regex.bash deleted file mode 100644 index f998cc416..000000000 --- a/node_modules/bats-assert/src/refute_regex.bash +++ /dev/null @@ -1,64 +0,0 @@ -# `refute_regex` -# -# This function is similar to `refute_equal` but uses pattern matching instead -# of equality, by wrapping `! [[ value =~ pattern ]]`. -# -# Fail if the value (first parameter) matches the pattern (second parameter). -# -# ```bash -# @test 'refute_regex()' { -# refute_regex 'WhatsApp' 'Threema' -# } -# ``` -# -# On failure, the value, the pattern and the match are displayed. -# -# ``` -# @test 'refute_regex()' { -# refute_regex 'WhatsApp' 'What.' -# } -# -# -- value matches regular expression -- -# value : WhatsApp -# pattern : What. -# match : Whats -# case : sensitive -# -- -# ``` -# -# If the value or pattern is longer than one line then it is displayed in -# *multi-line* format. -# -# An error is displayed if the specified extended regular expression is invalid. -# -# For description of the matching behavior, refer to the documentation of the -# `=~` operator in the -# [Bash manual]: https://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html. -# -# Note that the `BASH_REMATCH` array is available immediately after the -# assertion fails but is fragile, i.e. prone to being overwritten as a side -# effect of other actions like calling `run`. Thus, it's good practice to avoid -# using `BASH_REMATCH` in conjunction with `refute_regex()`. The valuable -# information the array contains is the matching part of the value which is -# printed in the failing test log, as mentioned above. -refute_regex() { - local -r value="${1}" - local -r pattern="${2}" - - if ! __check_is_valid_regex "${pattern}" "${FUNCNAME[0]}"; then - return 1 - elif [[ "${value}" =~ ${pattern} ]]; then - if shopt -p nocasematch &>/dev/null; then - local case_sensitive=insensitive - else - local case_sensitive=sensitive - fi - batslib_print_kv_single_or_multi 8 \ - 'value' "${value}" \ - 'pattern' "${pattern}" \ - 'match' "${BASH_REMATCH[0]}" \ - 'case' "${case_sensitive}" \ - | batslib_decorate 'value matches regular expression' \ - | fail - fi -} diff --git a/node_modules/bats-support/CHANGELOG.md b/node_modules/bats-support/CHANGELOG.md deleted file mode 100644 index 324d247a7..000000000 --- a/node_modules/bats-support/CHANGELOG.md +++ /dev/null @@ -1,46 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -This project adheres to [Semantic Versioning](http://semver.org/). - - -## [0.3.0] - 2016-11-29 - -### Added - -- Restricting invocation to specific locations with - `batslib_is_caller()` - - -## [0.2.0] - 2016-03-22 - -### Added - -- `npm` support -- Reporting arbitrary failures with `fail()` (moved from `bats-assert`) - -### Changed - -- Library renamed to `bats-support` - - -## 0.1.0 - 2016-02-16 - -### Added - -- Two-column key-value formatting with `batslib_print_kv_single()` -- Multi-line key-value formatting with `batslib_print_kv_multi()` -- Mixed formatting with `batslib_print_kv_single_or_multi()` -- Header and footer decoration with `batslib_decorate()` -- Prefixing lines with `batslib_prefix()` -- Marking lines with `batslib_mark()` -- Common output function `batslib_err()` -- Line counting with `batslib_count_lines()` -- Checking whether a text is one line long with - `batslib_is_single_line()` -- Determining key width for two-column and mixed formatting with - `batslib_get_max_single_line_key_width()` - - -[0.3.0]: https://github.com/ztombol/bats-support/compare/v0.2.0...v0.3.0 -[0.2.0]: https://github.com/ztombol/bats-support/compare/v0.1.0...v0.2.0 diff --git a/node_modules/bats-support/LICENSE b/node_modules/bats-support/LICENSE deleted file mode 100644 index 670154e35..000000000 --- a/node_modules/bats-support/LICENSE +++ /dev/null @@ -1,116 +0,0 @@ -CC0 1.0 Universal - -Statement of Purpose - -The laws of most jurisdictions throughout the world automatically confer -exclusive Copyright and Related Rights (defined below) upon the creator and -subsequent owner(s) (each and all, an "owner") of an original work of -authorship and/or a database (each, a "Work"). - -Certain owners wish to permanently relinquish those rights to a Work for the -purpose of contributing to a commons of creative, cultural and scientific -works ("Commons") that the public can reliably and without fear of later -claims of infringement build upon, modify, incorporate in other works, reuse -and redistribute as freely as possible in any form whatsoever and for any -purposes, including without limitation commercial purposes. These owners may -contribute to the Commons to promote the ideal of a free culture and the -further production of creative, cultural and scientific works, or to gain -reputation or greater distribution for their Work in part through the use and -efforts of others. - -For these and/or other purposes and motivations, and without any expectation -of additional consideration or compensation, the person associating CC0 with a -Work (the "Affirmer"), to the extent that he or she is an owner of Copyright -and Related Rights in the Work, voluntarily elects to apply CC0 to the Work -and publicly distribute the Work under its terms, with knowledge of his or her -Copyright and Related Rights in the Work and the meaning and intended legal -effect of CC0 on those rights. - -1. Copyright and Related Rights. A Work made available under CC0 may be -protected by copyright and related or neighboring rights ("Copyright and -Related Rights"). Copyright and Related Rights include, but are not limited -to, the following: - - i. the right to reproduce, adapt, distribute, perform, display, communicate, - and translate a Work; - - ii. moral rights retained by the original author(s) and/or performer(s); - - iii. publicity and privacy rights pertaining to a person's image or likeness - depicted in a Work; - - iv. rights protecting against unfair competition in regards to a Work, - subject to the limitations in paragraph 4(a), below; - - v. rights protecting the extraction, dissemination, use and reuse of data in - a Work; - - vi. database rights (such as those arising under Directive 96/9/EC of the - European Parliament and of the Council of 11 March 1996 on the legal - protection of databases, and under any national implementation thereof, - including any amended or successor version of such directive); and - - vii. other similar, equivalent or corresponding rights throughout the world - based on applicable law or treaty, and any national implementations thereof. - -2. Waiver. To the greatest extent permitted by, but not in contravention of, -applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and -unconditionally waives, abandons, and surrenders all of Affirmer's Copyright -and Related Rights and associated claims and causes of action, whether now -known or unknown (including existing as well as future claims and causes of -action), in the Work (i) in all territories worldwide, (ii) for the maximum -duration provided by applicable law or treaty (including future time -extensions), (iii) in any current or future medium and for any number of -copies, and (iv) for any purpose whatsoever, including without limitation -commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes -the Waiver for the benefit of each member of the public at large and to the -detriment of Affirmer's heirs and successors, fully intending that such Waiver -shall not be subject to revocation, rescission, cancellation, termination, or -any other legal or equitable action to disrupt the quiet enjoyment of the Work -by the public as contemplated by Affirmer's express Statement of Purpose. - -3. Public License Fallback. Should any part of the Waiver for any reason be -judged legally invalid or ineffective under applicable law, then the Waiver -shall be preserved to the maximum extent permitted taking into account -Affirmer's express Statement of Purpose. In addition, to the extent the Waiver -is so judged Affirmer hereby grants to each affected person a royalty-free, -non transferable, non sublicensable, non exclusive, irrevocable and -unconditional license to exercise Affirmer's Copyright and Related Rights in -the Work (i) in all territories worldwide, (ii) for the maximum duration -provided by applicable law or treaty (including future time extensions), (iii) -in any current or future medium and for any number of copies, and (iv) for any -purpose whatsoever, including without limitation commercial, advertising or -promotional purposes (the "License"). The License shall be deemed effective as -of the date CC0 was applied by Affirmer to the Work. Should any part of the -License for any reason be judged legally invalid or ineffective under -applicable law, such partial invalidity or ineffectiveness shall not -invalidate the remainder of the License, and in such case Affirmer hereby -affirms that he or she will not (i) exercise any of his or her remaining -Copyright and Related Rights in the Work or (ii) assert any associated claims -and causes of action with respect to the Work, in either case contrary to -Affirmer's express Statement of Purpose. - -4. Limitations and Disclaimers. - - a. No trademark or patent rights held by Affirmer are waived, abandoned, - surrendered, licensed or otherwise affected by this document. - - b. Affirmer offers the Work as-is and makes no representations or warranties - of any kind concerning the Work, express, implied, statutory or otherwise, - including without limitation warranties of title, merchantability, fitness - for a particular purpose, non infringement, or the absence of latent or - other defects, accuracy, or the present or absence of errors, whether or not - discoverable, all to the greatest extent permissible under applicable law. - - c. Affirmer disclaims responsibility for clearing rights of other persons - that may apply to the Work or any use thereof, including without limitation - any person's Copyright and Related Rights in the Work. Further, Affirmer - disclaims responsibility for obtaining any necessary consents, permissions - or other rights required for any use of the Work. - - d. Affirmer understands and acknowledges that Creative Commons is not a - party to this document and has no duty or obligation with respect to this - CC0 or use of the Work. - -For more information, please see - diff --git a/node_modules/bats-support/README.md b/node_modules/bats-support/README.md deleted file mode 100644 index 71c02ba9c..000000000 --- a/node_modules/bats-support/README.md +++ /dev/null @@ -1,189 +0,0 @@ -*__Important:__ `bats-core` has been renamed to `bats-support`. GitHub -automatically redirects all references, e.g. submodules and clones will -continue to work, but you are encouraged to [update][github-rename] -them. Version numbering continues where `bats-core` left off.* - -[github-rename]: https://help.github.com/articles/renaming-a-repository/ - -- - - - - - -# bats-support - -[![GitHub license](https://img.shields.io/badge/license-CC0-blue.svg)](https://raw.githubusercontent.com/ztombol/bats-support/master/LICENSE) -[![GitHub release](https://img.shields.io/github/release/ztombol/bats-support.svg)](https://github.com/ztombol/bats-support/releases/latest) -[![Build Status](https://travis-ci.org/ztombol/bats-support.svg?branch=master)](https://travis-ci.org/ztombol/bats-support) - -`bats-support` is a supporting library providing common functions to -test helper libraries written for [Bats][bats]. - -Features: -- [error reporting](#error-reporting) -- [output formatting](#output-formatting) -- [language tools](#language-and-execution) - -See the [shared documentation][bats-docs] to learn how to install and -load this library. - -If you want to use this library in your own helpers or just want to -learn about its internals see the developer documentation in the [source -files](src). - - -## Error reporting - -### `fail` - -Display an error message and fail. This function provides a convenient -way to report failure in arbitrary situations. You can use it to -implement your own helpers when the ones available do not meet your -needs. Other functions use it internally as well. - -```bash -@test 'fail()' { - fail 'this test always fails' -} -``` - -The message can also be specified on the standard input. - -```bash -@test 'fail() with pipe' { - echo 'this test always fails' | fail -} -``` - -This function always fails and simply outputs the given message. - -``` -this test always fails -``` - - -## Output formatting - -Many test helpers need to produce human readable output. This library -provides a simple way to format simple messages and key value pairs, and -display them on the standard error. - - -### Simple message - -Simple messages without structure, e.g. one-line error messages, are -simply wrapped in a header and a footer to help them stand out. - -``` --- ERROR: assert_output -- -`--partial' and `--regexp' are mutually exclusive --- -``` - - -### Key-Value pairs - -Some helpers, e.g. [assertions][bats-assert], structure output as -key-value pairs. This library provides two ways to format them. - -When the value is one line long, a pair can be displayed in a columnar -fashion called ***two-column*** format. - -``` --- output differs -- -expected : want -actual : have --- -``` - -When the value is longer than one line, the key and value must be -displayed on separate lines. First, the key is displayed along with the -number of lines in the value. Then, the value, indented by two spaces -for added readability, starting on the next line. This is called -***multi-line*** format. - -``` --- command failed -- -status : 1 -output (2 lines): - Error! Something went terribly wrong! - Our engineers are panicing... \`>`;/ --- -``` - -Sometimes, for clarity, it is a good idea to display related values also -in this format, even if they are just one line long. - -``` --- output differs -- -expected (1 lines): - want -actual (3 lines): - have 1 - have 2 - have 3 --- -``` - -## Language and Execution - -### Restricting invocation to specific locations - -Sometimes a helper may work properly only when called from a certain -location. Because it depends on variables to be set or some other side -effect. - -A good example is cleaning up temporary files only if the test has -succeeded. The outcome of a test is only available in `teardown`. Thus, -to avoid programming mistakes, it makes sense to restrict such a -clean-up helper to that function. - -`batslib_is_caller` checks the call stack and returns `0` if the caller -was invoked from a given function, and `1` otherwise. This function -becomes really useful with the `--indirect` option, which allows calls -through intermediate functions, e.g. the calling function may be called -from a function that was called from the given function. - -Staying with the example above, the following code snippet implements a -helper that is restricted to `teardown` or any function called -indirectly from it. - -```shell -clean_up() { - # Check caller. - if batslib_is_caller --indirect 'teardown'; then - echo "Must be called from \`teardown'" \ - | batslib_decorate 'ERROR: clean_up' \ - | fail - return $? - fi - - # Body goes here... -} -``` - -In some cases a helper may be called from multiple locations. For -example, a logging function that uses the test name, description or -number, information only available in `setup`, `@test` or `teardown`, to -distinguish entries. The following snippet implements this restriction. - -```shell -log_test() { - # Check caller. - if ! ( batslib_is_caller --indirect 'setup' \ - || batslib_is_caller --indirect "$BATS_TEST_NAME" \ - || batslib_is_caller --indirect 'teardown' ) - then - echo "Must be called from \`setup', \`@test' or \`teardown'" \ - | batslib_decorate 'ERROR: log_test' \ - | fail - return $? - fi - - # Body goes here... -} -``` - - - - -[bats]: https://github.com/sstephenson/bats -[bats-docs]: https://github.com/ztombol/bats-docs -[bats-assert]: https://github.com/ztombol/bats-assert diff --git a/node_modules/bats-support/load.bash b/node_modules/bats-support/load.bash deleted file mode 100644 index 0727aebae..000000000 --- a/node_modules/bats-support/load.bash +++ /dev/null @@ -1,3 +0,0 @@ -source "$(dirname "${BASH_SOURCE[0]}")/src/output.bash" -source "$(dirname "${BASH_SOURCE[0]}")/src/error.bash" -source "$(dirname "${BASH_SOURCE[0]}")/src/lang.bash" diff --git a/node_modules/bats-support/package.json b/node_modules/bats-support/package.json deleted file mode 100644 index 501568770..000000000 --- a/node_modules/bats-support/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "bats-support", - "version": "0.3.0", - "description": "Supporting library for Bats test helpers", - "homepage": "https://github.com/jasonkarns/bats-support", - "license": "CC0-1.0", - "author": "Zoltán Tömböl (https://github.com/ztombol)", - "contributors": [ - "Jason Karns (http://jason.karns.name)" - ], - "repository": "github:jasonkarns/bats-support", - "bugs": "https://github.com/jasonkarns/bats-support/issues", - "directories": { - "lib": "src", - "test": "test" - }, - "files": [ - "load.bash", - "src" - ], - "scripts": { - "test": "bats ${CI+-t} test" - }, - "devDependencies": { - "bats": "^1" - }, - "peerDependencies": { - "bats": "0.4 || ^1" - } -} diff --git a/node_modules/bats-support/src/error.bash b/node_modules/bats-support/src/error.bash deleted file mode 100644 index e5d97912e..000000000 --- a/node_modules/bats-support/src/error.bash +++ /dev/null @@ -1,41 +0,0 @@ -# -# bats-support - Supporting library for Bats test helpers -# -# Written in 2016 by Zoltan Tombol -# -# To the extent possible under law, the author(s) have dedicated all -# copyright and related and neighboring rights to this software to the -# public domain worldwide. This software is distributed without any -# warranty. -# -# You should have received a copy of the CC0 Public Domain Dedication -# along with this software. If not, see -# . -# - -# -# error.bash -# ---------- -# -# Functions implementing error reporting. Used by public helper -# functions or test suits directly. -# - -# Fail and display a message. When no parameters are specified, the -# message is read from the standard input. Other functions use this to -# report failure. -# -# Globals: -# none -# Arguments: -# $@ - [=STDIN] message -# Returns: -# 1 - always -# Inputs: -# STDIN - [=$@] message -# Outputs: -# STDERR - message -fail() { - (( $# == 0 )) && batslib_err || batslib_err "$@" - return 1 -} diff --git a/node_modules/bats-support/src/lang.bash b/node_modules/bats-support/src/lang.bash deleted file mode 100644 index c57e299c6..000000000 --- a/node_modules/bats-support/src/lang.bash +++ /dev/null @@ -1,73 +0,0 @@ -# -# bats-util - Various auxiliary functions for Bats -# -# Written in 2016 by Zoltan Tombol -# -# To the extent possible under law, the author(s) have dedicated all -# copyright and related and neighboring rights to this software to the -# public domain worldwide. This software is distributed without any -# warranty. -# -# You should have received a copy of the CC0 Public Domain Dedication -# along with this software. If not, see -# . -# - -# -# lang.bash -# --------- -# -# Bash language and execution related functions. Used by public helper -# functions. -# - -# Check whether the calling function was called from a given function. -# -# By default, direct invocation is checked. The function succeeds if the -# calling function was called directly from the given function. In other -# words, if the given function is the next element on the call stack. -# -# When `--indirect' is specified, indirect invocation is checked. The -# function succeeds if the calling function was called from the given -# function with any number of intermediate calls. In other words, if the -# given function can be found somewhere on the call stack. -# -# Direct invocation is a form of indirect invocation with zero -# intermediate calls. -# -# Globals: -# FUNCNAME -# Options: -# -i, --indirect - check indirect invocation -# Arguments: -# $1 - calling function's name -# Returns: -# 0 - current function was called from the given function -# 1 - otherwise -batslib_is_caller() { - local -i is_mode_direct=1 - - # Handle options. - while (( $# > 0 )); do - case "$1" in - -i|--indirect) is_mode_direct=0; shift ;; - --) shift; break ;; - *) break ;; - esac - done - - # Arguments. - local -r func="$1" - - # Check call stack. - if (( is_mode_direct )); then - [[ $func == "${FUNCNAME[2]}" ]] && return 0 - else - local -i depth - for (( depth=2; depth<${#FUNCNAME[@]}; ++depth )); do - [[ $func == "${FUNCNAME[$depth]}" ]] && return 0 - done - fi - - return 1 -} diff --git a/node_modules/bats-support/src/output.bash b/node_modules/bats-support/src/output.bash deleted file mode 100644 index c6cf6a6b8..000000000 --- a/node_modules/bats-support/src/output.bash +++ /dev/null @@ -1,279 +0,0 @@ -# -# bats-support - Supporting library for Bats test helpers -# -# Written in 2016 by Zoltan Tombol -# -# To the extent possible under law, the author(s) have dedicated all -# copyright and related and neighboring rights to this software to the -# public domain worldwide. This software is distributed without any -# warranty. -# -# You should have received a copy of the CC0 Public Domain Dedication -# along with this software. If not, see -# . -# - -# -# output.bash -# ----------- -# -# Private functions implementing output formatting. Used by public -# helper functions. -# - -# Print a message to the standard error. When no parameters are -# specified, the message is read from the standard input. -# -# Globals: -# none -# Arguments: -# $@ - [=STDIN] message -# Returns: -# none -# Inputs: -# STDIN - [=$@] message -# Outputs: -# STDERR - message -batslib_err() { - { if (( $# > 0 )); then - echo "$@" - else - cat - - fi - } >&2 -} - -# Count the number of lines in the given string. -# -# TODO(ztombol): Fix tests and remove this note after #93 is resolved! -# NOTE: Due to a bug in Bats, `batslib_count_lines "$output"' does not -# give the same result as `${#lines[@]}' when the output contains -# empty lines. -# See PR #93 (https://github.com/sstephenson/bats/pull/93). -# -# Globals: -# none -# Arguments: -# $1 - string -# Returns: -# none -# Outputs: -# STDOUT - number of lines -batslib_count_lines() { - local -i n_lines=0 - local line - while IFS='' read -r line || [[ -n $line ]]; do - (( ++n_lines )) - done < <(printf '%s' "$1") - echo "$n_lines" -} - -# Determine whether all strings are single-line. -# -# Globals: -# none -# Arguments: -# $@ - strings -# Returns: -# 0 - all strings are single-line -# 1 - otherwise -batslib_is_single_line() { - for string in "$@"; do - (( $(batslib_count_lines "$string") > 1 )) && return 1 - done - return 0 -} - -# Determine the length of the longest key that has a single-line value. -# -# This function is useful in determining the correct width of the key -# column in two-column format when some keys may have multi-line values -# and thus should be excluded. -# -# Globals: -# none -# Arguments: -# $odd - key -# $even - value of the previous key -# Returns: -# none -# Outputs: -# STDOUT - length of longest key -batslib_get_max_single_line_key_width() { - local -i max_len=-1 - while (( $# != 0 )); do - local -i key_len="${#1}" - batslib_is_single_line "$2" && (( key_len > max_len )) && max_len="$key_len" - shift 2 - done - echo "$max_len" -} - -# Print key-value pairs in two-column format. -# -# Keys are displayed in the first column, and their corresponding values -# in the second. To evenly line up values, the key column is fixed-width -# and its width is specified with the first parameter (possibly computed -# using `batslib_get_max_single_line_key_width'). -# -# Globals: -# none -# Arguments: -# $1 - width of key column -# $even - key -# $odd - value of the previous key -# Returns: -# none -# Outputs: -# STDOUT - formatted key-value pairs -batslib_print_kv_single() { - local -ir col_width="$1"; shift - while (( $# != 0 )); do - printf '%-*s : %s\n' "$col_width" "$1" "$2" - shift 2 - done -} - -# Print key-value pairs in multi-line format. -# -# The key is displayed first with the number of lines of its -# corresponding value in parenthesis. Next, starting on the next line, -# the value is displayed. For better readability, it is recommended to -# indent values using `batslib_prefix'. -# -# Globals: -# none -# Arguments: -# $odd - key -# $even - value of the previous key -# Returns: -# none -# Outputs: -# STDOUT - formatted key-value pairs -batslib_print_kv_multi() { - while (( $# != 0 )); do - printf '%s (%d lines):\n' "$1" "$( batslib_count_lines "$2" )" - printf '%s\n' "$2" - shift 2 - done -} - -# Print all key-value pairs in either two-column or multi-line format -# depending on whether all values are single-line. -# -# If all values are single-line, print all pairs in two-column format -# with the specified key column width (identical to using -# `batslib_print_kv_single'). -# -# Otherwise, print all pairs in multi-line format after indenting values -# with two spaces for readability (identical to using `batslib_prefix' -# and `batslib_print_kv_multi') -# -# Globals: -# none -# Arguments: -# $1 - width of key column (for two-column format) -# $even - key -# $odd - value of the previous key -# Returns: -# none -# Outputs: -# STDOUT - formatted key-value pairs -batslib_print_kv_single_or_multi() { - local -ir width="$1"; shift - local -a pairs=( "$@" ) - - local -a values=() - local -i i - for (( i=1; i < ${#pairs[@]}; i+=2 )); do - values+=( "${pairs[$i]}" ) - done - - if batslib_is_single_line "${values[@]}"; then - batslib_print_kv_single "$width" "${pairs[@]}" - else - local -i i - for (( i=1; i < ${#pairs[@]}; i+=2 )); do - pairs[$i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )" - done - batslib_print_kv_multi "${pairs[@]}" - fi -} - -# Prefix each line read from the standard input with the given string. -# -# Globals: -# none -# Arguments: -# $1 - [= ] prefix string -# Returns: -# none -# Inputs: -# STDIN - lines -# Outputs: -# STDOUT - prefixed lines -batslib_prefix() { - local -r prefix="${1:- }" - local line - while IFS='' read -r line || [[ -n $line ]]; do - printf '%s%s\n' "$prefix" "$line" - done -} - -# Mark select lines of the text read from the standard input by -# overwriting their beginning with the given string. -# -# Usually the input is indented by a few spaces using `batslib_prefix' -# first. -# -# Globals: -# none -# Arguments: -# $1 - marking string -# $@ - indices (zero-based) of lines to mark -# Returns: -# none -# Inputs: -# STDIN - lines -# Outputs: -# STDOUT - lines after marking -batslib_mark() { - local -r symbol="$1"; shift - # Sort line numbers. - set -- $( sort -nu <<< "$( printf '%d\n' "$@" )" ) - - local line - local -i idx=0 - while IFS='' read -r line || [[ -n $line ]]; do - if (( ${1:--1} == idx )); then - printf '%s\n' "${symbol}${line:${#symbol}}" - shift - else - printf '%s\n' "$line" - fi - (( ++idx )) - done -} - -# Enclose the input text in header and footer lines. -# -# The header contains the given string as title. The output is preceded -# and followed by an additional newline to make it stand out more. -# -# Globals: -# none -# Arguments: -# $1 - title -# Returns: -# none -# Inputs: -# STDIN - text -# Outputs: -# STDOUT - decorated text -batslib_decorate() { - echo - echo "-- $1 --" - cat - - echo '--' - echo -} diff --git a/package-lock.json b/package-lock.json index beb0a3088..405cfe586 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "pr-840", + "name": "pr-893", "lockfileVersion": 3, "requires": true, "packages": {