summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2021-02-13 10:08:32 +0000
committerDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2021-02-13 10:08:32 +0000
commited49fd5a2cdfc2f492960fe50bd02e4874aa9ae8 (patch)
treef73ba6c633153b82e66385e57d8b0983fbf4266f
parent3ce866aa66a97c177c67a47ba0ba339afd5373bc (diff)
parenteef7b40a392750d9ff86280a64fb0b64f80a4b7e (diff)
downloadsubplot-ed49fd5a2cdfc2f492960fe50bd02e4874aa9ae8.tar.gz
Merge branch 'test-installed' into 'main'
feat: allow subplot.md to be used to test an installed Subplot Closes #97 See merge request larswirzenius/subplot!134
-rw-r--r--subplot.md48
-rw-r--r--subplot.py41
2 files changed, 75 insertions, 14 deletions
diff --git a/subplot.md b/subplot.md
index d701995..2db50f6 100644
--- a/subplot.md
+++ b/subplot.md
@@ -213,6 +213,54 @@ be good and helpful, writing it will require effort and skill. No tool
can replace that.
+
+## Using this document to verify Subplot works
+
+This document ("subplot") can be used to verify Subplot itself from
+its source tree or an installed Subplot. The default is to test
+Subplot from the source tree, and the `./check` script does that. You
+can run this in the source tree to build Subplot and then verify it
+using itself:
+
+~~~sh
+$ cargo build -q
+$ cargo run --bin sp-codegen -- subplot.md -o test.py
+$ python3 test.py
+... much output
+OK, all scenarios finished successfully
+$
+~~~
+
+To test an installed Subplot, generate the test program, and tell the
+test program where Subplot is installed. Again, in the Subplot source
+tree:
+
+~~~sh
+$ cargo build -q
+$ cargo run --bin sp-codegen -- subplot.md -o test.py
+$ python3 test.py --env SUBPLOT_DIR=/usr/local/bin
+... much output
+OK, all scenarios finished successfully
+$
+~~~
+
+You can do this with an installed Subplot as well:
+
+~~~sh
+$ cargo clean
+$ /usr/local/bin/sp-codegen subplot.md -o test.py
+$ python3 test.py --env SUBPLOT_DIR=/usr/local/bin
+... much output
+OK, all scenarios finished successfully
+$
+~~~
+
+The generated test program is self-standing, and can be run from
+anywhere. However, to generate it you need to be in the Subplot
+source tree. You can move it elsewhere after generating it, you if you
+prefer.
+
+
# Requirements
This chapter lists requirements for Subplot. These requirements are
diff --git a/subplot.py b/subplot.py
index 7d9544b..975b579 100644
--- a/subplot.py
+++ b/subplot.py
@@ -20,23 +20,36 @@ def install_subplot(ctx):
runcmd_prepend_to_path = globals()["runcmd_prepend_to_path"]
srcdir = globals()["srcdir"]
- # Create a "bin" directory for the wrapper. Can't put this into datadir, as
- # some of Subplot's scenarios make assumptions on what files exist there.
- bindir = ctx["bin-dir"] = tempfile.mkdtemp()
- for prog in ["sp-codegen", "sp-docgen"]:
- filename = os.path.join(bindir, prog)
- with open(filename, "w") as f:
- f.write(wrapper.format(prog=prog, srcdir=srcdir))
- os.chmod(filename, 0o755)
-
- # Add the temporary bin directory to the path, and then the source
- # directory's Rust binary target directory.
- runcmd_prepend_to_path(ctx, dirname=bindir)
- runcmd_prepend_to_path(ctx, dirname=os.path.join(srcdir, "target", "debug"))
+ # If the SUBPLOT_DIR is set, we expect the Subplot binaries to be installed
+ # in that directory. Otherwise, we expect them to be in the source
+ # directory, under target/debug, which is where Rust puts them. In the
+ # latter case, we create a wrapper script to add the necessary options to
+ # also use the resources from the source tree.
+
+ bindir = os.environ.get("SUBPLOT_DIR")
+ if bindir is not None:
+ runcmd_prepend_to_path(ctx, dirname=bindir)
+ else:
+ # Create a "bin" directory for the wrapper. Can't put this into datadir, as
+ # some of Subplot's scenarios make assumptions on what files exist there.
+ bindir = ctx["bin-dir"] = tempfile.mkdtemp()
+ for prog in ["sp-codegen", "sp-docgen"]:
+ filename = os.path.join(bindir, prog)
+ with open(filename, "w") as f:
+ f.write(wrapper.format(prog=prog, srcdir=srcdir))
+ os.chmod(filename, 0o755)
+
+ # Add the temporary bin directory to the path, and then the source
+ # directory's Rust binary target directory.
+ runcmd_prepend_to_path(ctx, dirname=bindir)
+ runcmd_prepend_to_path(ctx, dirname=os.path.join(srcdir, "target", "debug"))
def uninstall_subplot(ctx):
- shutil.rmtree(ctx["bin-dir"])
+ if "bin-dir" in ctx:
+ bindir = ctx["bin-dir"]
+ if os.path.exists(bindir):
+ shutil.rmtree(bindir)
def scenario_was_run(ctx, name=None):