From 74e2506734ccbbcaed2564f2a8a0d9894952f3ac Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 10 Oct 2017 16:51:31 +0100 Subject: [PATCH] [functional-tests] use ../bin in the path for tools, even if they're failing. --- functional-tests/cache-functional-tests.scm | 105 ++++++++++---------- functional-tests/era-functional-tests.scm | 66 ++++++------ functional-tests/functional-tests.scm | 11 +- functional-tests/process.scm | 22 +++- functional-tests/thin-functional-tests.scm | 97 +++++++++--------- 5 files changed, 163 insertions(+), 138 deletions(-) diff --git a/functional-tests/cache-functional-tests.scm b/functional-tests/cache-functional-tests.scm index 1e47be3..856ea57 100644 --- a/functional-tests/cache-functional-tests.scm +++ b/functional-tests/cache-functional-tests.scm @@ -27,7 +27,7 @@ ((_ (md) b1 b2 ...) (with-temp-file-sized ((md "cache.bin" (meg 4))) (with-cache-xml (xml) - (cache-restore "-i" xml "-o" md) + (run-ok (cache-restore "-i" xml "-o" md)) b1 b2 ...))))) ;;; It would be nice if the metadata was at least similar to valid data. @@ -53,27 +53,27 @@ (define-scenario (cache-check v) "cache_check -V" - (receive (stdout _) (cache-check "-V") + (run-ok-rcv (stdout _) (cache-check "-V") (assert-equal tools-version stdout))) (define-scenario (cache-check version) "cache_check --version" - (receive (stdout _) (cache-check "--version") + (run-ok-rcv (stdout _) (cache-check "--version") (assert-equal tools-version stdout))) (define-scenario (cache-check h) "cache_check -h" - (receive (stdout _) (cache-check "-h") + (run-ok-rcv (stdout _) (cache-check "-h") (assert-equal cache-check-help stdout))) (define-scenario (cache-check help) "cache_check --help" - (receive (stdout _) (cache-check "--help") + (run-ok-rcv (stdout _) (cache-check "--help") (assert-equal cache-check-help stdout))) (define-scenario (cache-check must-specify-metadata) "Metadata file must be specified" - (receive (_ stderr) (run-fail "cache_check") + (run-fail-rcv (_ stderr) (cache-check) (assert-equal (string-append "No input file provided.\n" cache-check-help) @@ -82,7 +82,7 @@ (define-scenario (cache-check no-such-metadata) "Metadata file doesn't exist." (let ((bad-path "/arbitrary/filename")) - (receive (_ stderr) (run-fail "cache_check" bad-path) + (run-fail-rcv (_ stderr) (cache-check bad-path) (assert-starts-with (string-append bad-path ": No such file or directory") stderr)))) @@ -90,7 +90,7 @@ (define-scenario (cache-check metadata-file-cannot-be-a-directory) "Metadata file must not be a directory" (let ((bad-path "/tmp")) - (receive (_ stderr) (run-fail "cache_check" bad-path) + (run-fail-rcv (_ stderr) (cache-check bad-path) (assert-starts-with (string-append bad-path ": Not a block device or regular file") stderr)))) @@ -99,51 +99,51 @@ "Metadata file exists, but is unreadable." (with-valid-metadata (md) (run-ok "chmod" "-r" md) - (receive (_ stderr) (run-fail "cache_check" md) + (run-fail-rcv (_ stderr) (cache-check md) (assert-starts-with "syscall 'open' failed: Permission denied" stderr)))) (define-scenario (cache-check fails-with-corrupt-metadata) "Fail with corrupt superblock" (with-corrupt-metadata (md) - (run-fail "cache_check" md))) + (run-fail (cache-check md)))) (define-scenario (cache-check failing-q) "Fail quietly with -q" (with-corrupt-metadata (md) - (receive (stdout stderr) (run-fail "cache_check" "-q" md) + (run-fail-rcv (stdout stderr) (cache-check "-q" md) (assert-eof stdout) (assert-eof stderr)))) (define-scenario (cache-check failing-quiet) "Fail quietly with --quiet" (with-corrupt-metadata (md) - (receive (stdout stderr) (run-fail "cache_check" "--quiet" md) + (run-fail-rcv (stdout stderr) (cache-check "--quiet" md) (assert-eof stdout) (assert-eof stderr)))) (define-scenario (cache-check valid-metadata-passes) "A valid metadata area passes" (with-valid-metadata (md) - (cache-check md))) + (run-ok (cache-check md)))) (define-scenario (cache-check bad-metadata-version) "Invalid metadata version fails" (with-cache-xml (xml) (with-empty-metadata (md) (cache-restore "-i" xml "-o" md "--debug-override-metadata-version" "12345") - (run-fail "cache_check" md)))) + (run-fail (cache-check md))))) (define-scenario (cache-check tiny-metadata) "Prints helpful message in case tiny metadata given" (with-temp-file-sized ((md "cache.bin" 1024)) - (receive (_ stderr) (run-fail "cache_check" md) + (run-fail-rcv (_ stderr) (cache-check md) (assert-starts-with "Metadata device/file too small. Is this binary metadata?" stderr)))) (define-scenario (cache-check spot-accidental-xml-data) "Prints helpful message if XML metadata given" (with-cache-xml (xml) (system (fmt #f "man bash >> " xml)) - (receive (_ stderr) (run-fail "cache_check" xml) + (run-fail-rcv (_ stderr) (cache-check xml) (assert-matches ".*This looks like XML. cache_check only checks the binary metadata format." stderr)))) ;;;----------------------------------------------------------- @@ -152,34 +152,34 @@ (define-scenario (cache-restore v) "print version (-V flag)" - (receive (stdout _) (cache-restore "-V") + (run-ok-rcv (stdout _) (cache-restore "-V") (assert-equal tools-version stdout))) (define-scenario (cache-restore version) "print version (--version flags)" - (receive (stdout _) (cache-restore "--version") + (run-ok-rcv (stdout _) (cache-restore "--version") (assert-equal tools-version stdout))) (define-scenario (cache-restore h) "cache_restore -h" - (receive (stdout _) (cache-restore "-h") + (run-ok-rcv (stdout _) (cache-restore "-h") (assert-equal cache-restore-help stdout))) (define-scenario (cache-restore help) "cache_restore --help" - (receive (stdout _) (cache-restore "--help") + (run-ok-rcv (stdout _) (cache-restore "--help") (assert-equal cache-restore-help stdout))) (define-scenario (cache-restore no-input-file) "forget to specify an input file" (with-empty-metadata (md) - (receive (_ stderr) (run-fail "cache_restore" "-o" md) + (run-fail-rcv (_ stderr) (cache-restore "-o" md) (assert-starts-with "No input file provided." stderr)))) (define-scenario (cache-restore missing-input-file) "the input file can't be found" (with-empty-metadata (md) - (receive (_ stderr) (run-fail "cache_restore -i no-such-file -o" md) + (run-fail-rcv (_ stderr) (cache-restore "-i no-such-file -o" md) (assert-superblock-untouched md) (assert-starts-with "Couldn't stat file" stderr)))) @@ -187,33 +187,33 @@ "the input file is just zeroes" (with-empty-metadata (md) (with-temp-file-sized ((xml "cache.xml" 4096)) - (receive (_ stderr) (run-fail "cache_restore -i " xml "-o" md) + (run-fail-rcv (_ stderr) (cache-restore "-i" xml "-o" md) (assert-superblock-untouched md))))) (define-scenario (cache-restore missing-output-file) "the output file can't be found" (with-cache-xml (xml) - (receive (_ stderr) (run-fail "cache_restore -i " xml) + (run-fail-rcv (_ stderr) (cache-restore "-i" xml) (assert-starts-with "No output file provided." stderr)))) (define-scenario (cache-restore tiny-output-file) "Fails if the output file is too small." (with-temp-file-sized ((md "cache.bin" (* 1024 4))) (with-cache-xml (xml) - (receive (_ stderr) (run-fail "cache_restore" "-i" xml "-o" md) + (run-fail-rcv (_ stderr) (cache-restore "-i" xml "-o" md) (assert-starts-with cache-restore-outfile-too-small-text stderr))))) (define-scenario (cache-restore successfully-restores) "Restore succeeds." (with-empty-metadata (md) (with-cache-xml (xml) - (cache-restore "-i" xml "-o" md)))) + (run-ok (cache-restore "-i" xml "-o" md))))) (define-scenario (cache-restore q) "cache_restore accepts -q" (with-empty-metadata (md) (with-cache-xml (xml) - (receive (stdout stderr) (cache-restore "-i" xml "-o" md "-q") + (run-ok-rcv (stdout stderr) (cache-restore "-i" xml "-o" md "-q") (assert-eof stdout) (assert-eof stderr))))) @@ -221,7 +221,7 @@ "cache_restore accepts --quiet" (with-empty-metadata (md) (with-cache-xml (xml) - (receive (stdout stderr) (cache-restore "-i" xml "-o" md "--quiet") + (run-ok-rcv (stdout stderr) (cache-restore "-i" xml "-o" md "--quiet") (assert-eof stdout) (assert-eof stderr))))) @@ -229,13 +229,15 @@ "we can set any metadata version" (with-empty-metadata (md) (with-cache-xml (xml) - (cache-restore "-i" xml "-o" md "--debug-override-metadata-version 10298")))) + (run-ok + (cache-restore "-i" xml "-o" md "--debug-override-metadata-version 10298"))))) (define-scenario (cache-restore omit-clean-shutdown) "accepts --omit-clean-shutdown" (with-empty-metadata (md) (with-cache-xml (xml) - (cache-restore "-i" xml "-o" md "--omit-clean-shutdown")))) + (run-ok + (cache-restore "-i" xml "-o" md "--omit-clean-shutdown"))))) ;;;----------------------------------------------------------- ;;; cache_dump scenarios @@ -243,41 +245,42 @@ (define-scenario (cache-dump v) "print version (-V flag)" - (receive (stdout _) (cache-dump "-V") + (run-ok-rcv (stdout _) (cache-dump "-V") (assert-equal tools-version stdout))) (define-scenario (cache-dump version) "print version (--version flags)" - (receive (stdout _) (cache-dump "--version") + (run-ok-rcv (stdout _) (cache-dump "--version") (assert-equal tools-version stdout))) (define-scenario (cache-dump h) "cache_dump -h" - (receive (stdout _) (cache-dump "-h") + (run-ok-rcv (stdout _) (cache-dump "-h") (assert-equal cache-dump-help stdout))) (define-scenario (cache-dump help) "cache_dump --help" - (receive (stdout _) (cache-dump "--help") + (run-ok-rcv (stdout _) (cache-dump "--help") (assert-equal cache-dump-help stdout))) (define-scenario (cache-dump missing-input-file) "Fails with missing input file." - (receive (stdout stderr) (run-fail "cache_dump") + (run-fail-rcv (stdout stderr) (cache-dump) (assert-starts-with "No input file provided." stderr))) (define-scenario (cache-dump small-input-file) "Fails with small input file" (with-temp-file-sized ((md "cache.bin" 512)) - (run-fail "cache_dump" md))) + (run-fail + (cache-dump md)))) (define-scenario (cache-dump restore-is-noop) "cache_dump followed by cache_restore is a noop." (with-valid-metadata (md) - (receive (d1-stdout _) (cache-dump md) + (run-ok-rcv (d1-stdout _) (cache-dump md) (with-temp-file-containing ((xml "cache.xml" d1-stdout)) - (cache-restore "-i" xml "-o" md) - (receive (d2-stdout _) (cache-dump md) + (run-ok (cache-restore "-i" xml "-o" md)) + (run-ok-rcv (d2-stdout _) (cache-dump md) (assert-equal d1-stdout d2-stdout)))))) ;;;----------------------------------------------------------- @@ -286,69 +289,69 @@ (define-scenario (cache-metadata-size v) "cache_metadata_size -V" - (receive (stdout _) (cache-metadata-size "-V") + (run-ok-rcv (stdout _) (cache-metadata-size "-V") (assert-equal tools-version stdout))) (define-scenario (cache-metadata-size version) "cache_metadata_size --version" - (receive (stdout _) (cache-metadata-size "--version") + (run-ok-rcv (stdout _) (cache-metadata-size "--version") (assert-equal tools-version stdout))) (define-scenario (cache-metadata-size h) "cache_metadata_size -h" - (receive (stdout _) (cache-metadata-size "-h") + (run-ok-rcv (stdout _) (cache-metadata-size "-h") (assert-equal cache-metadata-size-help stdout))) (define-scenario (cache-metadata-size help) "cache_metadata_size --help" - (receive (stdout _) (cache-metadata-size "--help") + (run-ok-rcv (stdout _) (cache-metadata-size "--help") (assert-equal cache-metadata-size-help stdout))) (define-scenario (cache-metadata-size no-args) "No arguments specified causes fail" - (receive (_ stderr) (run-fail "cache_metadata_size") + (run-fail-rcv (_ stderr) (cache-metadata-size) (assert-equal "Please specify either --device-size and --block-size, or --nr-blocks." stderr))) (define-scenario (cache-metadata-size device-size-only) "Just --device-size causes fail" - (receive (_ stderr) (run-fail "cache_metadata_size --device-size" (meg 100)) + (run-fail-rcv (_ stderr) (cache-metadata-size "--device-size" (meg 100)) (assert-equal "If you specify --device-size you must also give --block-size." stderr))) (define-scenario (cache-metadata-size block-size-only) "Just --block-size causes fail" - (receive (_ stderr) (run-fail "cache_metadata_size --block-size" 128) + (run-fail-rcv (_ stderr) (cache-metadata-size "--block-size" 128) (assert-equal "If you specify --block-size you must also give --device-size." stderr))) (define-scenario (cache-metadata-size conradictory-info-fails) "Contradictory info causes fail" - (receive (_ stderr) (run-fail "cache_metadata_size --device-size 102400 --block-size 1000 --nr-blocks 6") + (run-fail-rcv (_ stderr) (cache-metadata-size "--device-size 102400 --block-size 1000 --nr-blocks 6") (assert-equal "Contradictory arguments given, --nr-blocks doesn't match the --device-size and --block-size." stderr))) (define-scenario (cache-metadata-size all-args-agree) "All args agreeing succeeds" - (receive (stdout stderr) (cache-metadata-size "--device-size" 102400 "--block-size" 100 "--nr-blocks" 1024) + (run-ok-rcv (stdout stderr) (cache-metadata-size "--device-size" 102400 "--block-size" 100 "--nr-blocks" 1024) (assert-equal "8248 sectors" stdout) (assert-eof stderr))) (define-scenario (cache-metadata-size nr-blocks-alone) "Just --nr-blocks succeeds" - (receive (stdout stderr) (cache-metadata-size "--nr-blocks" 1024) + (run-ok-rcv (stdout stderr) (cache-metadata-size "--nr-blocks" 1024) (assert-equal "8248 sectors" stdout) (assert-eof stderr))) (define-scenario (cache-metadata-size dev-size-and-block-size-succeeds) "Specifying --device-size with --block-size succeeds" - (receive (stdout stderr) (cache-metadata-size "--device-size" 102400 "--block-size" 100) + (run-ok-rcv (stdout stderr) (cache-metadata-size "--device-size" 102400 "--block-size" 100) (assert-equal "8248 sectors" stdout) (assert-eof stderr))) (define-scenario (cache-metadata-size big-config) "A big configuration succeeds" - (receive (stdout stderr) (cache-metadata-size "--nr-blocks 67108864") + (run-ok-rcv (stdout stderr) (cache-metadata-size "--nr-blocks 67108864") (assert-equal "3678208 sectors" stdout) (assert-eof stderr))) ) diff --git a/functional-tests/era-functional-tests.scm b/functional-tests/era-functional-tests.scm index bc25c1f..373fe34 100644 --- a/functional-tests/era-functional-tests.scm +++ b/functional-tests/era-functional-tests.scm @@ -25,9 +25,9 @@ (syntax-rules () ((_ (md) b1 b2 ...) (with-temp-file-sized ((md "era.bin" (meg 4))) - (with-era-xml (xml) - (era-restore "-i" xml "-o" md) - b1 b2 ...))))) + (with-era-xml (xml) + (run-ok (era-restore "-i" xml "-o" md)) + b1 b2 ...))))) (define-syntax with-corrupt-metadata (syntax-rules () @@ -48,76 +48,76 @@ ;;;----------------------------------------------------------- (define-scenario (era-check v) "era_check -V" - (receive (stdout _) (era-check "-V") + (run-ok-rcv (stdout _) (era-check "-V") (assert-equal tools-version stdout))) (define-scenario (era-check version) "era_check --version" - (receive (stdout _) (era-check "--version") + (run-ok-rcv (stdout _) (era-check "--version") (assert-equal tools-version stdout))) (define-scenario (era-check h) "era_check -h" - (receive (stdout _) (era-check "-h") + (run-ok-rcv (stdout _) (era-check "-h") (assert-equal era-check-help stdout))) (define-scenario (era-check help) "era_check --help" - (receive (stdout _) (era-check "--help") + (run-ok-rcv (stdout _) (era-check "--help") (assert-equal era-check-help stdout))) (define-scenario (era-check no-device-specified) "Fail if no device specified" - (receive (_ stderr) (run-fail "era_check") + (run-fail-rcv (_ stderr) (era-check) (assert-starts-with "No input file provided." stderr))) (define-scenario (era-check dev-not-exist) "Fail if specified device doesn't exist" - (receive (_ stderr) (run-fail "era_check /dev/unlikely") + (run-fail-rcv (_ stderr) (era-check "/dev/unlikely") (assert-starts-with "/dev/unlikely: No such file or directory" stderr))) (define-scenario (era-check dev-is-a-directory) "Fail if given a directory instead of a file or device" - (receive (_ stderr) (run-fail "era_check /tmp") + (run-fail-rcv (_ stderr) (era-check "/tmp") (assert-starts-with "/tmp: Not a block device or regular file" stderr))) (define-scenario (era-check bad-permissions) "Fail if given a device with inadequate access permissions" (with-temp-file-sized ((md "era.bin" (meg 4))) (run-ok "chmod -r" md) - (receive (_ stderr) (run-fail "era_check" md) + (run-fail-rcv (_ stderr) (era-check md) (assert-starts-with "syscall 'open' failed: Permission denied" stderr)))) (define-scenario (era-check empty-dev) "Fail if given a file of zeroes" (with-empty-metadata (md) - (run-fail "era_check" md))) + (run-fail (era-check md)))) (define-scenario (era-check quiet) "Fail should give no output if --quiet" (with-empty-metadata (md) - (receive (stdout stderr) (run-fail "era_check --quiet" md) + (run-fail-rcv (stdout stderr) (era-check "--quiet" md) (assert-eof stdout) (assert-eof stderr)))) (define-scenario (era-check q) "Fail should give no output if -q" (with-empty-metadata (md) - (receive (stdout stderr) (run-fail "era_check -q" md) + (run-fail-rcv (stdout stderr) (era-check "-q" md) (assert-eof stdout) (assert-eof stderr)))) (define-scenario (era-check tiny-metadata) "Prints helpful message in case tiny metadata given" (with-temp-file-sized ((md "era.bin" 1024)) - (receive (_ stderr) (run-fail "era_check" md) + (run-fail-rcv (_ stderr) (era-check md) (assert-starts-with "Metadata device/file too small. Is this binary metadata?" stderr)))) (define-scenario (era-check spot-accidental-xml-data) "Prints helpful message if XML metadata given" (with-era-xml (xml) (system (fmt #f "man bash >> " xml)) - (receive (_ stderr) (run-fail "era_check" xml) + (run-fail-rcv (_ stderr) (era-check xml) (assert-matches ".*This looks like XML. era_check only checks the binary metadata format." stderr)))) ;;;----------------------------------------------------------- @@ -125,34 +125,34 @@ ;;;----------------------------------------------------------- (define-scenario (era-restore v) "era_restore -V" - (receive (stdout _) (era-restore "-V") + (run-ok-rcv (stdout _) (era-restore "-V") (assert-equal tools-version stdout))) (define-scenario (era-restore version) "era_restore --version" - (receive (stdout _) (era-restore "--version") + (run-ok-rcv (stdout _) (era-restore "--version") (assert-equal tools-version stdout))) (define-scenario (era-restore h) "era_restore -h" - (receive (stdout _) (era-restore "-h") + (run-ok-rcv (stdout _) (era-restore "-h") (assert-equal era-restore-help stdout))) (define-scenario (era-restore help) "era_restore --help" - (receive (stdout _) (era-restore "--help") + (run-ok-rcv (stdout _) (era-restore "--help") (assert-equal era-restore-help stdout))) (define-scenario (era-restore input-unspecified) "Fails if no xml specified" (with-empty-metadata (md) - (receive (_ stderr) (run-fail "era_restore" "-o" md) + (run-fail-rcv (_ stderr) (era-restore "-o" md) (assert-starts-with "No input file provided." stderr)))) (define-scenario (era-restore missing-input-file) "the input file can't be found" (with-empty-metadata (md) - (receive (_ stderr) (run-fail "era_restore -i no-such-file -o" md) + (run-fail-rcv (_ stderr) (era-restore "-i no-such-file -o" md) (assert-superblock-untouched md) (assert-starts-with "Couldn't stat file" stderr)))) @@ -160,26 +160,26 @@ "the input file is just zeroes" (with-empty-metadata (md) (with-temp-file-sized ((xml "era.xml" 4096)) - (receive (_ stderr) (run-fail "era_restore -i " xml "-o" md) + (run-fail-rcv (_ stderr) (era-restore "-i " xml "-o" md) (assert-superblock-untouched md))))) (define-scenario (era-restore output-unspecified) "Fails if no metadata dev specified" (with-era-xml (xml) - (receive (_ stderr) (run-fail "era_restore" "-i" xml) + (run-fail-rcv (_ stderr) (era-restore "-i" xml) (assert-starts-with "No output file provided." stderr)))) (define-scenario (era-restore success) "Succeeds with xml and metadata" (with-era-xml (xml) (with-empty-metadata (md) - (era-restore "-i" xml "-o" md)))) + (run-ok (era-restore "-i" xml "-o" md))))) (define-scenario (era-restore quiet) "No output with --quiet (succeeding)" (with-era-xml (xml) (with-empty-metadata (md) - (receive (stdout stderr) (era-restore "--quiet" "-i" xml "-o" md) + (run-ok-rcv (stdout stderr) (era-restore "--quiet" "-i" xml "-o" md) (assert-eof stdout) (assert-eof stderr))))) @@ -187,7 +187,7 @@ "No output with -q (succeeding)" (with-era-xml (xml) (with-empty-metadata (md) - (receive (stdout stderr) (era-restore "-q" "-i" xml "-o" md) + (run-ok-rcv (stdout stderr) (era-restore "-q" "-i" xml "-o" md) (assert-eof stdout) (assert-eof stderr))))) @@ -195,7 +195,7 @@ "No output with --quiet (failing)" (with-temp-file ((bad-xml "era.xml")) (with-empty-metadata (md) - (receive (stdout stderr) (run-fail "era_restore" "--quiet" "-i" bad-xml "-o" md) + (run-fail-rcv (stdout stderr) (era-restore "--quiet" "-i" bad-xml "-o" md) (assert-eof stdout) (assert-starts-with "Couldn't stat file" stderr))))) @@ -203,7 +203,7 @@ "No output with --q(failing)" (with-temp-file ((bad-xml "era.xml")) (with-empty-metadata (md) - (receive (stdout stderr) (run-fail "era_restore" "-q" "-i" bad-xml "-o" md) + (run-fail-rcv (stdout stderr) (era-restore "-q" "-i" bad-xml "-o" md) (assert-eof stdout) (assert-starts-with "Couldn't stat file" stderr))))) @@ -213,14 +213,14 @@ (define-scenario (era-dump small-input-file) "Fails with small input file" (with-temp-file-sized ((md "era.bin" 512)) - (run-fail "era_dump" md))) + (run-fail (era-dump md)))) (define-scenario (era-dump restore-is-noop) "era_dump followed by era_restore is a noop." (with-valid-metadata (md) - (receive (d1-stdout _) (era-dump md) + (run-ok-rcv (d1-stdout _) (era-dump md) (with-temp-file-containing ((xml "era.xml" d1-stdout)) - (era-restore "-i" xml "-o" md) - (receive (d2-stdout _) (era-dump md) + (run-ok (era-restore "-i" xml "-o" md)) + (run-ok-rcv (d2-stdout _) (era-dump md) (assert-equal d1-stdout d2-stdout)))))) ) diff --git a/functional-tests/functional-tests.scm b/functional-tests/functional-tests.scm index 16d15fe..9622a24 100644 --- a/functional-tests/functional-tests.scm +++ b/functional-tests/functional-tests.scm @@ -189,7 +189,10 @@ (lambda () (get-line (current-input-port)))))) - (define (tool-name sym) + ;;----------------------------------------------- + ;; A 'tool' is a function that builds up a command line. This can then be + ;; passed to the functions in the (process) library. + (define (tool-path sym) (define (to-underscore c) (if (eq? #\- c) #\_ c)) @@ -201,8 +204,10 @@ (define-syntax define-tool (syntax-rules () - ((_ tool-sym) (define (tool-sym . flags) - (apply run-ok (tool-name 'tool-sym) flags))))) + ((_ sym) (define sym + (let ((path (tool-path 'sym))) + (lambda args + (build-command-line (cons path args)))))))) (define (assert-equal str1 str2) (unless (equal? str1 str2) diff --git a/functional-tests/process.scm b/functional-tests/process.scm index d39bd9c..fdae700 100644 --- a/functional-tests/process.scm +++ b/functional-tests/process.scm @@ -1,9 +1,12 @@ (library (process) - (export run + (export build-command-line + run run-ok - run-fail) + run-fail + run-ok-rcv + run-fail-rcv) (import (chezscheme) (fail) @@ -58,5 +61,18 @@ (or (= 139 x) (zero? x)))) - (run-with-exit-code fails? cmd-and-args))) + (run-with-exit-code fails? cmd-and-args)) + + (define-syntax run-ok-rcv + (syntax-rules () + ((_ (stdout stderr) cmd b1 b2 ...) + (receive (stdout stderr) (run-ok cmd) + b1 b2 ...)))) + + (define-syntax run-fail-rcv + (syntax-rules () + ((_ (stdout stderr) cmd b1 b2 ...) + (receive (stdout stderr) (run-fail cmd) + b1 b2 ...)))) + ) diff --git a/functional-tests/thin-functional-tests.scm b/functional-tests/thin-functional-tests.scm index 628989f..7f8ee0d 100644 --- a/functional-tests/thin-functional-tests.scm +++ b/functional-tests/thin-functional-tests.scm @@ -33,7 +33,7 @@ ((_ (md) b1 b2 ...) (with-temp-file-sized ((md "thin.bin" (meg 4))) (with-thin-xml (xml) - (thin-restore "-i" xml "-o" md) + (run-ok (thin-restore "-i" xml "-o" md)) b1 b2 ...))))) ;;; It would be nice if the metadata was at least similar to valid data. @@ -59,71 +59,71 @@ (define-scenario (thin-check v) "thin_check -V" - (receive (stdout _) (thin-check "-V") + (run-ok-rcv (stdout _) (thin-check "-V") (assert-equal tools-version stdout))) (define-scenario (thin-check version) "thin_check --version" - (receive (stdout _) (thin-check "--version") + (run-ok-rcv (stdout _) (thin-check "--version") (assert-equal tools-version stdout))) (define-scenario (thin-check h) "print help (-h)" - (receive (stdout _) (thin-check "-h") + (run-ok-rcv (stdout _) (thin-check "-h") (assert-equal thin-check-help stdout))) (define-scenario (thin-check help) "print help (--help)" - (receive (stdout _) (thin-check "--help") + (run-ok-rcv (stdout _) (thin-check "--help") (assert-equal thin-check-help stdout))) (define-scenario (thin-check bad-option) "Unrecognised option should cause failure" - (run-fail "thin_check --hedgehogs-only")) + (run-fail (thin-check "--hedgehogs-only"))) (define-scenario (thin-check superblock-only-valid) "--super-block-only check passes on valid metadata" (with-valid-metadata (md) - (thin-check "--super-block-only" md))) + (run-ok (thin-check "--super-block-only" md)))) (define-scenario (thin-check superblock-only-invalid) "--super-block-only check fails with corrupt metadata" (with-corrupt-metadata (md) - (run-fail "thin_check --super-block-only" md))) + (run-fail (thin-check "--super-block-only" md)))) (define-scenario (thin-check skip-mappings-valid) "--skip-mappings check passes on valid metadata" (with-valid-metadata (md) - (thin-check "--skip-mappings" md))) + (run-ok (thin-check "--skip-mappings" md)))) (define-scenario (thin-check ignore-non-fatal-errors) "--ignore-non-fatal-errors check passes on valid metadata" (with-valid-metadata (md) - (thin-check "--ignore-non-fatal-errors" md))) + (run-ok (thin-check "--ignore-non-fatal-errors" md)))) (define-scenario (thin-check quiet) "--quiet should give no output" (with-valid-metadata (md) - (receive (stdout stderr) (thin-check "--quiet" md) + (run-ok-rcv (stdout stderr) (thin-check "--quiet" md) (assert-eof stdout) (assert-eof stderr)))) (define-scenario (thin-check clear-needs-check-flag) "Accepts --clear-needs-check-flag" (with-valid-metadata (md) - (thin-check "--clear-needs-check-flag" md))) + (run-ok (thin-check "--clear-needs-check-flag" md)))) (define-scenario (thin-check tiny-metadata) "Prints helpful message in case tiny metadata given" (with-temp-file-sized ((md "thin.bin" 1024)) - (receive (_ stderr) (run-fail "thin_check" md) + (run-fail-rcv (_ stderr) (thin-check md) (assert-starts-with "Metadata device/file too small. Is this binary metadata?" stderr)))) (define-scenario (thin-check spot-accidental-xml-data) "Prints helpful message if XML metadata given" (with-thin-xml (xml) (system (fmt #f "man bash >> " xml)) - (receive (_ stderr) (run-fail "thin_check" xml) + (run-fail-rcv (_ stderr) (thin-check xml) (assert-matches ".*This looks like XML. thin_check only checks the binary metadata format." stderr)))) ;;;----------------------------------------------------------- @@ -132,34 +132,34 @@ (define-scenario (thin-restore print-version-v) "print help (-V)" - (receive (stdout _) (thin-restore "-V") + (run-ok-rcv (stdout _) (thin-restore "-V") (assert-equal tools-version stdout))) (define-scenario (thin-restore print-version-long) "print help (--version)" - (receive (stdout _) (thin-restore "--version") + (run-ok-rcv (stdout _) (thin-restore "--version") (assert-equal tools-version stdout))) (define-scenario (thin-restore h) "print help (-h)" - (receive (stdout _) (thin-restore "-h") + (run-ok-rcv (stdout _) (thin-restore "-h") (assert-equal thin-restore-help stdout))) (define-scenario (thin-restore help) "print help (-h)" - (receive (stdout _) (thin-restore "--help") + (run-ok-rcv (stdout _) (thin-restore "--help") (assert-equal thin-restore-help stdout))) (define-scenario (thin-restore no-input-file) "forget to specify an input file" (with-empty-metadata (md) - (receive (_ stderr) (run-fail "thin_restore" "-o" md) + (run-fail-rcv (_ stderr) (thin-restore "-o" md) (assert-starts-with "No input file provided." stderr)))) (define-scenario (thin-restore missing-input-file) "the input file can't be found" (with-empty-metadata (md) - (receive (_ stderr) (run-fail "thin_restore -i no-such-file -o" md) + (run-fail-rcv (_ stderr) (thin-restore "-i no-such-file -o" md) (assert-superblock-untouched md) (assert-starts-with "Couldn't stat file" stderr)))) @@ -167,34 +167,34 @@ "the input file is just zeroes" (with-empty-metadata (md) (with-temp-file-sized ((xml "thin.xml" 4096)) - (receive (_ stderr) (run-fail "thin_restore -i " xml "-o" md) + (run-fail-rcv (_ stderr) (thin-restore "-i " xml "-o" md) (assert-superblock-untouched md))))) (define-scenario (thin-restore missing-output-file) "the output file can't be found" (with-thin-xml (xml) - (receive (_ stderr) (run-fail "thin_restore -i " xml) + (run-fail-rcv (_ stderr) (thin-restore "-i " xml) (assert-starts-with "No output file provided." stderr)))) (define-scenario (thin-restore tiny-output-file) "Fails if the output file is too small." (with-temp-file-sized ((md "thin.bin" 4096)) (with-thin-xml (xml) - (receive (_ stderr) (run-fail "thin_restore" "-i" xml "-o" md) + (run-fail-rcv (_ stderr) (thin-restore "-i" xml "-o" md) (assert-starts-with thin-restore-outfile-too-small-text stderr))))) (define-scenario (thin-restore q) "thin_restore accepts -q" (with-empty-metadata (md) (with-thin-xml (xml) - (receive (stdout _) (thin-restore "-i" xml "-o" md "-q") + (run-ok-rcv (stdout _) (thin-restore "-i" xml "-o" md "-q") (assert-eof stdout))))) (define-scenario (thin-restore quiet) "thin_restore accepts --quiet" (with-empty-metadata (md) (with-thin-xml (xml) - (receive (stdout _) (thin-restore "-i" xml "-o" md "--quiet") + (run-ok-rcv (stdout _) (thin-restore "-i" xml "-o" md "--quiet") (assert-eof stdout))))) ;;;----------------------------------------------------------- @@ -204,15 +204,15 @@ (define-scenario (thin-dump small-input-file) "Fails with small input file" (with-temp-file-sized ((md "thin.bin" 512)) - (run-fail "thin_dump" md))) + (run-fail (thin-dump md)))) (define-scenario (thin-dump restore-is-noop) "thin_dump followed by thin_restore is a noop." (with-valid-metadata (md) - (receive (d1-stdout _) (thin-dump md) + (run-ok-rcv (d1-stdout _) (thin-dump md) (with-temp-file-containing ((xml "thin.xml" d1-stdout)) - (thin-restore "-i" xml "-o" md) - (receive (d2-stdout _) (thin-dump md) + (run-ok (thin-restore "-i" xml "-o" md)) + (run-ok-rcv (d2-stdout _) (thin-dump md) (assert-equal d1-stdout d2-stdout)))))) ;;;----------------------------------------------------------- @@ -221,49 +221,50 @@ (define-scenario (thin-rmap v) "thin_rmap accepts -V" - (receive (stdout _) (thin-rmap "-V") + (run-ok-rcv (stdout _) (thin-rmap "-V") (assert-equal tools-version stdout))) (define-scenario (thin-rmap version) "thin_rmap accepts --version" - (receive (stdout _) (thin-rmap "--version") + (run-ok-rcv (stdout _) (thin-rmap "--version") (assert-equal tools-version stdout))) (define-scenario (thin-rmap h) "thin_rmap accepts -h" - (receive (stdout _) (thin-rmap "-h") + (run-ok-rcv (stdout _) (thin-rmap "-h") (assert-equal thin-rmap-help stdout))) (define-scenario (thin-rmap help) "thin_rmap accepts --help" - (receive (stdout _) (thin-rmap "--help") + (run-ok-rcv (stdout _) (thin-rmap "--help") (assert-equal thin-rmap-help stdout))) (define-scenario (thin-rmap unrecognised-flag) "thin_rmap complains with bad flags." - (run-fail "thin_rmap --unleash-the-hedgehogs")) + (run-fail (thin-rmap "--unleash-the-hedgehogs"))) (define-scenario (thin-rmap valid-region-format-should-pass) "thin_rmap with a valid region format should pass." (with-valid-metadata (md) - (thin-rmap "--region 23..7890" md))) + (run-ok + (thin-rmap "--region 23..7890" md)))) (define-scenario (thin-rmap invalid-region-should-fail) "thin_rmap with an invalid region format should fail." (for-each (lambda (pattern) (with-valid-metadata (md) - (run-fail "thin_rmap --region" pattern md))) + (run-fail (thin-rmap "--region" pattern md)))) '("23,7890" "23..six" "found..7890" "89..88" "89..89" "89.." "" "89...99"))) (define-scenario (thin-rmap multiple-regions-should-pass) "thin_rmap should handle multiple regions." (with-valid-metadata (md) - (thin-rmap "--region 1..23 --region 45..78" md))) + (run-ok (thin-rmap "--region 1..23 --region 45..78" md)))) (define-scenario (thin-rmap handles-junk-input) "Fail gracefully if given nonsense" (with-thin-xml (xml) - (receive (_ stderr) (run-fail "thin_rmap --region 0..-1" xml) + (run-fail-rcv (_ stderr) (thin-rmap "--region 0..-1" xml) #t))) ;;;----------------------------------------------------------- @@ -271,43 +272,43 @@ ;;;----------------------------------------------------------- (define-scenario (thin-delta v) "thin_delta accepts -V" - (receive (stdout _) (thin-delta "-V") + (run-ok-rcv (stdout _) (thin-delta "-V") (assert-equal tools-version stdout))) (define-scenario (thin-delta version) "thin_delta accepts --version" - (receive (stdout _) (thin-delta "--version") + (run-ok-rcv (stdout _) (thin-delta "--version") (assert-equal tools-version stdout))) (define-scenario (thin-delta h) "thin_delta accepts -h" - (receive (stdout _) (thin-delta "-h") + (run-ok-rcv (stdout _) (thin-delta "-h") (assert-equal thin-delta-help stdout))) (define-scenario (thin-delta help) "thin_delta accepts --help" - (receive (stdout _) (thin-delta "--help") + (run-ok-rcv (stdout _) (thin-delta "--help") (assert-equal thin-delta-help stdout))) (define-scenario (thin-delta unrecognised-option) "Unrecognised option should cause failure" (with-valid-metadata (md) - (receive (stdout stderr) (run-fail "thin_delta --unleash-the-hedgehogs") - (assert-starts-with "thin_delta: unrecognized option '--unleash-the-hedgehogs" stderr)))) + (run-fail-rcv (stdout stderr) (thin-delta "--unleash-the-hedgehogs") + (assert-matches ".*thin_delta: unrecognized option '--unleash-the-hedgehogs" stderr)))) (define-scenario (thin-delta snap1-unspecified) "Fails without --snap1 fails" - (receive (_ stderr) (run-fail "thin_delta --snap2 45 foo") + (run-fail-rcv (_ stderr) (thin-delta "--snap2 45 foo") (assert-starts-with "--snap1 not specified." stderr))) (define-scenario (thin-delta snap2-unspecified) "Fails without --snap2 fails" - (receive (_ stderr) (run-fail "thin_delta --snap1 45 foo") + (run-fail-rcv (_ stderr) (thin-delta "--snap1 45 foo") (assert-starts-with "--snap2 not specified." stderr))) (define-scenario (thin-delta device-unspecified) "Fails if no device given" - (receive (_ stderr) (run-fail "thin_delta --snap1 45 --snap2 46") + (run-fail-rcv (_ stderr) (thin-delta "--snap1 45 --snap2 46") (assert-starts-with "No input device provided." stderr))) ;;;----------------------------------------------------------- @@ -317,6 +318,6 @@ "Fails gracefully if run on XML rather than metadata" (with-thin-xml (xml) (with-empty-metadata (md) - (receive (_ stderr) (run-fail "thin_repair -i " xml "-o" md) + (run-fail-rcv (_ stderr) (thin-repair "-i" xml "-o" md) #t)))) )