From 5319e3605b73f634a6538a28257e40fd6d29392e Mon Sep 17 00:00:00 2001 From: Justin Ross Date: Mon, 26 Feb 2024 07:43:44 -0500 Subject: [PATCH] Support commands that are expected to fail --- example/skewer.yaml | 8 ++++++-- python/skewer/main.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/example/skewer.yaml b/example/skewer.yaml index 57ff6ca..8991c39 100644 --- a/example/skewer.yaml +++ b/example/skewer.yaml @@ -26,8 +26,12 @@ steps: - title: Fail on demand commands: west: - - run: | - if [ -n "${SKEWER_FAIL}" ]; then expr 1 / 0; fi + - run: "if [ -n \"${SKEWER_FAIL}\" ]; then expr 1 / 0; fi" + - title: Fail expectedly + commands: + west: + - run: "expr 1 / 0" + expect_failure: true - standard: hello_world/expose_the_backend - standard: hello_world/access_the_frontend - standard: hello_world/cleaning_up diff --git a/python/skewer/main.py b/python/skewer/main.py index df3e05e..fdb26ac 100644 --- a/python/skewer/main.py +++ b/python/skewer/main.py @@ -186,7 +186,16 @@ def run_step(model, step, work_dir, check=True): await_console_ok() if command.run: - run(command.run.replace("~", work_dir), shell=True, check=check) + proc = run(command.run.replace("~", work_dir), shell=True, check=False) + + if command.expect_failure: + if proc.exit_code == 0: + fail("A command expected to fail did not fail") + + continue + + if check and proc.exit_code > 0: + raise PlanoProcessError(proc) def pause_for_demo(model): notice("Pausing for demo time") @@ -675,6 +684,7 @@ def commands(self): class Command: run = object_property("run") + expect_failure = object_property("expect_failure", False) apply = object_property("apply") output = object_property("output") await_resource = object_property("await_resource")