From 46e3bf2cfba5b96681fdac9fc918a695122c4f77 Mon Sep 17 00:00:00 2001 From: jcamiel Date: Thu, 12 Oct 2023 22:52:53 +0200 Subject: [PATCH] Use exit code 255 to signal skipped integration test. --- integration/test_script.py | 30 ++++++++++++------- integration/tests_failed/aws_sigv4_option.sh | 3 +- integration/tests_ok/aws_sigv4_option.sh | 2 +- .../tests_ok/http_version_2_option.ps1 | 2 +- integration/tests_ok/http_version_2_option.sh | 2 +- .../tests_ok/http_version_3_option.ps1 | 2 +- integration/tests_ok/http_version_3_option.sh | 2 +- 7 files changed, 26 insertions(+), 17 deletions(-) diff --git a/integration/test_script.py b/integration/test_script.py index 7c9902db2..625839580 100755 --- a/integration/test_script.py +++ b/integration/test_script.py @@ -35,22 +35,32 @@ def test(script_file: str): print(cmd) result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - test_exit_code(os.path.splitext(script_file)[0] + ".exit", result) - test_stdout(os.path.splitext(script_file)[0] + ".out", result) - test_stdout_pattern(os.path.splitext(script_file)[0] + ".out.pattern", result) - test_stderr(os.path.splitext(script_file)[0] + ".err", result) - test_stderr_pattern(os.path.splitext(script_file)[0] + ".err.pattern", result) + basename = os.path.splitext(script_file)[0] + + _continue = test_exit_code(f"{basename}.exit", result) + if not _continue: + print(f"{cmd} - skipped") + return + test_stdout(f"{basename}.out", result) + test_stdout_pattern(f"{basename}.out.pattern", result) + test_stderr(f"{basename}.err", result) + test_stderr_pattern(f"{basename}.err.pattern", result) -def test_exit_code(f, result) -> int: - """test exit code""" +def test_exit_code(f: str, result: subprocess.CompletedProcess) -> bool: + """Test actual exit code `result` against an expected exit code in file `f`""" if os.path.exists(f): expected = int(open(f, encoding="utf-8").read().strip()) else: expected = 0 - if result.returncode != expected: + actual = result.returncode + # Exit code 255 is the signal to skip test. + if actual == 255: + return False + + if actual != expected: print(">>> error in return code") - print(f"expected: {expected} actual:{result.returncode}") + print(f"expected: {expected} actual:{actual}") stderr = decode_string(result.stderr).strip() if stderr != "": print(stderr) @@ -60,7 +70,7 @@ def test_exit_code(f, result) -> int: sys.exit(1) - return expected + return True def test_stdout(f, result): diff --git a/integration/tests_failed/aws_sigv4_option.sh b/integration/tests_failed/aws_sigv4_option.sh index 3bc77ebf2..ab3a8102c 100755 --- a/integration/tests_failed/aws_sigv4_option.sh +++ b/integration/tests_failed/aws_sigv4_option.sh @@ -7,8 +7,7 @@ set +eo pipefail # simply ignore test if option is available on the system # FIXME: remove this test once all integration test targets have aws-sigv4 support in libcurl if curl --aws-sigv4 2>&1 | grep -qv 'option --aws-sigv4: is unknown'; then - cat tests_failed/aws_sigv4_option.err >&2 - exit 3 + exit 255 fi set -Eeuo pipefail diff --git a/integration/tests_ok/aws_sigv4_option.sh b/integration/tests_ok/aws_sigv4_option.sh index 9bf6dae64..970310318 100755 --- a/integration/tests_ok/aws_sigv4_option.sh +++ b/integration/tests_ok/aws_sigv4_option.sh @@ -6,7 +6,7 @@ set +eo pipefail # simply ignore test # FIXME: remove this workaround once all integration test targets have aws-sigv4 support in libcurl if curl --aws-sigv4 2>&1 | grep -q 'option --aws-sigv4: is unknown'; then - exit 0 + exit 255 fi set -Eeuo pipefail diff --git a/integration/tests_ok/http_version_2_option.ps1 b/integration/tests_ok/http_version_2_option.ps1 index 99f111ba0..c784d3e78 100755 --- a/integration/tests_ok/http_version_2_option.ps1 +++ b/integration/tests_ok/http_version_2_option.ps1 @@ -4,7 +4,7 @@ $ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Continue' curl --version | grep Features | grep -q HTTP2 if ($LASTEXITCODE -eq 1) { - exit 0 + exit 255 } $ErrorActionPreference = 'Stop' diff --git a/integration/tests_ok/http_version_2_option.sh b/integration/tests_ok/http_version_2_option.sh index 528accbea..37075ade4 100755 --- a/integration/tests_ok/http_version_2_option.sh +++ b/integration/tests_ok/http_version_2_option.sh @@ -4,7 +4,7 @@ set -Eeuo pipefail set +eo pipefail curl --version | grep Features | grep -q HTTP2 if [ $? -eq 1 ]; then - exit 0 + exit 255 fi set -Eeuo pipefail diff --git a/integration/tests_ok/http_version_3_option.ps1 b/integration/tests_ok/http_version_3_option.ps1 index 680c9dc29..dddac89fb 100755 --- a/integration/tests_ok/http_version_3_option.ps1 +++ b/integration/tests_ok/http_version_3_option.ps1 @@ -4,7 +4,7 @@ $ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Continue' curl --version | grep Features | grep -q HTTP3 if ($LASTEXITCODE -eq 1) { - exit 0 + exit 255 } $ErrorActionPreference = 'Stop' diff --git a/integration/tests_ok/http_version_3_option.sh b/integration/tests_ok/http_version_3_option.sh index 2e19a3e8a..476b331e3 100755 --- a/integration/tests_ok/http_version_3_option.sh +++ b/integration/tests_ok/http_version_3_option.sh @@ -4,7 +4,7 @@ set -Eeuo pipefail set +eo pipefail curl --version | grep Features | grep -q HTTP3 if [ $? -eq 1 ]; then - exit 0 + exit 255 fi set -Eeuo pipefail