nitunit: add options to search the compiler
authorJean Privat <jean@pryen.org>
Thu, 19 May 2016 02:36:33 +0000 (22:36 -0400)
committerJean Privat <jean@pryen.org>
Thu, 19 May 2016 02:36:33 +0000 (22:36 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/nitunit.nit
src/testing/testing_base.nit

index 1cffdf5..0d89dc6 100644 (file)
@@ -20,7 +20,7 @@ import testing
 
 var toolcontext = new ToolContext
 
-toolcontext.option_context.add_option(toolcontext.opt_full, toolcontext.opt_output, toolcontext.opt_dir, toolcontext.opt_noact, toolcontext.opt_pattern, toolcontext.opt_file, toolcontext.opt_gen_unit, toolcontext.opt_gen_force, toolcontext.opt_gen_private, toolcontext.opt_gen_show)
+toolcontext.option_context.add_option(toolcontext.opt_full, toolcontext.opt_output, toolcontext.opt_dir, toolcontext.opt_noact, toolcontext.opt_pattern, toolcontext.opt_file, toolcontext.opt_gen_unit, toolcontext.opt_gen_force, toolcontext.opt_gen_private, toolcontext.opt_gen_show, toolcontext.opt_nitc)
 toolcontext.tooldescription = "Usage: nitunit [OPTION]... <file.nit>...\nExecutes the unit tests from Nit source files."
 
 toolcontext.process_options(args)
index 7528887..7ca4c77 100644 (file)
@@ -27,6 +27,8 @@ redef class ToolContext
        var opt_dir = new OptionString("Working directory (default is '.nitunit')", "--dir")
        # opt --no-act
        var opt_noact = new OptionBool("Does not compile and run tests", "--no-act")
+       # opt --nitc
+       var opt_nitc = new OptionString("nitc compiler to use", "--nitc")
 
        # Working directory for testing.
        fun test_dir: String do
@@ -40,10 +42,28 @@ redef class ToolContext
        # If not `nitc` is suitable, then prints an error and quit.
        fun find_nitc: String
        do
+               var nitc = opt_nitc.value
+               if nitc != null then
+                       if not nitc.file_exists then
+                               fatal_error(null, "error: cannot find `{nitc}` given by --nitc.")
+                               abort
+                       end
+                       return nitc
+               end
+
+               nitc = "NITC".environ
+               if nitc != "" then
+                       if not nitc.file_exists then
+                               fatal_error(null, "error: cannot find `{nitc}` given by NITC.")
+                               abort
+                       end
+                       return nitc
+               end
+
                var nit_dir = nit_dir
-               var nitc = nit_dir/"bin/nitc"
+               nitc = nit_dir/"bin/nitc"
                if not nitc.file_exists then
-                       fatal_error(null, "Error: cannot find nitc. Set envvar NIT_DIR.")
+                       fatal_error(null, "Error: cannot find nitc. Set envvar NIT_DIR or NITC or use the --nitc option.")
                        abort
                end
                return nitc