diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-04-12 11:04:33 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-04-12 11:06:05 +0300 |
commit | 71d60540f441304f5010fd42284a0c70f9b36af9 (patch) | |
tree | 435c10e84871b3354d4206e89c2f320c97c14b46 | |
parent | 22719be2c3b13e4dd0463db10023d615a6bde847 (diff) | |
download | subplot-71d60540f441304f5010fd42284a0c70f9b36af9.tar.gz |
feat(python lib/runcmd): run commands in sub-directory
-rw-r--r-- | share/python/lib/runcmd.md | 20 | ||||
-rw-r--r-- | share/python/lib/runcmd.py | 11 | ||||
-rw-r--r-- | share/python/lib/runcmd.yaml | 8 |
3 files changed, 38 insertions, 1 deletions
diff --git a/share/python/lib/runcmd.md b/share/python/lib/runcmd.md index 4615f69..5f99b2a 100644 --- a/share/python/lib/runcmd.md +++ b/share/python/lib/runcmd.md @@ -37,6 +37,16 @@ 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, /bin/pwd +then exit code is 0 +then command is successful +then stdout contains "/xyzzy" +~~~ + ## Failed execution ~~~scenario @@ -45,6 +55,15 @@ 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, /bin/false +then exit code is not 0 +and command fails +~~~ + # Check we can prepend to $PATH This scenario verifies that we can add a directory to the beginning of @@ -187,6 +206,7 @@ template: python bindings: - runcmd.yaml - runcmd_test.yaml +- files.yaml functions: - runcmd.py - runcmd_test.py diff --git a/share/python/lib/runcmd.py b/share/python/lib/runcmd.py index a2564c6..cc4fd38 100644 --- a/share/python/lib/runcmd.py +++ b/share/python/lib/runcmd.py @@ -113,9 +113,18 @@ def runcmd_step(ctx, argv0=None, args=None): runcmd_exit_code_is_zero(ctx) +def runcmd_step_in(ctx, dirname=None, argv0=None, args=None): + runcmd_try_to_run_in(ctx, dirname=dirname, argv0=argv0, args=args) + runcmd_exit_code_is_zero(ctx) + + def runcmd_try_to_run(ctx, argv0=None, args=None): + runcmd_try_to_run_in(ctx, dirname=None, argv0=argv0, args=args) + + +def runcmd_try_to_run_in(ctx, dirname=None, argv0=None, args=None): argv = [shlex.quote(argv0)] + shlex.split(args) - runcmd_run(ctx, argv) + runcmd_run(ctx, argv, cwd=dirname) # diff --git a/share/python/lib/runcmd.yaml b/share/python/lib/runcmd.yaml index 48dde90..a5119d8 100644 --- a/share/python/lib/runcmd.yaml +++ b/share/python/lib/runcmd.yaml @@ -10,10 +10,18 @@ regex: true function: runcmd_step +- when: I run, in (?P<dirname>\S+), (?P<argv0>\S+)(?P<args>.*) + regex: true + function: runcmd_step_in + - when: I try to run (?P<argv0>\S+)(?P<args>.*) regex: true function: runcmd_try_to_run +- when: I try to run, in (?P<dirname>\S+), (?P<argv0>\S+)(?P<args>.*) + regex: true + function: runcmd_try_to_run_in + # Steps to examine exit code of latest command. - then: exit code is {exit} |