diff mbox series

[3/3] patchtest/selftest: add test case for --error-on-failure return code

Message ID 20260318161209.54396-3-naftaly.ralamboarivony@smile.fr
State Under Review
Headers show
Series [1/3] patchtest: add --error-on-failure option | expand

Commit Message

naftaly.ralamboarivony@smile.fr March 18, 2026, 4:12 p.m. UTC
From: Naftaly RALAMBOARIVONY <naftaly.ralamboarivony@smile.fr>

Add a test case to verify that patchtest --error-on-failure
returns the correct exit code for PASS,FAIL and SKIP scenarios.

Signed-off-by: Naftaly RALAMBOARIVONY <naftaly.ralamboarivony@smile.fr>
---
 meta/lib/patchtest/selftest/selftest | 37 ++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
diff mbox series

Patch

diff --git a/meta/lib/patchtest/selftest/selftest b/meta/lib/patchtest/selftest/selftest
index 51681bec38..39114a45a0 100755
--- a/meta/lib/patchtest/selftest/selftest
+++ b/meta/lib/patchtest/selftest/selftest
@@ -142,6 +142,42 @@  def test(root, patch, extra_args=None):
 
     return results
 
+def test_error_on_failure(root, patch):
+    try:
+        output = test(root, patch, "--error-on-failure")
+        return output, 0
+    except subprocess.CalledProcessError as e:
+        return e.output, e.returncode
+
+def test_returncode(patches, counts):
+
+    for target in ("FAIL", "PASS", "SKIP"):
+        for patch_info in patches:
+
+            testid = patch_info["testid"]
+            expected = str(patch_info["expected"]).upper()
+
+            if expected == target:
+                results, returncode = test_error_on_failure(
+                    patch_info["root"], patch_info["patch"]
+                )
+
+                if target == "FAIL" and returncode != 0:
+                    print("XFAIL: test_returncode.%s (file: %s)" % (testid.strip("."), os.path.basename(patch_info["patch"])))
+                    counts["xfail"] = counts["xfail"] + 1
+                elif target == "PASS" and returncode == 0:
+                    counts["xpass"] = counts["xpass"] + 1
+                    print("XPASS: test_returncode.%s (file: %s)" % (testid.strip("."), os.path.basename(patch_info["patch"])))
+                elif target == "SKIP" and returncode == 0:
+                    counts["xskip"] = counts["xskip"] + 1
+                    print("XSKIP: test_returncode.%s (file: %s)" % (testid.strip("."), os.path.basename(patch_info["patch"])))
+                else:
+                    print(f"Test failed: target '{target}', expected return code '{expected}', got '{returncode}'")
+
+                break
+
+    return counts
+
 def test_head_attached(patches, counts, branch):
 
     git_attach_head(branch)
@@ -178,6 +214,7 @@  def run_tests(patches, counts):
     counts = test_head_detached(patches, counts)
     restore_git_state(git_state)
     run_sh(f"git branch -D {temp_branch}")
+    counts = test_returncode(patches, counts)
 
     return counts