diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2022-01-01 18:09:35 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2022-01-01 18:09:35 +0000 |
commit | b9de4d5e810d07b679ad9ab9e46d58e4c76213cc (patch) | |
tree | b69c6b84b9ce025d6f7afd92d734452757f4f365 | |
parent | 95b3d27d27a8dab7cb8a5136000a2331ab9b4a4a (diff) | |
download | subplot-b9de4d5e810d07b679ad9ab9e46d58e4c76213cc.tar.gz |
tests: Make runcmd.md a common test set now
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r-- | subplotlib/runcmd.md | 187 | ||||
-rw-r--r-- | tests/subplots/common/runcmd.md (renamed from tests/subplots/python/runcmd.md) | 6 | ||||
-rw-r--r-- | tests/subplots/common/runcmd_test.py (renamed from tests/subplots/python/runcmd_test.py) | 0 | ||||
-rw-r--r-- | tests/subplots/common/runcmd_test.rs | 25 | ||||
-rw-r--r-- | tests/subplots/common/runcmd_test.yaml (renamed from tests/subplots/python/runcmd_test.yaml) | 6 |
5 files changed, 34 insertions, 190 deletions
diff --git a/subplotlib/runcmd.md b/subplotlib/runcmd.md deleted file mode 100644 index f6b9d85..0000000 --- a/subplotlib/runcmd.md +++ /dev/null @@ -1,187 +0,0 @@ ---- -title: Acceptance criteria for the runcmd step library for subplotlib. -author: The Subplot project -bindings: - - lib/runcmd.yaml - - lib/files.yaml -impls: - rust: [] -... - -# Introduction - -The [Subplot][] step library `runcmd` for Rust provides scenario steps -and their implementations for running Unix commands and examining the -results. The library consists of a bindings file `steplibrary/runcmd.yaml` and -implementations inside the `subplotlib` crate itself. - -[subplot]: https://subplot.liw.fi/ - -This document explains the acceptance criteria for the library and how -they're verified. It uses the steps and functions from the -`steplibrary/runcmd` library. The scenarios all have the same structure: run a -command, then examine the exit code, standard output (stdout for -short), or standard error output (stderr) of the command. - -The scenarios use the Unix commands `true` and `false` to -generate exit codes, and `echo` to produce stdout. To generate -stderr, they use the little helper script below. - -```{#err.sh .file .sh .numberLines} -#!/bin/sh -echo "$@" 1>&2 -``` - -# Check exit code - -These scenarios verify the exit code. To make it easier to write -scenarios in language that flows more naturally, there are a couple of -variations. - -## Successful execution - -```scenario -when I run true -then exit code is 0 -and command is successful -``` - -## Successful execution in a sub-directory - -```scenario -given a directory xyzzy -when I run, in xyzzy, pwd -then exit code is 0 -then command is successful -then stdout contains "/xyzzy" -``` - -## Failed execution - -```scenario -when I try to run false -then exit code is not 0 -and command fails -``` - -## Failed execution in a sub-directory - -```scenario -given a directory xyzzy -when I try to run, in xyzzy, false -then exit code is not 0 -and command fails -``` - -# Check output has what we want - -These scenarios verify that stdout or stderr do have something we want -to have. - -## Check stdout is exactly as wanted - -Note that the string is surrounded by double quotes to make it clear -to the reader what's inside. Also, C-style string escapes are -understood. - -```scenario -when I run echo hello, world -then stdout is exactly "hello, world\n" -``` - -## Check stderr is exactly as wanted - -```scenario -given helper script err.sh for runcmd -when I run sh err.sh hello, world -then stderr is exactly "hello, world\n" -``` - -## Check stdout using sub-string search - -Exact string comparisons are not always enough, so we can verify a -sub-string is in output. - -```scenario -when I run echo hello, world -then stdout contains "world\n" -and exit code is 0 -``` - -## Check stderr using sub-string search - -```scenario -given helper script err.sh for runcmd -when I run sh err.sh hello, world -then stderr contains "world\n" -``` - -## Check stdout using regular expressions - -Fixed strings are not always enough, so we can verify output matches a -regular expression. Note that the regular expression is not delimited -and does not get any C-style string escaped decoded. - -```scenario -when I run echo hello, world -then stdout matches regex world$ -``` - -## Check stderr using regular expressions - -```scenario -given helper script err.sh for runcmd -when I run sh err.sh hello, world -then stderr matches regex world$ -``` - -# Check output doesn't have what we want to avoid - -These scenarios verify that the stdout or stderr do not -have something we want to avoid. - -## Check stdout is not exactly something - -```scenario -when I run echo hi -then stdout isn't exactly "hello, world\n" -``` - -## Check stderr is not exactly something - -```scenario -given helper script err.sh for runcmd -when I run sh err.sh hi -then stderr isn't exactly "hello, world\n" -``` - -## Check stdout doesn't contain sub-string - -```scenario -when I run echo hi -then stdout doesn't contain "world" -``` - -## Check stderr doesn't contain sub-string - -```scenario -given helper script err.sh for runcmd -when I run sh err.sh hi -then stderr doesn't contain "world" -``` - -## Check stdout doesn't match regular expression - -```scenario -when I run echo hi -then stdout doesn't match regex world$ - -``` - -## Check stderr doesn't match regular expressions - -```scenario -given helper script err.sh for runcmd -when I run sh err.sh hi -then stderr doesn't match regex world$ -``` diff --git a/tests/subplots/python/runcmd.md b/tests/subplots/common/runcmd.md index 01e6904..4f66685 100644 --- a/tests/subplots/python/runcmd.md +++ b/tests/subplots/common/runcmd.md @@ -3,8 +3,8 @@ The [Subplot][] library `runcmd` for Python provides scenario steps and their implementations for running Unix commands and examining the results. The library consists of a bindings file `lib/runcmd.yaml` and -implementations in Python in `lib/runcmd.py`. There is no Bash -version. +implementations in Python in `lib/runcmd.py` or in the Rust subplotlib +step library. There is no Bash version. [Subplot]: https://subplot.liw.fi/ @@ -211,4 +211,6 @@ impls: - lib/runcmd.py - runcmd_test.py - lib/files.py + rust: + - runcmd_test.rs ... diff --git a/tests/subplots/python/runcmd_test.py b/tests/subplots/common/runcmd_test.py index 4aa5f49..4aa5f49 100644 --- a/tests/subplots/python/runcmd_test.py +++ b/tests/subplots/common/runcmd_test.py diff --git a/tests/subplots/common/runcmd_test.rs b/tests/subplots/common/runcmd_test.rs new file mode 100644 index 0000000..7759e5f --- /dev/null +++ b/tests/subplots/common/runcmd_test.rs @@ -0,0 +1,25 @@ +use subplotlib::steplibrary::files::{self, Datadir}; +use subplotlib::steplibrary::runcmd::Runcmd; + +#[cfg(unix)] +use std::os::unix::fs::PermissionsExt; + +#[step] +#[context(Datadir)] +fn create_script_from_embedded( + context: &ScenarioContext, + filename: &str, + embedded: SubplotDataFile, +) { + files::create_from_embedded_with_other_name::call(context, filename, embedded)?; + let filename = context.with(|dd: &Datadir| dd.canonicalise_filename(filename), false)?; + let mut perms = std::fs::symlink_metadata(&filename)?.permissions(); + #[cfg(unix)] + perms.set_mode(perms.mode() | 0o111); + std::fs::set_permissions(&filename, perms)?; +} + +#[step] +fn prepend_to_path(context: &mut Runcmd, dirname: &str) { + context.prepend_to_path(dirname); +} diff --git a/tests/subplots/python/runcmd_test.yaml b/tests/subplots/common/runcmd_test.yaml index 2ad981e..daab202 100644 --- a/tests/subplots/python/runcmd_test.yaml +++ b/tests/subplots/common/runcmd_test.yaml @@ -1,9 +1,13 @@ -- given: "executable script {filename} from {embedded}" +- given: "executable script {filename} from {embedded:file}" impl: python: function: create_script_from_embedded + rust: + function: create_script_from_embedded - when: "I prepend {dirname} to PATH" impl: python: function: runcmd_prepend_to_path + rust: + function: prepend_to_path |