[functional-tests] use ../bin in the path for tools, even if they're

failing.
This commit is contained in:
Joe Thornber 2017-10-10 16:51:31 +01:00
parent ad208bd22e
commit 74e2506734
5 changed files with 163 additions and 138 deletions

View File

@ -27,7 +27,7 @@
((_ (md) b1 b2 ...) ((_ (md) b1 b2 ...)
(with-temp-file-sized ((md "cache.bin" (meg 4))) (with-temp-file-sized ((md "cache.bin" (meg 4)))
(with-cache-xml (xml) (with-cache-xml (xml)
(cache-restore "-i" xml "-o" md) (run-ok (cache-restore "-i" xml "-o" md))
b1 b2 ...))))) b1 b2 ...)))))
;;; It would be nice if the metadata was at least similar to valid data. ;;; It would be nice if the metadata was at least similar to valid data.
@ -53,27 +53,27 @@
(define-scenario (cache-check v) (define-scenario (cache-check v)
"cache_check -V" "cache_check -V"
(receive (stdout _) (cache-check "-V") (run-ok-rcv (stdout _) (cache-check "-V")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (cache-check version) (define-scenario (cache-check version)
"cache_check --version" "cache_check --version"
(receive (stdout _) (cache-check "--version") (run-ok-rcv (stdout _) (cache-check "--version")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (cache-check h) (define-scenario (cache-check h)
"cache_check -h" "cache_check -h"
(receive (stdout _) (cache-check "-h") (run-ok-rcv (stdout _) (cache-check "-h")
(assert-equal cache-check-help stdout))) (assert-equal cache-check-help stdout)))
(define-scenario (cache-check help) (define-scenario (cache-check help)
"cache_check --help" "cache_check --help"
(receive (stdout _) (cache-check "--help") (run-ok-rcv (stdout _) (cache-check "--help")
(assert-equal cache-check-help stdout))) (assert-equal cache-check-help stdout)))
(define-scenario (cache-check must-specify-metadata) (define-scenario (cache-check must-specify-metadata)
"Metadata file must be specified" "Metadata file must be specified"
(receive (_ stderr) (run-fail "cache_check") (run-fail-rcv (_ stderr) (cache-check)
(assert-equal (assert-equal
(string-append "No input file provided.\n" (string-append "No input file provided.\n"
cache-check-help) cache-check-help)
@ -82,7 +82,7 @@
(define-scenario (cache-check no-such-metadata) (define-scenario (cache-check no-such-metadata)
"Metadata file doesn't exist." "Metadata file doesn't exist."
(let ((bad-path "/arbitrary/filename")) (let ((bad-path "/arbitrary/filename"))
(receive (_ stderr) (run-fail "cache_check" bad-path) (run-fail-rcv (_ stderr) (cache-check bad-path)
(assert-starts-with (assert-starts-with
(string-append bad-path ": No such file or directory") (string-append bad-path ": No such file or directory")
stderr)))) stderr))))
@ -90,7 +90,7 @@
(define-scenario (cache-check metadata-file-cannot-be-a-directory) (define-scenario (cache-check metadata-file-cannot-be-a-directory)
"Metadata file must not be a directory" "Metadata file must not be a directory"
(let ((bad-path "/tmp")) (let ((bad-path "/tmp"))
(receive (_ stderr) (run-fail "cache_check" bad-path) (run-fail-rcv (_ stderr) (cache-check bad-path)
(assert-starts-with (assert-starts-with
(string-append bad-path ": Not a block device or regular file") (string-append bad-path ": Not a block device or regular file")
stderr)))) stderr))))
@ -99,51 +99,51 @@
"Metadata file exists, but is unreadable." "Metadata file exists, but is unreadable."
(with-valid-metadata (md) (with-valid-metadata (md)
(run-ok "chmod" "-r" 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)))) (assert-starts-with "syscall 'open' failed: Permission denied" stderr))))
(define-scenario (cache-check fails-with-corrupt-metadata) (define-scenario (cache-check fails-with-corrupt-metadata)
"Fail with corrupt superblock" "Fail with corrupt superblock"
(with-corrupt-metadata (md) (with-corrupt-metadata (md)
(run-fail "cache_check" md))) (run-fail (cache-check md))))
(define-scenario (cache-check failing-q) (define-scenario (cache-check failing-q)
"Fail quietly with -q" "Fail quietly with -q"
(with-corrupt-metadata (md) (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 stdout)
(assert-eof stderr)))) (assert-eof stderr))))
(define-scenario (cache-check failing-quiet) (define-scenario (cache-check failing-quiet)
"Fail quietly with --quiet" "Fail quietly with --quiet"
(with-corrupt-metadata (md) (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 stdout)
(assert-eof stderr)))) (assert-eof stderr))))
(define-scenario (cache-check valid-metadata-passes) (define-scenario (cache-check valid-metadata-passes)
"A valid metadata area passes" "A valid metadata area passes"
(with-valid-metadata (md) (with-valid-metadata (md)
(cache-check md))) (run-ok (cache-check md))))
(define-scenario (cache-check bad-metadata-version) (define-scenario (cache-check bad-metadata-version)
"Invalid metadata version fails" "Invalid metadata version fails"
(with-cache-xml (xml) (with-cache-xml (xml)
(with-empty-metadata (md) (with-empty-metadata (md)
(cache-restore "-i" xml "-o" md "--debug-override-metadata-version" "12345") (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) (define-scenario (cache-check tiny-metadata)
"Prints helpful message in case tiny metadata given" "Prints helpful message in case tiny metadata given"
(with-temp-file-sized ((md "cache.bin" 1024)) (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)))) (assert-starts-with "Metadata device/file too small. Is this binary metadata?" stderr))))
(define-scenario (cache-check spot-accidental-xml-data) (define-scenario (cache-check spot-accidental-xml-data)
"Prints helpful message if XML metadata given" "Prints helpful message if XML metadata given"
(with-cache-xml (xml) (with-cache-xml (xml)
(system (fmt #f "man bash >> " 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)))) (assert-matches ".*This looks like XML. cache_check only checks the binary metadata format." stderr))))
;;;----------------------------------------------------------- ;;;-----------------------------------------------------------
@ -152,34 +152,34 @@
(define-scenario (cache-restore v) (define-scenario (cache-restore v)
"print version (-V flag)" "print version (-V flag)"
(receive (stdout _) (cache-restore "-V") (run-ok-rcv (stdout _) (cache-restore "-V")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (cache-restore version) (define-scenario (cache-restore version)
"print version (--version flags)" "print version (--version flags)"
(receive (stdout _) (cache-restore "--version") (run-ok-rcv (stdout _) (cache-restore "--version")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (cache-restore h) (define-scenario (cache-restore h)
"cache_restore -h" "cache_restore -h"
(receive (stdout _) (cache-restore "-h") (run-ok-rcv (stdout _) (cache-restore "-h")
(assert-equal cache-restore-help stdout))) (assert-equal cache-restore-help stdout)))
(define-scenario (cache-restore help) (define-scenario (cache-restore help)
"cache_restore --help" "cache_restore --help"
(receive (stdout _) (cache-restore "--help") (run-ok-rcv (stdout _) (cache-restore "--help")
(assert-equal cache-restore-help stdout))) (assert-equal cache-restore-help stdout)))
(define-scenario (cache-restore no-input-file) (define-scenario (cache-restore no-input-file)
"forget to specify an input file" "forget to specify an input file"
(with-empty-metadata (md) (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)))) (assert-starts-with "No input file provided." stderr))))
(define-scenario (cache-restore missing-input-file) (define-scenario (cache-restore missing-input-file)
"the input file can't be found" "the input file can't be found"
(with-empty-metadata (md) (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-superblock-untouched md)
(assert-starts-with "Couldn't stat file" stderr)))) (assert-starts-with "Couldn't stat file" stderr))))
@ -187,33 +187,33 @@
"the input file is just zeroes" "the input file is just zeroes"
(with-empty-metadata (md) (with-empty-metadata (md)
(with-temp-file-sized ((xml "cache.xml" 4096)) (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))))) (assert-superblock-untouched md)))))
(define-scenario (cache-restore missing-output-file) (define-scenario (cache-restore missing-output-file)
"the output file can't be found" "the output file can't be found"
(with-cache-xml (xml) (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)))) (assert-starts-with "No output file provided." stderr))))
(define-scenario (cache-restore tiny-output-file) (define-scenario (cache-restore tiny-output-file)
"Fails if the output file is too small." "Fails if the output file is too small."
(with-temp-file-sized ((md "cache.bin" (* 1024 4))) (with-temp-file-sized ((md "cache.bin" (* 1024 4)))
(with-cache-xml (xml) (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))))) (assert-starts-with cache-restore-outfile-too-small-text stderr)))))
(define-scenario (cache-restore successfully-restores) (define-scenario (cache-restore successfully-restores)
"Restore succeeds." "Restore succeeds."
(with-empty-metadata (md) (with-empty-metadata (md)
(with-cache-xml (xml) (with-cache-xml (xml)
(cache-restore "-i" xml "-o" md)))) (run-ok (cache-restore "-i" xml "-o" md)))))
(define-scenario (cache-restore q) (define-scenario (cache-restore q)
"cache_restore accepts -q" "cache_restore accepts -q"
(with-empty-metadata (md) (with-empty-metadata (md)
(with-cache-xml (xml) (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 stdout)
(assert-eof stderr))))) (assert-eof stderr)))))
@ -221,7 +221,7 @@
"cache_restore accepts --quiet" "cache_restore accepts --quiet"
(with-empty-metadata (md) (with-empty-metadata (md)
(with-cache-xml (xml) (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 stdout)
(assert-eof stderr))))) (assert-eof stderr)))))
@ -229,13 +229,15 @@
"we can set any metadata version" "we can set any metadata version"
(with-empty-metadata (md) (with-empty-metadata (md)
(with-cache-xml (xml) (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) (define-scenario (cache-restore omit-clean-shutdown)
"accepts --omit-clean-shutdown" "accepts --omit-clean-shutdown"
(with-empty-metadata (md) (with-empty-metadata (md)
(with-cache-xml (xml) (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 ;;; cache_dump scenarios
@ -243,41 +245,42 @@
(define-scenario (cache-dump v) (define-scenario (cache-dump v)
"print version (-V flag)" "print version (-V flag)"
(receive (stdout _) (cache-dump "-V") (run-ok-rcv (stdout _) (cache-dump "-V")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (cache-dump version) (define-scenario (cache-dump version)
"print version (--version flags)" "print version (--version flags)"
(receive (stdout _) (cache-dump "--version") (run-ok-rcv (stdout _) (cache-dump "--version")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (cache-dump h) (define-scenario (cache-dump h)
"cache_dump -h" "cache_dump -h"
(receive (stdout _) (cache-dump "-h") (run-ok-rcv (stdout _) (cache-dump "-h")
(assert-equal cache-dump-help stdout))) (assert-equal cache-dump-help stdout)))
(define-scenario (cache-dump help) (define-scenario (cache-dump help)
"cache_dump --help" "cache_dump --help"
(receive (stdout _) (cache-dump "--help") (run-ok-rcv (stdout _) (cache-dump "--help")
(assert-equal cache-dump-help stdout))) (assert-equal cache-dump-help stdout)))
(define-scenario (cache-dump missing-input-file) (define-scenario (cache-dump missing-input-file)
"Fails with 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))) (assert-starts-with "No input file provided." stderr)))
(define-scenario (cache-dump small-input-file) (define-scenario (cache-dump small-input-file)
"Fails with small input file" "Fails with small input file"
(with-temp-file-sized ((md "cache.bin" 512)) (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) (define-scenario (cache-dump restore-is-noop)
"cache_dump followed by cache_restore is a noop." "cache_dump followed by cache_restore is a noop."
(with-valid-metadata (md) (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)) (with-temp-file-containing ((xml "cache.xml" d1-stdout))
(cache-restore "-i" xml "-o" md) (run-ok (cache-restore "-i" xml "-o" md))
(receive (d2-stdout _) (cache-dump md) (run-ok-rcv (d2-stdout _) (cache-dump md)
(assert-equal d1-stdout d2-stdout)))))) (assert-equal d1-stdout d2-stdout))))))
;;;----------------------------------------------------------- ;;;-----------------------------------------------------------
@ -286,69 +289,69 @@
(define-scenario (cache-metadata-size v) (define-scenario (cache-metadata-size v)
"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))) (assert-equal tools-version stdout)))
(define-scenario (cache-metadata-size version) (define-scenario (cache-metadata-size version)
"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))) (assert-equal tools-version stdout)))
(define-scenario (cache-metadata-size h) (define-scenario (cache-metadata-size h)
"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))) (assert-equal cache-metadata-size-help stdout)))
(define-scenario (cache-metadata-size help) (define-scenario (cache-metadata-size help)
"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))) (assert-equal cache-metadata-size-help stdout)))
(define-scenario (cache-metadata-size no-args) (define-scenario (cache-metadata-size no-args)
"No arguments specified causes fail" "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." (assert-equal "Please specify either --device-size and --block-size, or --nr-blocks."
stderr))) stderr)))
(define-scenario (cache-metadata-size device-size-only) (define-scenario (cache-metadata-size device-size-only)
"Just --device-size causes fail" "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." (assert-equal "If you specify --device-size you must also give --block-size."
stderr))) stderr)))
(define-scenario (cache-metadata-size block-size-only) (define-scenario (cache-metadata-size block-size-only)
"Just --block-size causes fail" "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." (assert-equal "If you specify --block-size you must also give --device-size."
stderr))) stderr)))
(define-scenario (cache-metadata-size conradictory-info-fails) (define-scenario (cache-metadata-size conradictory-info-fails)
"Contradictory info causes fail" "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." (assert-equal "Contradictory arguments given, --nr-blocks doesn't match the --device-size and --block-size."
stderr))) stderr)))
(define-scenario (cache-metadata-size all-args-agree) (define-scenario (cache-metadata-size all-args-agree)
"All args agreeing succeeds" "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-equal "8248 sectors" stdout)
(assert-eof stderr))) (assert-eof stderr)))
(define-scenario (cache-metadata-size nr-blocks-alone) (define-scenario (cache-metadata-size nr-blocks-alone)
"Just --nr-blocks succeeds" "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-equal "8248 sectors" stdout)
(assert-eof stderr))) (assert-eof stderr)))
(define-scenario (cache-metadata-size dev-size-and-block-size-succeeds) (define-scenario (cache-metadata-size dev-size-and-block-size-succeeds)
"Specifying --device-size with --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-equal "8248 sectors" stdout)
(assert-eof stderr))) (assert-eof stderr)))
(define-scenario (cache-metadata-size big-config) (define-scenario (cache-metadata-size big-config)
"A big configuration succeeds" "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-equal "3678208 sectors" stdout)
(assert-eof stderr))) (assert-eof stderr)))
) )

View File

@ -26,7 +26,7 @@
((_ (md) b1 b2 ...) ((_ (md) b1 b2 ...)
(with-temp-file-sized ((md "era.bin" (meg 4))) (with-temp-file-sized ((md "era.bin" (meg 4)))
(with-era-xml (xml) (with-era-xml (xml)
(era-restore "-i" xml "-o" md) (run-ok (era-restore "-i" xml "-o" md))
b1 b2 ...))))) b1 b2 ...)))))
(define-syntax with-corrupt-metadata (define-syntax with-corrupt-metadata
@ -48,76 +48,76 @@
;;;----------------------------------------------------------- ;;;-----------------------------------------------------------
(define-scenario (era-check v) (define-scenario (era-check v)
"era_check -V" "era_check -V"
(receive (stdout _) (era-check "-V") (run-ok-rcv (stdout _) (era-check "-V")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (era-check version) (define-scenario (era-check version)
"era_check --version" "era_check --version"
(receive (stdout _) (era-check "--version") (run-ok-rcv (stdout _) (era-check "--version")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (era-check h) (define-scenario (era-check h)
"era_check -h" "era_check -h"
(receive (stdout _) (era-check "-h") (run-ok-rcv (stdout _) (era-check "-h")
(assert-equal era-check-help stdout))) (assert-equal era-check-help stdout)))
(define-scenario (era-check help) (define-scenario (era-check help)
"era_check --help" "era_check --help"
(receive (stdout _) (era-check "--help") (run-ok-rcv (stdout _) (era-check "--help")
(assert-equal era-check-help stdout))) (assert-equal era-check-help stdout)))
(define-scenario (era-check no-device-specified) (define-scenario (era-check no-device-specified)
"Fail if 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))) (assert-starts-with "No input file provided." stderr)))
(define-scenario (era-check dev-not-exist) (define-scenario (era-check dev-not-exist)
"Fail if specified device doesn't 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))) (assert-starts-with "/dev/unlikely: No such file or directory" stderr)))
(define-scenario (era-check dev-is-a-directory) (define-scenario (era-check dev-is-a-directory)
"Fail if given a directory instead of a file or device" "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))) (assert-starts-with "/tmp: Not a block device or regular file" stderr)))
(define-scenario (era-check bad-permissions) (define-scenario (era-check bad-permissions)
"Fail if given a device with inadequate access permissions" "Fail if given a device with inadequate access permissions"
(with-temp-file-sized ((md "era.bin" (meg 4))) (with-temp-file-sized ((md "era.bin" (meg 4)))
(run-ok "chmod -r" md) (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)))) (assert-starts-with "syscall 'open' failed: Permission denied" stderr))))
(define-scenario (era-check empty-dev) (define-scenario (era-check empty-dev)
"Fail if given a file of zeroes" "Fail if given a file of zeroes"
(with-empty-metadata (md) (with-empty-metadata (md)
(run-fail "era_check" md))) (run-fail (era-check md))))
(define-scenario (era-check quiet) (define-scenario (era-check quiet)
"Fail should give no output if --quiet" "Fail should give no output if --quiet"
(with-empty-metadata (md) (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 stdout)
(assert-eof stderr)))) (assert-eof stderr))))
(define-scenario (era-check q) (define-scenario (era-check q)
"Fail should give no output if -q" "Fail should give no output if -q"
(with-empty-metadata (md) (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 stdout)
(assert-eof stderr)))) (assert-eof stderr))))
(define-scenario (era-check tiny-metadata) (define-scenario (era-check tiny-metadata)
"Prints helpful message in case tiny metadata given" "Prints helpful message in case tiny metadata given"
(with-temp-file-sized ((md "era.bin" 1024)) (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)))) (assert-starts-with "Metadata device/file too small. Is this binary metadata?" stderr))))
(define-scenario (era-check spot-accidental-xml-data) (define-scenario (era-check spot-accidental-xml-data)
"Prints helpful message if XML metadata given" "Prints helpful message if XML metadata given"
(with-era-xml (xml) (with-era-xml (xml)
(system (fmt #f "man bash >> " 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)))) (assert-matches ".*This looks like XML. era_check only checks the binary metadata format." stderr))))
;;;----------------------------------------------------------- ;;;-----------------------------------------------------------
@ -125,34 +125,34 @@
;;;----------------------------------------------------------- ;;;-----------------------------------------------------------
(define-scenario (era-restore v) (define-scenario (era-restore v)
"era_restore -V" "era_restore -V"
(receive (stdout _) (era-restore "-V") (run-ok-rcv (stdout _) (era-restore "-V")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (era-restore version) (define-scenario (era-restore version)
"era_restore --version" "era_restore --version"
(receive (stdout _) (era-restore "--version") (run-ok-rcv (stdout _) (era-restore "--version")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (era-restore h) (define-scenario (era-restore h)
"era_restore -h" "era_restore -h"
(receive (stdout _) (era-restore "-h") (run-ok-rcv (stdout _) (era-restore "-h")
(assert-equal era-restore-help stdout))) (assert-equal era-restore-help stdout)))
(define-scenario (era-restore help) (define-scenario (era-restore help)
"era_restore --help" "era_restore --help"
(receive (stdout _) (era-restore "--help") (run-ok-rcv (stdout _) (era-restore "--help")
(assert-equal era-restore-help stdout))) (assert-equal era-restore-help stdout)))
(define-scenario (era-restore input-unspecified) (define-scenario (era-restore input-unspecified)
"Fails if no xml specified" "Fails if no xml specified"
(with-empty-metadata (md) (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)))) (assert-starts-with "No input file provided." stderr))))
(define-scenario (era-restore missing-input-file) (define-scenario (era-restore missing-input-file)
"the input file can't be found" "the input file can't be found"
(with-empty-metadata (md) (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-superblock-untouched md)
(assert-starts-with "Couldn't stat file" stderr)))) (assert-starts-with "Couldn't stat file" stderr))))
@ -160,26 +160,26 @@
"the input file is just zeroes" "the input file is just zeroes"
(with-empty-metadata (md) (with-empty-metadata (md)
(with-temp-file-sized ((xml "era.xml" 4096)) (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))))) (assert-superblock-untouched md)))))
(define-scenario (era-restore output-unspecified) (define-scenario (era-restore output-unspecified)
"Fails if no metadata dev specified" "Fails if no metadata dev specified"
(with-era-xml (xml) (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)))) (assert-starts-with "No output file provided." stderr))))
(define-scenario (era-restore success) (define-scenario (era-restore success)
"Succeeds with xml and metadata" "Succeeds with xml and metadata"
(with-era-xml (xml) (with-era-xml (xml)
(with-empty-metadata (md) (with-empty-metadata (md)
(era-restore "-i" xml "-o" md)))) (run-ok (era-restore "-i" xml "-o" md)))))
(define-scenario (era-restore quiet) (define-scenario (era-restore quiet)
"No output with --quiet (succeeding)" "No output with --quiet (succeeding)"
(with-era-xml (xml) (with-era-xml (xml)
(with-empty-metadata (md) (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 stdout)
(assert-eof stderr))))) (assert-eof stderr)))))
@ -187,7 +187,7 @@
"No output with -q (succeeding)" "No output with -q (succeeding)"
(with-era-xml (xml) (with-era-xml (xml)
(with-empty-metadata (md) (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 stdout)
(assert-eof stderr))))) (assert-eof stderr)))))
@ -195,7 +195,7 @@
"No output with --quiet (failing)" "No output with --quiet (failing)"
(with-temp-file ((bad-xml "era.xml")) (with-temp-file ((bad-xml "era.xml"))
(with-empty-metadata (md) (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-eof stdout)
(assert-starts-with "Couldn't stat file" stderr))))) (assert-starts-with "Couldn't stat file" stderr)))))
@ -203,7 +203,7 @@
"No output with --q(failing)" "No output with --q(failing)"
(with-temp-file ((bad-xml "era.xml")) (with-temp-file ((bad-xml "era.xml"))
(with-empty-metadata (md) (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-eof stdout)
(assert-starts-with "Couldn't stat file" stderr))))) (assert-starts-with "Couldn't stat file" stderr)))))
@ -213,14 +213,14 @@
(define-scenario (era-dump small-input-file) (define-scenario (era-dump small-input-file)
"Fails with small input file" "Fails with small input file"
(with-temp-file-sized ((md "era.bin" 512)) (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) (define-scenario (era-dump restore-is-noop)
"era_dump followed by era_restore is a noop." "era_dump followed by era_restore is a noop."
(with-valid-metadata (md) (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)) (with-temp-file-containing ((xml "era.xml" d1-stdout))
(era-restore "-i" xml "-o" md) (run-ok (era-restore "-i" xml "-o" md))
(receive (d2-stdout _) (era-dump md) (run-ok-rcv (d2-stdout _) (era-dump md)
(assert-equal d1-stdout d2-stdout)))))) (assert-equal d1-stdout d2-stdout))))))
) )

View File

@ -189,7 +189,10 @@
(lambda () (lambda ()
(get-line (current-input-port)))))) (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) (define (to-underscore c)
(if (eq? #\- c) #\_ c)) (if (eq? #\- c) #\_ c))
@ -201,8 +204,10 @@
(define-syntax define-tool (define-syntax define-tool
(syntax-rules () (syntax-rules ()
((_ tool-sym) (define (tool-sym . flags) ((_ sym) (define sym
(apply run-ok (tool-name 'tool-sym) flags))))) (let ((path (tool-path 'sym)))
(lambda args
(build-command-line (cons path args))))))))
(define (assert-equal str1 str2) (define (assert-equal str1 str2)
(unless (equal? str1 str2) (unless (equal? str1 str2)

View File

@ -1,9 +1,12 @@
(library (library
(process) (process)
(export run (export build-command-line
run
run-ok run-ok
run-fail) run-fail
run-ok-rcv
run-fail-rcv)
(import (chezscheme) (import (chezscheme)
(fail) (fail)
@ -58,5 +61,18 @@
(or (= 139 x) (or (= 139 x)
(zero? 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 ...))))
)

View File

@ -33,7 +33,7 @@
((_ (md) b1 b2 ...) ((_ (md) b1 b2 ...)
(with-temp-file-sized ((md "thin.bin" (meg 4))) (with-temp-file-sized ((md "thin.bin" (meg 4)))
(with-thin-xml (xml) (with-thin-xml (xml)
(thin-restore "-i" xml "-o" md) (run-ok (thin-restore "-i" xml "-o" md))
b1 b2 ...))))) b1 b2 ...)))))
;;; It would be nice if the metadata was at least similar to valid data. ;;; It would be nice if the metadata was at least similar to valid data.
@ -59,71 +59,71 @@
(define-scenario (thin-check v) (define-scenario (thin-check v)
"thin_check -V" "thin_check -V"
(receive (stdout _) (thin-check "-V") (run-ok-rcv (stdout _) (thin-check "-V")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (thin-check version) (define-scenario (thin-check version)
"thin_check --version" "thin_check --version"
(receive (stdout _) (thin-check "--version") (run-ok-rcv (stdout _) (thin-check "--version")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (thin-check h) (define-scenario (thin-check h)
"print help (-h)" "print help (-h)"
(receive (stdout _) (thin-check "-h") (run-ok-rcv (stdout _) (thin-check "-h")
(assert-equal thin-check-help stdout))) (assert-equal thin-check-help stdout)))
(define-scenario (thin-check help) (define-scenario (thin-check help)
"print help (--help)" "print help (--help)"
(receive (stdout _) (thin-check "--help") (run-ok-rcv (stdout _) (thin-check "--help")
(assert-equal thin-check-help stdout))) (assert-equal thin-check-help stdout)))
(define-scenario (thin-check bad-option) (define-scenario (thin-check bad-option)
"Unrecognised option should cause failure" "Unrecognised option should cause failure"
(run-fail "thin_check --hedgehogs-only")) (run-fail (thin-check "--hedgehogs-only")))
(define-scenario (thin-check superblock-only-valid) (define-scenario (thin-check superblock-only-valid)
"--super-block-only check passes on valid metadata" "--super-block-only check passes on valid metadata"
(with-valid-metadata (md) (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) (define-scenario (thin-check superblock-only-invalid)
"--super-block-only check fails with corrupt metadata" "--super-block-only check fails with corrupt metadata"
(with-corrupt-metadata (md) (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) (define-scenario (thin-check skip-mappings-valid)
"--skip-mappings check passes on valid metadata" "--skip-mappings check passes on valid metadata"
(with-valid-metadata (md) (with-valid-metadata (md)
(thin-check "--skip-mappings" md))) (run-ok (thin-check "--skip-mappings" md))))
(define-scenario (thin-check ignore-non-fatal-errors) (define-scenario (thin-check ignore-non-fatal-errors)
"--ignore-non-fatal-errors check passes on valid metadata" "--ignore-non-fatal-errors check passes on valid metadata"
(with-valid-metadata (md) (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) (define-scenario (thin-check quiet)
"--quiet should give no output" "--quiet should give no output"
(with-valid-metadata (md) (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 stdout)
(assert-eof stderr)))) (assert-eof stderr))))
(define-scenario (thin-check clear-needs-check-flag) (define-scenario (thin-check clear-needs-check-flag)
"Accepts --clear-needs-check-flag" "Accepts --clear-needs-check-flag"
(with-valid-metadata (md) (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) (define-scenario (thin-check tiny-metadata)
"Prints helpful message in case tiny metadata given" "Prints helpful message in case tiny metadata given"
(with-temp-file-sized ((md "thin.bin" 1024)) (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)))) (assert-starts-with "Metadata device/file too small. Is this binary metadata?" stderr))))
(define-scenario (thin-check spot-accidental-xml-data) (define-scenario (thin-check spot-accidental-xml-data)
"Prints helpful message if XML metadata given" "Prints helpful message if XML metadata given"
(with-thin-xml (xml) (with-thin-xml (xml)
(system (fmt #f "man bash >> " 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)))) (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) (define-scenario (thin-restore print-version-v)
"print help (-V)" "print help (-V)"
(receive (stdout _) (thin-restore "-V") (run-ok-rcv (stdout _) (thin-restore "-V")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (thin-restore print-version-long) (define-scenario (thin-restore print-version-long)
"print help (--version)" "print help (--version)"
(receive (stdout _) (thin-restore "--version") (run-ok-rcv (stdout _) (thin-restore "--version")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (thin-restore h) (define-scenario (thin-restore h)
"print help (-h)" "print help (-h)"
(receive (stdout _) (thin-restore "-h") (run-ok-rcv (stdout _) (thin-restore "-h")
(assert-equal thin-restore-help stdout))) (assert-equal thin-restore-help stdout)))
(define-scenario (thin-restore help) (define-scenario (thin-restore help)
"print help (-h)" "print help (-h)"
(receive (stdout _) (thin-restore "--help") (run-ok-rcv (stdout _) (thin-restore "--help")
(assert-equal thin-restore-help stdout))) (assert-equal thin-restore-help stdout)))
(define-scenario (thin-restore no-input-file) (define-scenario (thin-restore no-input-file)
"forget to specify an input file" "forget to specify an input file"
(with-empty-metadata (md) (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)))) (assert-starts-with "No input file provided." stderr))))
(define-scenario (thin-restore missing-input-file) (define-scenario (thin-restore missing-input-file)
"the input file can't be found" "the input file can't be found"
(with-empty-metadata (md) (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-superblock-untouched md)
(assert-starts-with "Couldn't stat file" stderr)))) (assert-starts-with "Couldn't stat file" stderr))))
@ -167,34 +167,34 @@
"the input file is just zeroes" "the input file is just zeroes"
(with-empty-metadata (md) (with-empty-metadata (md)
(with-temp-file-sized ((xml "thin.xml" 4096)) (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))))) (assert-superblock-untouched md)))))
(define-scenario (thin-restore missing-output-file) (define-scenario (thin-restore missing-output-file)
"the output file can't be found" "the output file can't be found"
(with-thin-xml (xml) (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)))) (assert-starts-with "No output file provided." stderr))))
(define-scenario (thin-restore tiny-output-file) (define-scenario (thin-restore tiny-output-file)
"Fails if the output file is too small." "Fails if the output file is too small."
(with-temp-file-sized ((md "thin.bin" 4096)) (with-temp-file-sized ((md "thin.bin" 4096))
(with-thin-xml (xml) (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))))) (assert-starts-with thin-restore-outfile-too-small-text stderr)))))
(define-scenario (thin-restore q) (define-scenario (thin-restore q)
"thin_restore accepts -q" "thin_restore accepts -q"
(with-empty-metadata (md) (with-empty-metadata (md)
(with-thin-xml (xml) (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))))) (assert-eof stdout)))))
(define-scenario (thin-restore quiet) (define-scenario (thin-restore quiet)
"thin_restore accepts --quiet" "thin_restore accepts --quiet"
(with-empty-metadata (md) (with-empty-metadata (md)
(with-thin-xml (xml) (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))))) (assert-eof stdout)))))
;;;----------------------------------------------------------- ;;;-----------------------------------------------------------
@ -204,15 +204,15 @@
(define-scenario (thin-dump small-input-file) (define-scenario (thin-dump small-input-file)
"Fails with small input file" "Fails with small input file"
(with-temp-file-sized ((md "thin.bin" 512)) (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) (define-scenario (thin-dump restore-is-noop)
"thin_dump followed by thin_restore is a noop." "thin_dump followed by thin_restore is a noop."
(with-valid-metadata (md) (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)) (with-temp-file-containing ((xml "thin.xml" d1-stdout))
(thin-restore "-i" xml "-o" md) (run-ok (thin-restore "-i" xml "-o" md))
(receive (d2-stdout _) (thin-dump md) (run-ok-rcv (d2-stdout _) (thin-dump md)
(assert-equal d1-stdout d2-stdout)))))) (assert-equal d1-stdout d2-stdout))))))
;;;----------------------------------------------------------- ;;;-----------------------------------------------------------
@ -221,49 +221,50 @@
(define-scenario (thin-rmap v) (define-scenario (thin-rmap v)
"thin_rmap accepts -V" "thin_rmap accepts -V"
(receive (stdout _) (thin-rmap "-V") (run-ok-rcv (stdout _) (thin-rmap "-V")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (thin-rmap version) (define-scenario (thin-rmap version)
"thin_rmap accepts --version" "thin_rmap accepts --version"
(receive (stdout _) (thin-rmap "--version") (run-ok-rcv (stdout _) (thin-rmap "--version")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (thin-rmap h) (define-scenario (thin-rmap h)
"thin_rmap accepts -h" "thin_rmap accepts -h"
(receive (stdout _) (thin-rmap "-h") (run-ok-rcv (stdout _) (thin-rmap "-h")
(assert-equal thin-rmap-help stdout))) (assert-equal thin-rmap-help stdout)))
(define-scenario (thin-rmap help) (define-scenario (thin-rmap help)
"thin_rmap accepts --help" "thin_rmap accepts --help"
(receive (stdout _) (thin-rmap "--help") (run-ok-rcv (stdout _) (thin-rmap "--help")
(assert-equal thin-rmap-help stdout))) (assert-equal thin-rmap-help stdout)))
(define-scenario (thin-rmap unrecognised-flag) (define-scenario (thin-rmap unrecognised-flag)
"thin_rmap complains with bad flags." "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) (define-scenario (thin-rmap valid-region-format-should-pass)
"thin_rmap with a valid region format should pass." "thin_rmap with a valid region format should pass."
(with-valid-metadata (md) (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) (define-scenario (thin-rmap invalid-region-should-fail)
"thin_rmap with an invalid region format should fail." "thin_rmap with an invalid region format should fail."
(for-each (lambda (pattern) (for-each (lambda (pattern)
(with-valid-metadata (md) (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"))) '("23,7890" "23..six" "found..7890" "89..88" "89..89" "89.." "" "89...99")))
(define-scenario (thin-rmap multiple-regions-should-pass) (define-scenario (thin-rmap multiple-regions-should-pass)
"thin_rmap should handle multiple regions." "thin_rmap should handle multiple regions."
(with-valid-metadata (md) (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) (define-scenario (thin-rmap handles-junk-input)
"Fail gracefully if given nonsense" "Fail gracefully if given nonsense"
(with-thin-xml (xml) (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))) #t)))
;;;----------------------------------------------------------- ;;;-----------------------------------------------------------
@ -271,43 +272,43 @@
;;;----------------------------------------------------------- ;;;-----------------------------------------------------------
(define-scenario (thin-delta v) (define-scenario (thin-delta v)
"thin_delta accepts -V" "thin_delta accepts -V"
(receive (stdout _) (thin-delta "-V") (run-ok-rcv (stdout _) (thin-delta "-V")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (thin-delta version) (define-scenario (thin-delta version)
"thin_delta accepts --version" "thin_delta accepts --version"
(receive (stdout _) (thin-delta "--version") (run-ok-rcv (stdout _) (thin-delta "--version")
(assert-equal tools-version stdout))) (assert-equal tools-version stdout)))
(define-scenario (thin-delta h) (define-scenario (thin-delta h)
"thin_delta accepts -h" "thin_delta accepts -h"
(receive (stdout _) (thin-delta "-h") (run-ok-rcv (stdout _) (thin-delta "-h")
(assert-equal thin-delta-help stdout))) (assert-equal thin-delta-help stdout)))
(define-scenario (thin-delta help) (define-scenario (thin-delta help)
"thin_delta accepts --help" "thin_delta accepts --help"
(receive (stdout _) (thin-delta "--help") (run-ok-rcv (stdout _) (thin-delta "--help")
(assert-equal thin-delta-help stdout))) (assert-equal thin-delta-help stdout)))
(define-scenario (thin-delta unrecognised-option) (define-scenario (thin-delta unrecognised-option)
"Unrecognised option should cause failure" "Unrecognised option should cause failure"
(with-valid-metadata (md) (with-valid-metadata (md)
(receive (stdout stderr) (run-fail "thin_delta --unleash-the-hedgehogs") (run-fail-rcv (stdout stderr) (thin-delta "--unleash-the-hedgehogs")
(assert-starts-with "thin_delta: unrecognized option '--unleash-the-hedgehogs" stderr)))) (assert-matches ".*thin_delta: unrecognized option '--unleash-the-hedgehogs" stderr))))
(define-scenario (thin-delta snap1-unspecified) (define-scenario (thin-delta snap1-unspecified)
"Fails without --snap1 fails" "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))) (assert-starts-with "--snap1 not specified." stderr)))
(define-scenario (thin-delta snap2-unspecified) (define-scenario (thin-delta snap2-unspecified)
"Fails without --snap2 fails" "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))) (assert-starts-with "--snap2 not specified." stderr)))
(define-scenario (thin-delta device-unspecified) (define-scenario (thin-delta device-unspecified)
"Fails if no device given" "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))) (assert-starts-with "No input device provided." stderr)))
;;;----------------------------------------------------------- ;;;-----------------------------------------------------------
@ -317,6 +318,6 @@
"Fails gracefully if run on XML rather than metadata" "Fails gracefully if run on XML rather than metadata"
(with-thin-xml (xml) (with-thin-xml (xml)
(with-empty-metadata (md) (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)))) #t))))
) )