From 83a4ed97f0d70726e3a06c95ec2c7d8a8ba3cfb5 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 15 Sep 2021 08:23:18 +0300 Subject: fix: use impl in bindings file, for new Subplot Sponsored-by: author --- subplot/ewww.yaml | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/subplot/ewww.yaml b/subplot/ewww.yaml index 7353863..d59a5fd 100644 --- a/subplot/ewww.yaml +++ b/subplot/ewww.yaml @@ -1,33 +1,53 @@ - given: a self-signed certificate as {cert}, using key {key} - function: copy_test_certificate + impl: + python: + function: copy_test_certificate - given: a running server using config file {filename} - function: start_server - cleanup: stop_server + impl: + python: + function: start_server + cleanup: stop_server - given: directory {dirname} - function: create_directory + impl: + python: + function: create_directory - then: I am redirected to {location} - function: fixme + impl: + python: + function: fixme - then: I can do at least {number} requests per second - function: fixme + impl: + python: + function: fixme - then: I get status code {code} - function: http_status_code_is + impl: + python: + function: http_status_code_is - then: 'header (?P
\S+) is "(?P.+)"' regex: true - function: http_header_is + impl: + python: + function: http_header_is - then: 'body is "(?P.*)"' regex: true - function: http_body_is + impl: + python: + function: http_body_is - when: I request {method} {url} - function: request + impl: + python: + function: request - when: I request files under {url} in random order {count} times - function: fixme + impl: + python: + function: fixme -- cgit v1.2.1 From eccb45b085a5b0e930b29efbd74deaeb4e2b5b73 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 15 Sep 2021 08:25:56 +0300 Subject: test: handle user-chosen cargo target directory Sponsored-by: author --- check | 63 ++++++++++++++++++++++++++------------------------------- subplot/ewww.py | 14 +++++-------- 2 files changed, 34 insertions(+), 43 deletions(-) diff --git a/check b/check index 272ee63..ceffb0e 100755 --- a/check +++ b/check @@ -4,63 +4,58 @@ set -eu verbose=false moar=true -while [ "$#" -gt 0 ] && $moar -do - case "$1" in +while [ "$#" -gt 0 ] && $moar; do + case "$1" in verbose | -v | --verbose) - verbose=true - shift 1 - ;; - esac + verbose=true + shift 1 + ;; + esac done hideok= -if command -v chronic > /dev/null -then - hideok=chronic +if command -v chronic >/dev/null; then + hideok=chronic fi quiet=-q -if $verbose -then - quiet= - hideok= +if $verbose; then + quiet= + hideok= fi - codegen() { - $hideok subplot codegen "$1" --output "$2" - rm -f test.log - $hideok python3 test.py --log test.log + target="$(cargo metadata --format-version=1 | + python3 -c 'import sys, json; o = json.load(sys.stdin); print(o["target_directory"])')" + $hideok subplot codegen "$1" --output "$2" + rm -f test.log + $hideok python3 test.py --log test.log --env "CARGO_TARGET_DIR=$target" } docgen() { - subplot docgen "$1" --output "$2" + subplot docgen "$1" --output "$2" } $hideok cargo build --all-targets -if cargo --list | awk '{ print $1 }' | grep 'clippy$' > /dev/null -then - # shellcheck disable=SC2086 - cargo clippy $quiet +if cargo --list | awk '{ print $1 }' | grep 'clippy$' >/dev/null; then + # shellcheck disable=SC2086 + cargo clippy $quiet fi # shellcheck disable=SC2086 $hideok cargo test $quiet -if cargo fmt --help > /dev/null 2> /dev/null -then - $hideok cargo fmt -- --check +if cargo fmt --help >/dev/null 2>/dev/null; then + $hideok cargo fmt -- --check fi -$hideok ./mktestcert test.key test.pem hunter2 +$hideok ./mktestcert test.key test.pem hunter2 -for md in [^R]*.md -do - $hideok echo "$md =====================================" - codegen "$md" test.py - docgen "$md" "$(basename "$md" .md).pdf" - docgen "$md" "$(basename "$md" .md).html" - $hideok echo +for md in [^R]*.md; do + $hideok echo "$md =====================================" + codegen "$md" test.py + docgen "$md" "$(basename "$md" .md).pdf" + docgen "$md" "$(basename "$md" .md).html" + $hideok echo done echo "Everything seems to be in order." diff --git a/subplot/ewww.py b/subplot/ewww.py index a6c4c4f..11915ae 100644 --- a/subplot/ewww.py +++ b/subplot/ewww.py @@ -10,12 +10,6 @@ import urllib.parse import yaml -# Name of Rust binary, debug-build. -def _binary(name): - srcdir = globals()["srcdir"] - return os.path.abspath(os.path.join(srcdir, "target", "debug", name)) - - # Write a file with given content. def _write(filename, content): open(filename, "w").write(content) @@ -59,6 +53,7 @@ def copy_test_certificate(ctx, cert=None, key=None): # Start server using named configuration file. def start_server(ctx, filename=None): get_file = globals()["get_file"] + srcdir = globals()["srcdir"] daemon_start_on_port = globals()["daemon_start_on_port"] logging.debug(f"Starting ewww with config file {filename}") @@ -72,9 +67,10 @@ def start_server(ctx, filename=None): config = yaml.safe_dump(config) _write(filename, config) - daemon_start_on_port( - ctx, path=_binary("ewww"), args=filename, name="ewww", port=port - ) + target = os.environ.get("CARGO_TARGET_DIR", os.path.join(srcdir, "target")) + logging.debug(f"Cargo target directory: {target}") + binary = os.path.join(target, "debug", "ewww") + daemon_start_on_port(ctx, binary, args=filename, name="ewww", port=port) # Stop previously started server. -- cgit v1.2.1