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 /build2 | |
parent | ea84c30622ea265b38ec7235c707f8b75df78b16 (diff) |
Implement testscript working directory cleanup
Diffstat (limited to 'build2')
-rw-r--r-- | build2/test/rule.cxx | 33 |
1 files changed, 24 insertions, 9 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. // |