From fa1c4ab4a3c01671e4c8ec9976a187bba4e6e2a1 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 18 May 2016 22:31:29 -0400 Subject: [PATCH] nitunit: factorize the search of a compiler Signed-off-by: Jean Privat --- src/testing/testing_base.nit | 14 ++++++++++++++ src/testing/testing_doc.nit | 7 +------ src/testing/testing_suite.nit | 7 +------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/testing/testing_base.nit b/src/testing/testing_base.nit index 62cfb08..7528887 100644 --- a/src/testing/testing_base.nit +++ b/src/testing/testing_base.nit @@ -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 diff --git a/src/testing/testing_doc.nit b/src/testing/testing_doc.nit index 2514454..4c5883b 100644 --- a/src/testing/testing_doc.nit +++ b/src/testing/testing_doc.nit @@ -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}" diff --git a/src/testing/testing_suite.nit b/src/testing/testing_suite.nit index 0de6e0a..f79b03b 100644 --- a/src/testing/testing_suite.nit +++ b/src/testing/testing_suite.nit @@ -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 -- 1.7.9.5