From 278140ebf2bc97eb72a1e8adb04a40a0a5807d8f Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 4 Nov 2016 10:51:57 +0300 Subject: Add mkdir and touch builtins --- tests/test/script/integration/testscript | 20 ++--- tests/test/script/runner/buildfile | 5 +- tests/test/script/runner/cleanup.test | 122 ++++++++++++++++++++++++------- tests/test/script/runner/mkdir.test | 50 +++++++++++++ tests/test/script/runner/redirect.test | 107 ++++++++++++++++++--------- tests/test/script/runner/status.test | 45 ++++++++++-- tests/test/script/runner/touch.test | 44 +++++++++++ 7 files changed, 316 insertions(+), 77 deletions(-) create mode 100644 tests/test/script/runner/mkdir.test create mode 100644 tests/test/script/runner/touch.test (limited to 'tests') diff --git a/tests/test/script/integration/testscript b/tests/test/script/integration/testscript index f9e89e2..8663e6f 100644 --- a/tests/test/script/integration/testscript +++ b/tests/test/script/integration/testscript @@ -2,7 +2,7 @@ # copyright : Copyright (c) 2014-2016 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -+mkdir build &build/ # @@ TMP ++mkdir build +cat <>>build/boostrap.build project = test amalgamation = @@ -39,14 +39,12 @@ test.arguments = test $* <>EOE != 0 ./: test{foo} EOI @@ -55,7 +53,7 @@ EOE : wd-exists-before : -touch foo.test &foo.test; #@@ TMP +touch foo.test; mkdir test &!test/; $* <>EOE ./: test{foo} @@ -65,7 +63,7 @@ EOE : wd-not-empty-before : -touch foo.test &foo.test; #@@ TMP +touch foo.test; mkdir test &!test/; touch test/dummy &!test/dummy; $* <>EOE @@ -78,11 +76,13 @@ EOE : wd-not-empty-after : : The idea here is to run a nested testscript that creates (but does not -: clean up) a file in our working directory. Note that we still have to -: remove everything after detecting the failure. +: clean up) a file in our working directory. Note that an implicit cleanup +: cancelation is not required as the file is out of the test root directory +: scope. Also note that we still have to remove everything after detecting the +: failure. : cat <>>foo.test; -touch ../../dummy &!../../dummy +touch ../../dummy EOI $* <>EOE &test/*** != 0 ./: test{foo} diff --git a/tests/test/script/runner/buildfile b/tests/test/script/runner/buildfile index e5f2761..b9c0e69 100644 --- a/tests/test/script/runner/buildfile +++ b/tests/test/script/runner/buildfile @@ -4,6 +4,9 @@ import libs = libbutl%lib{butl} -exe{driver}: cxx{driver} $libs test{cleanup redirect status} +exe{driver}: cxx{driver} $libs test{cleanup mkdir redirect status touch} + +if ($cxx.target.class == "windows") # @@ TMP + test{*}: ext = ".exe" include ../../../../../build2/ diff --git a/tests/test/script/runner/cleanup.test b/tests/test/script/runner/cleanup.test index bb65c27..4cd8650 100644 --- a/tests/test/script/runner/cleanup.test +++ b/tests/test/script/runner/cleanup.test @@ -2,7 +2,7 @@ # copyright : Copyright (c) 2014-2016 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -+mkdir build &build/ # @@ Should not be necessary once builtin. ++mkdir build +cat <>>build/boostrap.build project = test amalgamation = @@ -13,6 +13,7 @@ EOI b = $build.driver -q --no-column --buildfile - <"./: test{testscript}" \ &?test/*** test c = cat >>>testscript +test = \'$test\' # Valid cleanups. # @@ -33,6 +34,28 @@ $b $c <"$* &!a"; $b +: file-implicit +: +: Test that a file created out of the script working directory is not +: implicitly registered for cleanup. If it were, the test would fail due to +: 'rm' failure. +: +$c <"touch ../../a"; +$b; +rm a + +: file-append +: +: Test that file append redirect doesn't not register cleanup. If it did, that +: cleanup would fail as the file would be already deleted by 'rm'. +: +$c <>>&a; +rm a +EOI +$b + : dir-always : $c <"$* -d a &a/"; @@ -43,6 +66,16 @@ $b $c <"$* &?a/"; $b +: dir-implicit +: +: Test that a directory created out of the script working directory is not +: implicitly registered for cleanup. If it were, the test would fail due to +: 'rm' failure. +: +$c <"mkdir ../../a"; +$b; +rm -r a + : wildcard-always : $c <"$* -d a/b -f a/b/c &a/***"; @@ -54,7 +87,8 @@ $c <"$* &?a/***"; $b : order -: Test that cleanup is performed in registration reversed order +: +: Test that cleanup is performed in registration reversed order. : $c <"$* -d a/b &a/ &a/b/"; $b @@ -62,7 +96,8 @@ $b # Invalid cleanups. # : file-not-exists -: Test cleanup of non-existing file +: +: Test cleanup of non-existing file. : $c <"$* &a"; $b 2>>EOE != 0 @@ -70,23 +105,34 @@ testscript:1: error: registered for cleanup file test/1/a does not exist EOE : file-out-wd -: Test cleanup of file out of working directory +: +: Test explicit cleanup of a file out of the script working directory. +: +$c <"$* &../../a"; +$b 2>>EOE != 0 +testscript:1: error: file cleanup ../../a is out of working directory test/ +EOE + +: file-in-wd +: +: Test cleanup explicit registration of a file being outside the scope working +: directory but inside the script working directory. : $c <"$* &../a"; $b 2>>EOE != 0 -testscript:1: error: registered for cleanup file test/a is out of working directory test/1/ +testscript:1: error: registered for cleanup file test/a does not exist EOE : not-file -: Test cleanup of directory as a file +: +: Test cleanup of a directory as a file. : $c <"$* -d a &a"; -$b 2>>EOE != 0 -error: unable to remove file test/1/a: Is a directory -EOE +$b 2>- != 0 # @@ REGEX : dir-not-exists -: Test cleanup of non-existing directory +: +: Test cleanup of non-existing directory. : $c <"$* &a/"; $b 2>>EOE != 0 @@ -94,15 +140,27 @@ testscript:1: error: registered for cleanup directory test/1/a/ does not exist EOE : dir-out-wd -: Test cleanup of directory out of working directory +: +: Test cleanup of a directory out of the script working directory. +: +$c <"$* &../../a/"; +$b 2>>EOE != 0 +testscript:1: error: directory cleanup ../../a/ is out of working directory test/ +EOE + +: dir-in-wd +: +: Test cleanup explicit registration of a directory being outside the scope +: working directory but inside the script working directory. : $c <"$* &../a/"; $b 2>>EOE != 0 -testscript:1: error: registered for cleanup directory test/a/ is out of working directory test/1/ +testscript:1: error: registered for cleanup directory test/a/ does not exist EOE : dir-not-empty -: Test cleanup of non-empty directory +: +: Test cleanup of a non-empty directory. : $c <"$* -d a -f a/b &a/"; $b 2>>EOE != 0 @@ -110,15 +168,15 @@ testscript:1: error: registered for cleanup directory test/1/a/ is not empty EOE : not-dir -: Test cleanup of file as a directory +: +: Test cleanup of a file as a directory. : $c <"$* -f a &a/"; -$b 2>>EOE != 0 -error: unable to remove directory test/1/a/: Not a directory -EOE +$b 2>- != 0 # @@ REGEX : wildcard-not-exists -: Test cleanup of wildcard not matching any directory +: +: Test cleanup of a wildcard not matching any directory. : $c <"$* &a/***"; $b 2>>EOE != 0 @@ -126,23 +184,34 @@ testscript:1: error: registered for cleanup wildcard test/1/a/*** doesn't match EOE : wildcard-out-wd -: Test cleanup of wildcard out of working directory +: +: Test cleanup of a wildcard out of the script working directory. +: +$c <"$* &../../a/***"; +$b 2>>EOE != 0 +testscript:1: error: wildcard cleanup ../../a/*** is out of working directory test/ +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. : $c <"$* &../a/***"; $b 2>>EOE != 0 -testscript:1: error: registered for cleanup wildcard test/a/*** is out of working directory test/1/ +testscript:1: error: registered for cleanup wildcard test/a/*** doesn't match a directory EOE : wildcard-not-dir -: Test cleanup of file as a wildcard +: +: Test cleanup of a file as a wildcard. : $c <"$* -f a &a/***"; -$b 2>>EOE != 0 -error: unable to remove directory test/1/a/: Not a directory -EOE +$b 2>- != 0 # @@ REGEX : implicit-overwrite -: Test implicit cleanup being overwritten with an explicit one +: +: Test an implicit cleanup being overwritten with the explicit one, : $c <"$* -o foo >>>a &!a"; $b 2>>EOE != 0 @@ -150,7 +219,8 @@ testscript:1: error: registered for cleanup directory test/1/ is not empty EOE : explicit-overwrite -: Test explicit cleanup not being overwritten with an implicit one +: +: Test an explicit cleanup not being overwritten with the implicit one. : $c <"mkdir: missing directory" == 1 + +: empty-path +: +: Test creation of empty directory path. +: +mkdir '' 2>"mkdir: invalid path ''" == 1 + +: already-exists +: +: Test creation of an existing directory. Note that error message is +: platform-dependent so is not checked. +: +mkdir a 2>- a == 1 # @@ REGEX + +: not-exists +: +: Test creation of a directory with non-existent parent. Note that error +: message is platform-dependent so is not checked. +: +mkdir a/b 2>- == 1 # @@ REGEX diff --git a/tests/test/script/runner/redirect.test b/tests/test/script/runner/redirect.test index a49cd3c..68cc9aa 100644 --- a/tests/test/script/runner/redirect.test +++ b/tests/test/script/runner/redirect.test @@ -2,31 +2,39 @@ # copyright : Copyright (c) 2014-2016 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -$* -o foo >- # out-null -$* -e foo 2>- # err-null -$* -i 0 foo # out-str -$* -e foo 2>foo # err-str -$* -i 1 foo # inout-str -$* -i 2 foo # inerr-str -$* -i 1 -e bar foo 2>bar # inout-err-str - -$* -i 0 <- : out-null +$* -e foo 2>- : err-null +$* -i 0 foo : out-str +$* -e foo 2>foo : err-str +$* -i 1 foo : inout-str +$* -i 2 foo : inerr-str +$* -i 1 -e bar foo 2>bar : inout-err-str + +: in-doc +: +$* -i 0 <>EOO # out-doc +: out-doc +: +$* -o foo -o bar >>EOO foo bar EOO -$* -e foo -e bar 2>>EOO # err-doc +: err-doc +: +$* -e foo -e bar 2>>EOO foo bar EOO -$* -i 1 <>EOO # inout-doc +: inout-doc +: +$* -i 1 <>EOO foo bar EOI @@ -34,7 +42,9 @@ foo bar EOO -$* -i 2 <>EOE # inerr-doc +: inerr-doc +: +$* -i 2 <>EOE foo bar EOI @@ -42,22 +52,15 @@ foo bar EOE -$* -i 1 -e bar -e baz -s 2 <>EOO 2>>EOE == 2 # inout-err-doc-status -foo -bar +: empty-str-doc +: +$* -i 1 -e "" <>EOO 2>"" EOI -foo -bar EOO -bar -baz -EOE -$* -i 1 -e "" <>EOO 2>"" # empty-str-doc -EOI -EOO - -$* -i 1 <>EOO # nl-containing-doc +: nl-containing-doc +: +$* -i 1 <>EOO EOI @@ -67,13 +70,18 @@ EOO # # @@ TMP Need does not compare test. # -$* -i 1 <:"foo" >:"foo" # no-newline-str +: no-newline-str +: +$* -i 1 <:"foo" >:"foo" + #\ $* -i 1 <:"foo" >!"foo" # no-newline-str-fail1 $* -i 1 <"foo" >:!"foo" # no-newline-str-fail2 #\ -$* -i 1 <<:EOI >>:EOO # no-newline-doc +: no-newline-doc +: +$* -i 1 <<:EOI >>:EOO foo EOI foo @@ -93,29 +101,39 @@ foo EOO #\ -$* -i 1 <<:EOI >>:EOO 2>:"" # no-newline-empty-str-doc +: no-newline-empty-str-doc +: +$* -i 1 <<:EOI >>:EOO 2>:"" EOI EOO -$* -i 1 <<:EOI >>:EOO # no-newline-nl-cont-doc +: no-newline-nl-cont-doc +: +$* -i 1 <<:EOI >>:EOO EOI EOO -$* -o foo >>>out; # file +: file +: +$* -o foo >>>out; $* -e bar 2>>>&out; $* -i 1 <<>EOO foo bar EOO -$* -o foo -e bar 2>>EOE 1>&2 # merge-str +: merge-str +: +$* -o foo -e bar 2>>EOE 1>&2 foo bar EOE -$* -i 1 <>EOO 2>&1 # merge-doc +: merge-doc +: +$* -i 1 <>EOO 2>&1 foo bar EOI @@ -124,7 +142,9 @@ bar baz EOO -$* -o foo -e bar 2>&1 >>>out; # merge-file +: merge-file +: +$* -o foo -e bar 2>&1 >>>out; $* -e baz -o biz 1>&2 2>>>&out; $* -i 1 <<>EOO foo @@ -132,3 +152,20 @@ bar baz biz EOO + +# Builtins redirects. +# +# @@ That will probably become redundant when builtins and process obtain file +# descriptors uniformly. +# +: builtins +: +{ + echo "abc" >- : out-null + echo "abc" 1>&2 2>- : err-null + echo - : in-str + echo "foo" >foo : out-str + echo "foo" 2>foo 1>&2 : err-str + cat foo : inout-str # @@ cat is not a builtin yet. + cat foo 1>&2 : inerr-str +} diff --git a/tests/test/script/runner/status.test b/tests/test/script/runner/status.test index 0ef1ee9..f1ad5bf 100644 --- a/tests/test/script/runner/status.test +++ b/tests/test/script/runner/status.test @@ -2,8 +2,43 @@ # copyright : Copyright (c) 2014-2016 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -$* # status-def @@ status- is already in file name -$* == 0 # status-eq-0 -$* -s 1 != 0 # status-ne-0 -$* -s 1 == 1 # status-eq-1 -$* != 1 # status-ne-1 ++mkdir build ++cat <>>build/boostrap.build +project = test +amalgamation = + +using test +EOI + +b = $build.driver -q --no-column --buildfile - <"./: test{testscript}" \ + &?test/*** test +c = cat >>>testscript +test = \'$test\' + +# Successfull tests. +# +: eq-true +: +$c <"$* == 0"; +$b + +: ne-true +: +$c <"$* -s 1 != 0"; +$b + +# Faulty tests. +# +: eq-false +: +$c <"$* -s 1 == 0"; +$b 2>>EOE != 0 +testscript:1: error: ../../../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 +EOE diff --git a/tests/test/script/runner/touch.test b/tests/test/script/runner/touch.test new file mode 100644 index 0000000..e9d9f68 --- /dev/null +++ b/tests/test/script/runner/touch.test @@ -0,0 +1,44 @@ +# file : tests/test/script/runner/touch.test +# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: file +: +touch a + +: file-create +: +: Test that file is created. If it didn't then 'rm' would fail. +: +touch a &!a; +rm a + +: file-update +: +: Test that existing file touch doesn't register cleanup. If it did then it +: would be left dangling after 'rm' call and so test would fail. +: +$* -f a; +touch a; +rm a + +: no-args +: +: Test passing no arguments. +: +touch 2>"touch: missing file" == 1 + +: empty-path +: +: Test touching an empty path. +: +touch '' 2>"touch: invalid path ''" == 1 + +: dir-update +: +: Test touching an existing directory. +: +a = [path] $~; +a += "a"; +mkdir a; +touch 2>"touch: '$a' exists and is not a file" a == 1 -- cgit v1.1