diff mbox series

[RFC,2/6] patchtest: allow to pass patch from stdin

Message ID 20250203-b4-patchtest-v1-2-ef6ee5fcdd78@cherry.de
State New
Headers show
Series prepare patchtest to be run with b4 prep --check | expand

Commit Message

Quentin Schulz Feb. 3, 2025, 4 p.m. UTC
From: Quentin Schulz <quentin.schulz@cherry.de>

This allows to pass a patch via stdin to patchtest.
This will be useful when using b4 with patchtest, with the former
passing each patch to the latter via stdin.

Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de>
---
 scripts/patchtest | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/scripts/patchtest b/scripts/patchtest
index bcd48dbcc39573d7abd3247bc34cb9ac8a8a5c2e..66a9f6470ca860c2233fb9ace042edf4b4737c88 100755
--- a/scripts/patchtest
+++ b/scripts/patchtest
@@ -205,11 +205,20 @@  def main():
         patch_list = [patch_path]
 
     for patch in patch_list:
-        if os.path.getsize(patch) == 0:
+        if patch == "-":
+            import tempfile
+
+            patch = tempfile.NamedTemporaryFile(delete=False)
+            patch.write(sys.stdin.buffer.read())
+            patch.flush()
+            logger.info('Testing patch from stdin')
+            tmp_patch = True
+            patch = patch.name
+        elif os.path.getsize(patch) == 0:
             logger.error('patchtest: patch is empty')
             return 1
-
-        logger.info('Testing patch %s' % patch)
+        else:
+            logger.info('Testing patch %s' % patch)
 
         if log_results:
             log_path = patch + ".testresult"