nitunit: factorize the search of a compiler
authorJean Privat <jean@pryen.org>
Thu, 19 May 2016 02:31:29 +0000 (22:31 -0400)
committerJean Privat <jean@pryen.org>
Thu, 19 May 2016 02:31:29 +0000 (22:31 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/testing/testing_base.nit
src/testing/testing_doc.nit
src/testing/testing_suite.nit

index 62cfb08..7528887 100644 (file)
@@ -34,4 +34,18 @@ redef class ToolContext
                if dir == null then return ".nitunit"
                return dir
        end
+
+       # Search the `nitc` compiler to use
+       #
+       # If not `nitc` is suitable, then prints an error and quit.
+       fun find_nitc: String
+       do
+               var nit_dir = nit_dir
+               var nitc = nit_dir/"bin/nitc"
+               if not nitc.file_exists then
+                       fatal_error(null, "Error: cannot find nitc. Set envvar NIT_DIR.")
+                       abort
+               end
+               return nitc
+       end
 end
index 2514454..4c5883b 100644 (file)
@@ -268,12 +268,7 @@ class NitUnitExecutor
        # Can terminate the program if the compiler is not found
        private fun compile_unitfile(file: String): Int
        do
-               var nit_dir = toolcontext.nit_dir
-               var nitc = nit_dir/"bin/nitc"
-               if not nitc.file_exists then
-                       toolcontext.error(null, "Error: cannot find nitc. Set envvar NIT_DIR.")
-                       toolcontext.check_errors
-               end
+               var nitc = toolcontext.find_nitc
                var opts = new Array[String]
                if mmodule != null then
                        opts.add "-I {mmodule.filepath.dirname}"
index 0de6e0a..f79b03b 100644 (file)
@@ -183,12 +183,7 @@ class TestSuite
        # Compile all `test_cases` cases in one file.
        fun compile do
                # find nitc
-               var nit_dir = toolcontext.nit_dir
-               var nitc = nit_dir/"bin/nitc"
-               if not nitc.file_exists then
-                       toolcontext.error(null, "Error: cannot find nitc. Set envvar NIT_DIR.")
-                       toolcontext.check_errors
-               end
+               var nitc = toolcontext.find_nitc
                # compile test suite
                var file = test_file
                var module_file = mmodule.location.file