SHA256
1
0
forked from pool/bats

Accepting request 856586 from home:cyphar:bats

- Backport https://github.com/bats-core/bats-core/pull/344. bsc#1180135
  + bsc1180135-0001-fix-dont-use-unbound-variables-in-setup-methods.patch
- Require gnu_parallel so that 'bats --jobs' works out of the box and is tested
  as part of the integration tests of the package.

OBS-URL: https://build.opensuse.org/request/show/856586
OBS-URL: https://build.opensuse.org/package/show/devel:tools/bats?expand=0&rev=19
This commit is contained in:
Martin Pluskal 2020-12-17 06:53:18 +00:00 committed by Git OBS Bridge
parent 64c416b781
commit 39768de0cd
3 changed files with 97 additions and 0 deletions

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Thu Dec 17 00:43:18 UTC 2020 - Aleksa Sarai <asarai@suse.com>
- Backport <https://github.com/bats-core/bats-core/pull/344>. bsc#1180135
+ bsc1180135-0001-fix-dont-use-unbound-variables-in-setup-methods.patch
-------------------------------------------------------------------
Wed Nov 18 22:44:45 UTC 2020 - Olav Reinert <seroton10@gmail.com>
@ -17,6 +23,12 @@ Wed Nov 18 21:32:54 UTC 2020 - Olav Reinert <seroton10@gmail.com>
- Install to /usr/libexec on Tumbleweed
-------------------------------------------------------------------
Fri Jul 3 01:08:46 UTC 2020 - Aleksa Sarai <asarai@suse.com>
- Require gnu_parallel so that 'bats --jobs' works out of the box and is tested
as part of the integration tests of the package.
-------------------------------------------------------------------
Wed May 20 12:04:49 UTC 2020 - Olav Reinert <seroton10@gmail.com>

View File

@ -25,7 +25,10 @@ License: MIT
Group: Development/Tools/Other
URL: https://github.com/%{pname}/%{pname}/
Source: https://github.com/%{pname}/%{pname}/archive/v%{version}.tar.gz
# FIX-UPSTREAM: Backport of https://github.com/bats-core/bats-core/pull/344. bsc#1180135
Patch1: bsc1180135-0001-fix-dont-use-unbound-variables-in-setup-methods.patch
BuildRequires: ncurses-utils
Requires: gnu_parallel
BuildArch: noarch
%description
@ -41,6 +44,8 @@ to test any UNIX program.
%prep
%setup -q -n %{pname}-%{version}
# bsc#1180135
%patch1 -p1
sed -i '1s|#!%{_bindir}/env bash|#!/bin/bash|' ./lib{,exec}/%{pname}/* ./bin/bats
%if 0%{?suse_version} <= 1500

View File

@ -0,0 +1,80 @@
From 43b8ae1444e2faf62a80455eafa42d0b02709423 Mon Sep 17 00:00:00 2001
From: Martin Schulze <martin.schulze@vireso.de>
Date: Mon, 17 Aug 2020 23:22:31 +0200
Subject: [PATCH] fix: don't use unbound variables in setup methods
- fixes #340
---
lib/bats-core/test_functions.bash | 2 +-
test/bats.bats | 13 +++++++++++
.../bats/set_-eu_in_setup_and_teardown.bats | 23 +++++++++++++++++++
3 files changed, 37 insertions(+), 1 deletion(-)
create mode 100644 test/fixtures/bats/set_-eu_in_setup_and_teardown.bats
diff --git a/lib/bats-core/test_functions.bash b/lib/bats-core/test_functions.bash
index 9eded0c0309a..e1fbb2a9f49a 100644
--- a/lib/bats-core/test_functions.bash
+++ b/lib/bats-core/test_functions.bash
@@ -54,7 +54,7 @@ teardown() {
skip() {
# if this is a skip in teardown ...
- if [[ -n "$BATS_TEARDOWN_STARTED" ]]; then
+ if [[ -n "${BATS_TEARDOWN_STARTED-}" ]]; then
# ... we want to skip the rest of teardown.
# communicate to bats_exit_trap that the teardown was completed without error
# shellcheck disable=SC2034
diff --git a/test/bats.bats b/test/bats.bats
index 1dc7e5be635c..73fb54459b28 100755
--- a/test/bats.bats
+++ b/test/bats.bats
@@ -576,3 +576,16 @@ END_OF_ERR_MSG
run bash -c "echo $'1..1\nok 1' | bats_test_count_validator"
[[ $status -eq 0 ]]
}
+
+@test "Don't use unbound variables inside bats (issue #340)" {
+ run bats "$FIXTURE_ROOT/set_-eu_in_setup_and_teardown.bats"
+ echo "$output"
+ [[ "${lines[0]}" == "1..4" ]]
+ [[ "${lines[1]}" == "ok 1 skipped test # skip" ]]
+ [[ "${lines[2]}" == "ok 2 skipped test with reason # skip reason" ]]
+ [[ "${lines[3]}" == "ok 3 passing test" ]]
+ [[ "${lines[4]}" == "not ok 4 failing test" ]]
+ [[ "${lines[5]}" == "# (in test file $RELATIVE_FIXTURE_ROOT/set_-eu_in_setup_and_teardown.bats, line 22)" ]]
+ [[ "${lines[6]}" == "# \`false' failed" ]]
+ [[ "${#lines[@]}" -eq 7 ]]
+}
diff --git a/test/fixtures/bats/set_-eu_in_setup_and_teardown.bats b/test/fixtures/bats/set_-eu_in_setup_and_teardown.bats
new file mode 100644
index 000000000000..e9879f0ab54e
--- /dev/null
+++ b/test/fixtures/bats/set_-eu_in_setup_and_teardown.bats
@@ -0,0 +1,23 @@
+setup() {
+ set -eu
+}
+
+teardown() {
+ set -eu
+}
+
+@test "skipped test" {
+ skip
+}
+
+@test "skipped test with reason" {
+ skip "reason"
+}
+
+@test "passing test" {
+ run true
+}
+
+@test "failing test" {
+ false
+}
\ No newline at end of file
--
2.29.2