From ca762afcb46f42c6302b6a63b915d949e0bc8ade Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 10 Sep 2021 09:14:27 +0300 Subject: test: tell Subplot-generated test program where the binaries are Previously, we blindly assumed that Cargo puts binaries in `target/debug` in the source tree. That is the default, but the user can change it. Now we get the Cargo target directory by parsing the output of "cargo metadata" and pass in the path to the test program via an environment variable. Also, reformat shell script. Sponsored-by: author --- check | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/check b/check index 8ff40c1..7d5098c 100755 --- a/check +++ b/check @@ -5,28 +5,24 @@ set -eu hideok=chronic -if [ "$#" -gt 0 ] -then - case "$1" in +if [ "$#" -gt 0 ]; then + case "$1" in verbose | -v | --verbose) - hideok= - shift - ;; - esac + hideok= + shift + ;; + esac fi -require_cmd() -{ - if ! command -v "$1" > /dev/null - then - echo "Need to have $1 installed, but can't find it" 1>&2 - return 1 - fi +require_cmd() { + if ! command -v "$1" >/dev/null; then + echo "Need to have $1 installed, but can't find it" 1>&2 + return 1 + fi } -got_cargo_cmd() -{ - cargo "$1" --help > /dev/null +got_cargo_cmd() { + cargo "$1" --help >/dev/null } require_cmd rustc @@ -43,7 +39,7 @@ require_cmd pdflatex # daemonize installation location changed from Debian 10 to 11. require_cmd daemonize || require_cmd /usr/sbin/daemonize -got_cargo_cmd clippy && cargo clippy --all-targets -q +got_cargo_cmd clippy && cargo clippy --all-targets -q $hideok cargo build --all-targets got_cargo_cmd fmt && $hideok cargo fmt -- --check $hideok cargo test @@ -51,13 +47,13 @@ $hideok cargo test subplot docgen obnam.md -o obnam.html subplot docgen obnam.md -o obnam.pdf +target="$(cargo metadata --format-version=1 | python3 -c 'import sys, json; o = json.load(sys.stdin); print(o["target_directory"])')" subplot codegen obnam.md -o test.py rm -f test.log -if [ "$(id -un)" = root ] -then - echo Not running tests as root. +if [ "$(id -un)" = root ]; then + echo Not running tests as root. else - $hideok python3 test.py --log test.log "$@" + $hideok python3 test.py --log test.log --env "CARGO_TARGET_DIR=$target" "$@" fi echo "Everything seems to be in order." -- cgit v1.2.1 From 6068ae53a9d85d83b6fcdb96530581794c2b0845 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 10 Sep 2021 09:17:06 +0300 Subject: test: run Obnam binaries from where Cargo puts them Sponsored-by: author --- subplot/client.py | 5 ++++- subplot/server.py | 8 +++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/subplot/client.py b/subplot/client.py index d0beba5..bea3b18 100644 --- a/subplot/client.py +++ b/subplot/client.py @@ -8,7 +8,10 @@ def install_obnam(ctx): srcdir = globals()["srcdir"] # Add the directory with built Rust binaries to the path. - runcmd_prepend_to_path(ctx, dirname=os.path.join(srcdir, "target", "debug")) + default_target = os.path.join(srcdir, "target") + target = os.environ.get("CARGO_TARGET_DIR", default_target) + runcmd_prepend_to_path(ctx, dirname=os.path.join(target, "debug")) + ctx["server-binary"] = os.path.join(target, "debug", "obnam-server") def uninstall_obnam(ctx): diff --git a/subplot/server.py b/subplot/server.py index 52ad8f4..2a3e397 100644 --- a/subplot/server.py +++ b/subplot/server.py @@ -33,9 +33,7 @@ def start_chunk_server(ctx, env=None): "address": f"localhost:{port}", } - server_binary = os.path.abspath( - os.path.join(srcdir, "target", "debug", "obnam-server") - ) + server_binary = ctx["server-binary"] filename = "config.yaml" yaml.safe_dump(config, stream=open(filename, "w")) @@ -44,8 +42,7 @@ def start_chunk_server(ctx, env=None): ctx["server_url"] = f"https://{config['address']}" daemon_start_on_port( - ctx, name="obnam-server", path=server_binary, args=filename, port=port, - env=env + ctx, name="obnam-server", path=server_binary, args=filename, port=port, env=env ) @@ -202,6 +199,7 @@ def _expand_vars(ctx, s): s = s[m.end() :] return "".join(result) + def _server_stderr_contains(ctx, wanted): daemon_get_stderr = globals()["daemon_get_stderr"] -- cgit v1.2.1