diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2016-12-01 22:26:06 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2016-12-05 17:21:48 +0300 |
commit | 66eea6d40b7fd2c12b297f7ce55a62e02f4db291 (patch) | |
tree | b32027be37054d110f52b8280cf8d2b959c78921 | |
parent | caf24aa705243f87c83d346d803adf84888a3cc5 (diff) |
Make use of casts and canonicalizations in testscripts
-rw-r--r-- | build2/test/script/builtin.cxx | 17 | ||||
-rw-r--r-- | build2/test/script/runner.cxx | 6 | ||||
-rw-r--r-- | tests/test/script/builtin/rm.test | 16 | ||||
-rw-r--r-- | tests/test/script/integration/testscript | 27 | ||||
-rw-r--r-- | tests/test/script/runner/cleanup.test | 68 | ||||
-rw-r--r-- | tests/test/script/runner/status.test | 4 | ||||
-rw-r--r-- | tests/value/reverse.test | 10 | ||||
-rw-r--r-- | unit-tests/test/script/parser/scope.test | 11 |
8 files changed, 83 insertions, 76 deletions
diff --git a/build2/test/script/builtin.cxx b/build2/test/script/builtin.cxx index b12ae7e..118f4a9 100644 --- a/build2/test/script/builtin.cxx +++ b/build2/test/script/builtin.cxx @@ -372,9 +372,9 @@ namespace build2 // rm [-r] [-f] <path>... // - // Remove a file or directory. A path must not be the test scope working + // Remove a file or directory. A path must not be the test working // directory or its parent directory. It also must not be outside the - // script working directory unless -f option is specified. Note that + // testscript working directory unless -f option is specified. Note that // directories are not removed by default. // // -r @@ -383,7 +383,7 @@ namespace build2 // // -f // Do not fail if path doesn't exist or no paths specified. Removing - // paths outside the script working directory is not an error. + // paths outside the testscript working directory is not an error. // // The implementation deviates from POSIX in a number of ways. It doesn't // interact with a user and fails immediatelly if unable to process an @@ -441,10 +441,11 @@ namespace build2 { path p (parse_path (*i, sp.wd_path)); - if (!p.sub (sp.root->wd_path) && !force) + const dir_path& wd (sp.root->wd_path); + if (!p.sub (wd) && !force) { - cerr << "rm: '" << p << "' is outside script working directory" - << endl; + cerr << "rm: '" << p << "' is out of working directory '" << wd + << "'" << endl; throw failed (); } @@ -462,8 +463,8 @@ namespace build2 if (sp.wd_path.sub (d)) { - cerr << "rm: '" << p << "' contains scope working directory" - << endl; + cerr << "rm: '" << p << "' contains test working directory '" + << sp.wd_path << "'" << endl; throw failed (); } diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx index 8e336a3..ee059f4 100644 --- a/build2/test/script/runner.cxx +++ b/build2/test/script/runner.cxx @@ -316,8 +316,8 @@ namespace build2 }; // Register the command explicit cleanups. Verify that the path being - // cleaned up is a sub-path of the root test scope working directory. - // Fail if this is not the case. + // cleaned up is a sub-path of the testscript working directory. Fail + // if this is not the case. // for (const auto& cl: c.cleanups) { @@ -326,7 +326,7 @@ namespace build2 bool wc (np.leaf ().string () == "***"); const path& cp (wc ? np.directory () : np); - const path& wd (sp.root->wd_path); + const dir_path& wd (sp.root->wd_path); if (!cp.sub (wd)) fail (ll) << (wc diff --git a/tests/test/script/builtin/rm.test b/tests/test/script/builtin/rm.test index 31dfca0..bb12827 100644 --- a/tests/test/script/builtin/rm.test +++ b/tests/test/script/builtin/rm.test @@ -2,11 +2,7 @@ # copyright : Copyright (c) 2014-2016 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -+if ($cxx.target.class != windows) # @@ TMP trailing separator - s = '/' -else - s = '\' -end +td = $~ : no-args : @@ -63,19 +59,19 @@ rm -r a : : Removing scope directory fails. : -rm -r ./ 2>"rm: '$~$s' contains scope working directory" == 1 +rm -r ./ 2>"rm: '([string] $~)' contains test working directory '$~'" == 1 : outside-scope : -: Removing path outside the script working directory fails. Need to use a path -: that unlikely exists (not to remove something useful). +: Removing path outside the testscript working directory fails. Need to use a +: path that unlikely exists (not to remove something useful). : : -rm ../../a/b/c 2>"rm: '$normalize([path] $~/../../a/b/c)' is outside script working directory" == 1 +rm ../../a/b/c 2>"rm: '$normalize([path] $~/../../a/b/c)' is out of working directory '$td'" == 1 : outside-scope-force : -: Removing path outside the script scope working directory succeeds with -f +: Removing path outside the testscript working directory succeeds with -f : option. Need to use a path that unlikely exists (not to remove something : useful). : diff --git a/tests/test/script/integration/testscript b/tests/test/script/integration/testscript index 8960b88..7cd8f0a 100644 --- a/tests/test/script/integration/testscript +++ b/tests/test/script/integration/testscript @@ -8,6 +8,9 @@ .include ../../common.test +cd = [string] $path.canonicalize(./) +td = [string] $path.canonicalize(test/) + : scrip-files : { @@ -15,18 +18,18 @@ : testscript-and-other : - $* <<EOI 2>>EOE != 0 + $* <<EOI 2>>"EOE" != 0 ./: test{../testscript ../foo} EOI - error: both 'testscript' and other names specified for dir{./} + error: both 'testscript' and other names specified for dir{$cd} EOE : other-and-testscript : - $* <<EOI 2>>EOE != 0 + $* <<EOI 2>>"EOE" != 0 ./: test{../foo ../testscript} EOI - error: both 'testscript' and other names specified for dir{./} + error: both 'testscript' and other names specified for dir{$cd} EOE : others @@ -40,20 +43,20 @@ : touch foo.test; touch test; -$* <<EOI 2>>EOE != 0 +$* <<EOI 2>>"EOE" != 0 ./: test{foo} EOI -error: working directory test/ is a file/symlink +error: working directory $td is a file/symlink EOE : wd-exists-before : touch foo.test; mkdir test &!test/; -$* <<EOI 2>>EOE +$* <<EOI 2>>"EOE" ./: test{foo} EOI -warning: working directory test/ exists at the beginning of the test +warning: working directory $td exists at the beginning of the test EOE : wd-not-empty-before @@ -61,10 +64,10 @@ EOE touch foo.test; mkdir test &!test/; touch test/dummy &!test/dummy; -$* <<EOI 2>>EOE +$* <<EOI 2>>"EOE" ./: test{foo} EOI -warning: working directory test/ exists and is not empty at the beginning of the test +warning: working directory $td exists and is not empty at the beginning of the test EOE : wd-not-empty-after @@ -78,8 +81,8 @@ EOE cat <<EOI >>>foo.test; touch ../../dummy EOI -$* <<EOI 2>>EOE &test/*** != 0 +$* <<EOI 2>>"EOE" &test/*** != 0 ./: test{foo} EOI -error: working directory test/ is not empty at the end of the test +error: working directory $td is not empty at the end of the test EOE diff --git a/tests/test/script/runner/cleanup.test b/tests/test/script/runner/cleanup.test index 52c0a29..c68304c 100644 --- a/tests/test/script/runner/cleanup.test +++ b/tests/test/script/runner/cleanup.test @@ -6,6 +6,8 @@ b += --no-column +td = [string] $path.canonicalize(test/) + # Valid cleanups. # # @@ TODO: $c <"$* -f a &a" && $b @@ -27,7 +29,7 @@ $b : file-implicit : -: Test that a file created out of the script working directory is not +: Test that a file created out of the testscript working directory is not : implicitly registered for cleanup. If it were, the test would fail due to : 'rm' failure. : @@ -59,7 +61,7 @@ $b : dir-implicit : -: Test that a directory created out of the script working directory is not +: Test that a directory created out of the testscript working directory is not : implicitly registered for cleanup. If it were, the test would fail due to : 'rm' failure. : @@ -91,27 +93,27 @@ $b : Test cleanup of non-existing file. : $c <"$* &a"; -$b 2>>EOE != 0 -testscript:1: error: registered for cleanup file test/1/a does not exist +$b 2>>"EOE" != 0 +testscript:1: error: registered for cleanup file $path.canonicalize(test/1/a) does not exist EOE : file-out-wd : -: Test explicit cleanup of a file out of the script working directory. +: Test explicit cleanup of a file out of the testscript working directory. : $c <"$* &../../a"; -$b 2>>EOE != 0 -testscript:1: error: file cleanup ../../a is out of working directory test/ +$b 2>>"EOE" != 0 +testscript:1: error: file cleanup $path.canonicalize(../../a) is out of working directory $td EOE : file-in-wd : -: Test cleanup explicit registration of a file being outside the scope working +: Test cleanup explicit registration of a file being outside the test working : directory but inside the script working directory. : $c <"$* &../a"; -$b 2>>EOE != 0 -testscript:1: error: registered for cleanup file test/a does not exist +$b 2>>"EOE" != 0 +testscript:1: error: registered for cleanup file $path.canonicalize(test/a) does not exist EOE : not-file @@ -126,27 +128,27 @@ $b 2>- != 0 # @@ REGEX : Test cleanup of non-existing directory. : $c <"$* &a/"; -$b 2>>EOE != 0 -testscript:1: error: registered for cleanup directory test/1/a/ does not exist +$b 2>>"EOE" != 0 +testscript:1: error: registered for cleanup directory ([string] $path.canonicalize(test/1/a/)) does not exist EOE : dir-out-wd : -: Test cleanup of a directory out of the script working directory. +: Test cleanup of a directory out of the testscript working directory. : $c <"$* &../../a/"; -$b 2>>EOE != 0 -testscript:1: error: directory cleanup ../../a/ is out of working directory test/ +$b 2>>"EOE" != 0 +testscript:1: error: directory cleanup ([string] $path.canonicalize(../../a/)) is out of working directory $td EOE : dir-in-wd : -: Test cleanup explicit registration of a directory being outside the scope -: working directory but inside the script working directory. +: Test cleanup explicit registration of a directory being outside the test +: working directory but inside the testscript working directory. : $c <"$* &../a/"; -$b 2>>EOE != 0 -testscript:1: error: registered for cleanup directory test/a/ does not exist +$b 2>>"EOE" != 0 +testscript:1: error: registered for cleanup directory ([string] $path.canonicalize(test/a/)) does not exist EOE : dir-not-empty @@ -154,8 +156,8 @@ EOE : Test cleanup of a non-empty directory. : $c <"$* -d a -f a/b &a/"; -$b 2>>EOE != 0 -testscript:1: error: registered for cleanup directory test/1/a/ is not empty +$b 2>>"EOE" != 0 +testscript:1: error: registered for cleanup directory ([string] $path.canonicalize(test/1/a/)) is not empty EOE : not-dir @@ -170,27 +172,27 @@ $b 2>- != 0 # @@ REGEX : Test cleanup of a wildcard not matching any directory. : $c <"$* &a/***"; -$b 2>>EOE != 0 -testscript:1: error: registered for cleanup wildcard test/1/a/*** doesn't match a directory +$b 2>>"EOE" != 0 +testscript:1: error: registered for cleanup wildcard $path.canonicalize(test/1/a/***) doesn't match a directory EOE : wildcard-out-wd : -: Test cleanup of a wildcard out of the script working directory. +: Test cleanup of a wildcard out of the testscript working directory. : $c <"$* &../../a/***"; -$b 2>>EOE != 0 -testscript:1: error: wildcard cleanup ../../a/*** is out of working directory test/ +$b 2>>"EOE" != 0 +testscript:1: error: wildcard cleanup $path.canonicalize(../../a/***) is out of working directory $td EOE : wildcard-in-wd : : Test cleanup registration of a wildcard matching the directory that being -: outside the scope working directory is inside the script working directory. +: outside the test working directory is inside the testscript working directory. : $c <"$* &../a/***"; -$b 2>>EOE != 0 -testscript:1: error: registered for cleanup wildcard test/a/*** doesn't match a directory +$b 2>>"EOE" != 0 +testscript:1: error: registered for cleanup wildcard $path.canonicalize(test/a/***) doesn't match a directory EOE : wildcard-not-dir @@ -205,8 +207,8 @@ $b 2>- != 0 # @@ REGEX : Test an implicit cleanup being overwritten with the explicit one, : $c <"$* -o foo >>>a &!a"; -$b 2>>EOE != 0 -testscript:1: error: registered for cleanup directory test/1/ is not empty +$b 2>>"EOE" != 0 +testscript:1: error: registered for cleanup directory ([string] $path.canonicalize(test/1/)) is not empty EOE : explicit-overwrite @@ -217,6 +219,6 @@ $c <<"EOO"; $* &!a; $* -o foo >>>a EOO -$b 2>>EOE != 0 -testscript:2: error: registered for cleanup directory test/1/ is not empty +$b 2>>"EOE" != 0 +testscript:2: error: registered for cleanup directory ([string] $path.canonicalize(test/1/)) is not empty EOE diff --git a/tests/test/script/runner/status.test b/tests/test/script/runner/status.test index f743518..941d485 100644 --- a/tests/test/script/runner/status.test +++ b/tests/test/script/runner/status.test @@ -28,12 +28,12 @@ $b : $c <"$* -s 1 == 0"; $b 2>>"EOE" != 0 -testscript:1: error: ../../../driver$ext exit status 1 != 0 +testscript:1: error: $path.canonicalize(../../../driver$ext) exit status 1 != 0 EOE : ne-false : $c <"$* -s 1 != 1"; $b 2>>"EOE" != 0 -testscript:1: error: ../../../driver$ext exit status 1 == 1 +testscript:1: error: $path.canonicalize(../../../driver$ext) exit status 1 == 1 EOE diff --git a/tests/value/reverse.test b/tests/value/reverse.test index 2ebfe68..52c21e8 100644 --- a/tests/value/reverse.test +++ b/tests/value/reverse.test @@ -1,4 +1,4 @@ -# file : tests/directive/reverse.test +# file : tests/value/reverse.test # copyright : Copyright (c) 2014-2016 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file @@ -46,17 +46,15 @@ EOO : dir-path : -r = ([string] $path.canonicalize(foo/bar/)); -s = ([string] $path.canonicalize(foo/bar)); $* <<EOI >>"EOO" x = [dir_path] foo/bar/ print ([string] $x) print "$x" print "-I$x" EOI -$r -$s --I$s +foo/bar/ +foo/bar +-Ifoo/bar EOO : dir-path-root diff --git a/unit-tests/test/script/parser/scope.test b/unit-tests/test/script/parser/scope.test index 44aebee..24b4a42 100644 --- a/unit-tests/test/script/parser/scope.test +++ b/unit-tests/test/script/parser/scope.test @@ -1,16 +1,23 @@ +# @@ REGEX Note that the script can still fail on POSIX for space-containing +# paths. +# +if ($cxx.target.class == "windows") + q = "'" +end + $* testscript <'cmd $@' >"cmd 1" # id-testscript $* foo.test <'cmd $@' >"cmd foo/1" # id wd = [dir_path] $~; wd += test-driver; wd += 1; -$* testscript <'cmd "$~"' >"cmd $wd" # wd-testscript +$* testscript <'cmd "$~"' >"cmd $q$wd$q" # wd-testscript wd = [dir_path] $~; wd += test-driver; wd += foo; wd += 1; -$* foo.test <'cmd "$~"' >"cmd $wd" # wd +$* foo.test <'cmd "$~"' >"cmd $q$wd$q" # wd $* -s <<EOI # group-empty { |