diff options
Diffstat (limited to 'subplot.md')
-rw-r--r-- | subplot.md | 185 |
1 files changed, 185 insertions, 0 deletions
@@ -691,6 +691,191 @@ then bar was done ~~~~ +## Automatic cleanup in scenarios + +A binding can define a cleanup function, which gets called at the end +of the scenario in reverse order for the successful steps. If a step +fails, all the cleanups for the successful steps are still called. We +test this for every language templat we support. + +~~~{#cleanup.yaml .file .yaml .numberLines} +- given: foo + function: foo + cleanup: foo_cleanup +- given: bar + function: bar + cleanup: bar_cleanup +- given: failure + function: failure + cleanup: failure_cleanup +~~~ + +~~~{#cleanup.py .file .python .numberLines} +def foo(ctx): + pass +def foo_cleanup(ctx): + pass +def bar(ctx): + pass +def bar_cleanup(ctx): + pass +def failure(ctx): + assert 0 +def failure_cleanup(ctx): + pass +~~~ + +~~~{#cleanup.sh .file .bash .numberLines} +foo() { + true +} +foo_cleanup() { + true +} +bar() { + true +} +bar_cleanup() { + true +} +failure() { + return 1 +} +failure_cleanup() { + true +} +~~~ + + +### Cleanup functions gets called on success (Python) + +~~~scenario +given file cleanup-success-python.md +and file cleanup.yaml +and file cleanup.py +when I run sp-codegen --run cleanup-success-python.md -o test.py +then scenario "Cleanup" was run +and step "given foo" was run, and then step "given bar" +and cleanup for "given bar" was run, and then for "given foo" +and program finished successfully +~~~ + + +~~~~~{#cleanup-success-python.md .file .markdown .numberLines} +--- +title: Cleanup +bindings: cleanup.yaml +functions: cleanup.py +template: python +... + +# Cleanup + +~~~scenario +given foo +given bar +~~~ +~~~~~ + + +### Cleanup functions get called on failure (Python) + +~~~scenario +given file cleanup-fail-python.md +and file cleanup.yaml +and file cleanup.py +when I try to run sp-codegen --run cleanup-fail-python.md -o test.py +then scenario "Cleanup" was run +and step "given foo" was run, and then step "given bar" +and cleanup for "given bar" was run, and then for "given foo" +and cleanup for "given failure" was not run +and exit code is non-zero +~~~ + +~~~~~{#cleanup-fail-python.md .file .markdown .numberLines} +--- +title: Cleanup +bindings: cleanup.yaml +functions: cleanup.py +template: python +... + +# Cleanup + +~~~scenario +given foo +given bar +given failure +~~~ +~~~~~ + + +### Cleanup functions gets called on success (Bash) + +~~~scenario +given file cleanup-success-bash.md +and file cleanup.yaml +and file cleanup.sh +when I run sp-codegen --run cleanup-success-bash.md -o test.sh +then scenario "Cleanup" was run +and step "given foo" was run, and then step "given bar" +and cleanup for "given bar" was run, and then for "given foo" +and program finished successfully +~~~ + +~~~~~{#cleanup-success-bash.md .file .markdown .numberLines} +--- +title: Cleanup +bindings: cleanup.yaml +functions: cleanup.sh +template: bash +... + +# Cleanup + +~~~scenario +given foo +given bar +~~~ +~~~~~ + + +### Cleanup functions get called on failure (Bash) + +If a step fails, all the cleanups for the preceding steps are still +called, in reverse order. + +~~~scenario +given file cleanup-fail-bash.md +and file cleanup.yaml +and file cleanup.sh +when I try to run sp-codegen --run cleanup-fail-bash.md -o test.sh +then scenario "Cleanup" was run +and step "given foo" was run, and then step "given bar" +and cleanup for "given bar" was run, and then for "given foo" +and cleanup for "given failure" was not run +and exit code is non-zero +~~~ + +~~~~~{#cleanup-fail-bash.md .file .markdown .numberLines} +--- +title: Cleanup +bindings: cleanup.yaml +functions: cleanup.sh +template: bash +... + +# Cleanup + +~~~scenario +given foo +given bar +given failure +~~~ +~~~~~ + + + ## Capturing parts of steps for functions A scenario step binding can capture parts of a scenario step, to be |