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

github.com/bats-core/bats-support.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMartin Schulze <37703201+martin-schulze-vireso@users.noreply.github.com>2023-08-26 14:53:31 +0300
committerGitHub <noreply@github.com>2023-08-26 14:53:31 +0300
commit9bf10e876dd6b624fe44423f0b35e064225f7556 (patch)
tree74c19328dcc42b2e68722bf0ef9d8b0b7478ab95 /test
parent3c8fadc5097c9acfc96d836dced2bb598e48b009 (diff)
parent37133a094744e4021a54c088f6da90d4c1233d07 (diff)
Merge pull request #9 from bats-core/pr/2HEADmaster
Save path when stubbed/mocked
Diffstat (limited to 'test')
-rwxr-xr-xtest/50-output-10-batslib_err.bats27
-rwxr-xr-xtest/50-output-19-batslib_decorate.bats33
-rwxr-xr-xtest/cat1
3 files changed, 61 insertions, 0 deletions
diff --git a/test/50-output-10-batslib_err.bats b/test/50-output-10-batslib_err.bats
index 8c27fd1..89b9db1 100755
--- a/test/50-output-10-batslib_err.bats
+++ b/test/50-output-10-batslib_err.bats
@@ -14,3 +14,30 @@ load test_helper
[ "$status" -eq 0 ]
[ "$output" == 'm1 m2' ]
}
+
+@test 'batslib_err() works with modified path' {
+ export PATH="$BATS_TEST_DIRNAME:$PATH"
+ echo 'm1 m2' | {
+ # Verify stub
+ run which cat
+ [ "$status" -eq 0 ]
+ [ "$output" = "$BATS_TEST_DIRNAME/cat" ]
+ # Should still work
+ run batslib_err
+ [ "$status" -eq 0 ]
+ [ "$output" == 'm1 m2' ]
+ }
+}
+
+@test 'batslib_err() works with mock function' {
+ echo 'm1 m2' | {
+ function cat {
+ echo "Mocked cat"
+ }
+ [ "$(cat)" = "Mocked cat" ]
+ # Should still work
+ run batslib_err
+ [ "$status" -eq 0 ]
+ [ "$output" == 'm1 m2' ]
+ }
+}
diff --git a/test/50-output-19-batslib_decorate.bats b/test/50-output-19-batslib_decorate.bats
index 02d55ad..a4d4fcb 100755
--- a/test/50-output-19-batslib_decorate.bats
+++ b/test/50-output-19-batslib_decorate.bats
@@ -11,3 +11,36 @@ load test_helper
[ "${lines[1]}" == 'body' ]
[ "${lines[2]}" == '--' ]
}
+
+@test 'batslib_decorate() works with modified path' {
+ export PATH="$BATS_TEST_DIRNAME:$PATH"
+ echo body | {
+ # Verify stub
+ run which cat
+ [ "$status" -eq 0 ]
+ [ "$output" = "$BATS_TEST_DIRNAME/cat" ]
+ # Should still work
+ run batslib_decorate 'title'
+ [ "$status" -eq 0 ]
+ [ "${#lines[@]}" -eq 3 ]
+ [ "${lines[0]}" == '-- title --' ]
+ [ "${lines[1]}" == 'body' ]
+ [ "${lines[2]}" == '--' ]
+ }
+}
+
+@test 'batslib_decorate() works with mock function' {
+ echo body | {
+ function cat {
+ echo "Mocked cat"
+ }
+ [ "$(cat)" = "Mocked cat" ]
+ # Should still work
+ run batslib_decorate 'title'
+ [ "$status" -eq 0 ]
+ [ "${#lines[@]}" -eq 3 ]
+ [ "${lines[0]}" == '-- title --' ]
+ [ "${lines[1]}" == 'body' ]
+ [ "${lines[2]}" == '--' ]
+ }
+}
diff --git a/test/cat b/test/cat
new file mode 100755
index 0000000..c45d58f
--- /dev/null
+++ b/test/cat
@@ -0,0 +1 @@
+# Dummy file stubbing a stub/mock