nitunit: testsuite+diff tries additional `.res` files
authorJean Privat <jean@pryen.org>
Thu, 2 Jun 2016 23:44:47 +0000 (19:44 -0400)
committerJean Privat <jean@pryen.org>
Fri, 3 Jun 2016 20:04:02 +0000 (16:04 -0400)
* "test_suite.sav/test_case.res" grouped by test-suites
  The current one.
  Useful if there is a lot of test-suites and test-cases in a directory
* "sav/test_case.res" just grouped in a common directory
  Useful if there is a lot of test-suites OR test-cases in a directory
* "test_case.res" raw in the directory.
  Useful is there is a few test-suites and test-cases in a directory.

All 3 are exclusive. If more than one exists, the test-case is failed.

Signed-off-by: Jean Privat <jean@pryen.org>

src/testing/testing_suite.nit

index 0137ef3..c15b1c0 100644 (file)
@@ -279,8 +279,12 @@ class TestCase
                        var mmodule = test_method.mclassdef.mmodule
                        var file = mmodule.filepath
                        if file != null then
-                               var sav = file.dirname / mmodule.name + ".sav" / test_method.name + ".res"
-                               if sav.file_exists then
+                               var tries = [ file.dirname / mmodule.name + ".sav" / test_method.name + ".res",
+                                       file.dirname / "sav" / test_method.name + ".res" ,
+                                       file.dirname / test_method.name + ".res" ]
+                               var savs = [ for t in tries do if t.file_exists then t ]
+                               if savs.length == 1 then
+                                       var sav = savs.first
                                        toolcontext.info("Diff output with {sav}", 1)
                                        res = toolcontext.safe_exec("diff -u --label 'expected:{sav}' --label 'got:{res_name}.out1' '{sav}' '{res_name}.out1' > '{res_name}.diff' 2>&1 </dev/null")
                                        if res != 0 then
@@ -288,8 +292,12 @@ class TestCase
                                                error = "Difference with expected output: diff -u {sav} {res_name}.out1"
                                                toolcontext.modelbuilder.failed_tests += 1
                                        end
+                               else if savs.length > 1 then
+                                       toolcontext.info("Conflicting diffs: {savs.join(", ")}", 1)
+                                       error = "Conflicting expected output: {savs.join(", ", " and ")} all exist"
+                                       toolcontext.modelbuilder.failed_tests += 1
                                else if not raw_output.is_empty then
-                                       toolcontext.info("No diff: {sav} not found", 2)
+                                       toolcontext.info("No diff: {tries.join(", ", " or ")} not found", 1)
                                end
                        end
                end