diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-10-31 12:06:24 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-11-04 09:26:36 +0200 |
commit | bd6ebe8c2ca359fb201b84d9004b650d943b4d51 (patch) | |
tree | 8012400544cea13ffc422e915363fb78286d8eb2 | |
parent | ea84c30622ea265b38ec7235c707f8b75df78b16 (diff) |
Implement testscript working directory cleanup
-rw-r--r-- | build2/test/rule.cxx | 33 | ||||
-rw-r--r-- | tests/test/script/integration/testscript | 38 |
2 files changed, 53 insertions, 18 deletions
diff --git a/build2/test/rule.cxx b/build2/test/rule.cxx index 36b92f2..12b052f 100644 --- a/build2/test/rule.cxx +++ b/build2/test/rule.cxx @@ -388,18 +388,33 @@ namespace build2 wd /= "test-" + t.name; // If this is a (potentially) multi-testscript test, then create (and - // cleanup) the root directory. If this is just 'testscript', then the - // root directory is used directly as test's working directory and it's - // the runner's responsibility to create and clean it up. + // later cleanup) the root directory. If this is just 'testscript', then + // the root directory is used directly as test's working directory and + // it's the runner's responsibility to create and clean it up. // - if (!*one) + // What should we do if the directory already exists? We used to fail + // which meant the user had to go and clean things up manually every + // time a test failed. This turned out to be really annoying. So now we + // issue a warning and clean it up automatically. The drawbacks of this + // approach are the potential loss of data from the previous failed test + // run and the possibility of deleting user-created files. + // + if (exists (static_cast<const path&> (wd), false)) + fail << "working directory " << wd << " is a file/symlink"; + + if (exists (wd)) { - if (!exists (wd)) - mkdir (wd, 2); - else if (!empty (wd)) - fail << "working directory " << wd << " is not empty at the " - << "beginning of the test"; + bool e (empty (wd)); + + warn << "working directory " << wd << " exists " + << (e ? "" : "and is not empty ") << "at the beginning " + << "of the test"; + + if (!e) + build2::rmdir_r (wd, false, 2); } + else if (!*one) + mkdir (wd, 2); // Run all the testscripts. // diff --git a/tests/test/script/integration/testscript b/tests/test/script/integration/testscript index 27c1a5d..658a6dc 100644 --- a/tests/test/script/integration/testscript +++ b/tests/test/script/integration/testscript @@ -36,22 +36,42 @@ EOI -rm -f testscript foo.test bar.test } -# work-dir-not-empty-begin +# work-dir-file # -touch foo.test; -mkdir test; -touch test/dummy; -$* <<EOI 2>>EOE != 0; +touch foo.test &foo.test; #@@ TMP +touch test &test; #@@ TMP +$* <<EOI 2>>EOE != 0 ./: test{foo} EOI -error: working directory test/ is not empty at the beginning of the test +error: working directory test/ is a file/symlink +EOE + +# work-dir-exists +# +touch foo.test &foo.test; #@@ TMP +mkdir test; #@@ Need a way to ignore/deregister cleanup. +$* <<EOI 2>>EOE +./: test{foo} +EOI +warning: working directory test/ exists at the beginning of the test +EOE + +# work-dir-not-empty +# +touch foo.test &foo.test; #@@ TMP +mkdir test; #@@ Need a way to ignore/deregister cleanup. +touch test/dummy; #@@ Need a way to ignore/deregister cleanup. +$* <<EOI 2>>EOE +./: test{foo} +EOI +warning: working directory test/ exists and is not empty at the beginning \ +of the test EOE -rm -f test/dummy foo.test; -rmdir test # work-dir-not-empty-end # -# @@ No (easy) way to test this. +# @@ No (easy) way to test this. Maybe if the inner test creates something +# without cleanup? -rm -f build/bootstrap.build -rmdir build/ |