Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bats-core/bats-assert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoltan Tombol <zoltan.tombol@gmail.com>2016-02-26 21:23:20 +0300
committerZoltan Tombol <zoltan.tombol@gmail.com>2016-02-26 21:23:20 +0300
commitbd7ece6cb495ba2f4cb7360226c6ba4966c1b7f6 (patch)
tree01692a66e9f6f935953da4a634fe8a423ca59d42
parentc529cbe996cc01d19d000048ff691014d150f7c2 (diff)
Fix -- handling in output and line matching functions
-rw-r--r--README.md17
-rw-r--r--src/assert.bash8
-rwxr-xr-xtest/50-assert-15-assert_output.bats7
-rwxr-xr-xtest/50-assert-16-refute_output.bats7
-rwxr-xr-xtest/50-assert-17-assert_line.bats7
-rwxr-xr-xtest/50-assert-18-refute_line.bats7
6 files changed, 49 insertions, 4 deletions
diff --git a/README.md b/README.md
index 5636351..6e99809 100644
--- a/README.md
+++ b/README.md
@@ -653,6 +653,23 @@ This option and partial matching (`--partial` or `-p`) are mutually
exclusive. An error is displayed when used simultaneously.
+## 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 -- '--'
+```
+
+
<!-- REFERENCES -->
[bats]: https://github.com/sstephenson/bats
diff --git a/src/assert.bash b/src/assert.bash
index 78b8416..58090dc 100644
--- a/src/assert.bash
+++ b/src/assert.bash
@@ -215,7 +215,7 @@ assert_output() {
case "$1" in
-p|--partial) is_mode_partial=1; shift ;;
-e|--regexp) is_mode_regexp=1; shift ;;
- --) break ;;
+ --) shift; break ;;
*) break ;;
esac
done
@@ -308,7 +308,7 @@ refute_output() {
case "$1" in
-p|--partial) is_mode_partial=1; shift ;;
-e|--regexp) is_mode_regexp=1; shift ;;
- --) break ;;
+ --) shift; break ;;
*) break ;;
esac
done
@@ -424,7 +424,7 @@ assert_line() {
;;
-p|--partial) is_mode_partial=1; shift ;;
-e|--regexp) is_mode_regexp=1; shift ;;
- --) break ;;
+ --) shift; break ;;
*) break ;;
esac
done
@@ -604,7 +604,7 @@ refute_line() {
;;
-p|--partial) is_mode_partial=1; shift ;;
-e|--regexp) is_mode_regexp=1; shift ;;
- --) break ;;
+ --) shift; break ;;
*) break ;;
esac
done
diff --git a/test/50-assert-15-assert_output.bats b/test/50-assert-15-assert_output.bats
index de622f5..cca79cc 100755
--- a/test/50-assert-15-assert_output.bats
+++ b/test/50-assert-15-assert_output.bats
@@ -233,3 +233,10 @@ test_r_regexp () {
[ "${lines[1]}" == "\`--partial' and \`--regexp' are mutually exclusive" ]
[ "${lines[2]}" == '--' ]
}
+
+@test "assert_output(): \`--' stops parsing options" {
+ run echo '-p'
+ run assert_output -- '-p'
+ [ "$status" -eq 0 ]
+ [ "${#lines[@]}" -eq 0 ]
+}
diff --git a/test/50-assert-16-refute_output.bats b/test/50-assert-16-refute_output.bats
index 2d47155..5204301 100755
--- a/test/50-assert-16-refute_output.bats
+++ b/test/50-assert-16-refute_output.bats
@@ -187,3 +187,10 @@ test_r_regexp () {
[ "${lines[1]}" == "\`--partial' and \`--regexp' are mutually exclusive" ]
[ "${lines[2]}" == '--' ]
}
+
+@test "refute_output(): \`--' stops parsing options" {
+ run echo '--'
+ run refute_output -- '-p'
+ [ "$status" -eq 0 ]
+ [ "${#lines[@]}" -eq 0 ]
+}
diff --git a/test/50-assert-17-assert_line.bats b/test/50-assert-17-assert_line.bats
index cd4588e..bee3850 100755
--- a/test/50-assert-17-assert_line.bats
+++ b/test/50-assert-17-assert_line.bats
@@ -325,3 +325,10 @@ test_index_r_regexp () {
[ "${lines[1]}" == "Invalid extended regular expression: \`[.*'" ]
[ "${lines[2]}" == '--' ]
}
+
+@test "assert_line(): \`--' stops parsing options" {
+ run printf 'a\n-p\nc'
+ run assert_line -- '-p'
+ [ "$status" -eq 0 ]
+ [ "${#lines[@]}" -eq 0 ]
+}
diff --git a/test/50-assert-18-refute_line.bats b/test/50-assert-18-refute_line.bats
index 30bbcba..9cc8185 100755
--- a/test/50-assert-18-refute_line.bats
+++ b/test/50-assert-18-refute_line.bats
@@ -333,3 +333,10 @@ test_index_r_regexp () {
[ "${lines[1]}" == "Invalid extended regular expression: \`[.*'" ]
[ "${lines[2]}" == '--' ]
}
+
+@test "refute_line(): \`--' stops parsing options" {
+ run printf 'a\n--\nc'
+ run refute_line -- '-p'
+ [ "$status" -eq 0 ]
+ [ "${#lines[@]}" -eq 0 ]
+}