nitunit: accept an absolute path for `--dir`.
authorJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Mon, 6 Oct 2014 16:22:28 +0000 (12:22 -0400)
committerJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Mon, 6 Oct 2014 21:17:42 +0000 (17:17 -0400)
Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

lib/standard/file.nit
src/testing/testing_doc.nit
src/testing/testing_suite.nit

index 36878e5..58fb382 100644 (file)
@@ -348,6 +348,22 @@ redef class String
                return "{self}/{path}"
        end
 
+       # Convert the path (`self`) to a program name.
+       #
+       # Ensure the path (`self`) will be treated as-is by POSIX shells when it is
+       # used as a program name. In order to do that, prepend `./` if needed.
+       #
+       #     assert "foo".to_program_name == "./foo"
+       #     assert "/foo".to_program_name == "/foo"
+       #     assert "".to_program_name == "./" # At least, your shell will detect the error.
+       fun to_program_name: String do
+               if self.has_prefix("/") then
+                       return self
+               else
+                       return "./{self}"
+               end
+       end
+
        # Alias for `join_path`
        #
        #     assert "hello" / "world"      ==  "hello/world"
index 9f31805..f543a2b 100644 (file)
@@ -136,7 +136,7 @@ class NitUnitExecutor
                var res = sys.system(cmd)
                var res2 = 0
                if res == 0 then
-                       res2 = sys.system("./{file}.bin >>'{file}.out1' 2>&1 </dev/null")
+                       res2 = sys.system("{file.to_program_name}.bin >>'{file}.out1' 2>&1 </dev/null")
                end
 
                var msg
index 25b1fc8..5936038 100644 (file)
@@ -244,7 +244,7 @@ class TestCase
                if toolcontext.opt_noact.value then return
                # execute
                var file = test_file
-               var res = sys.system("./{file}.bin > '{file}.out1' 2>&1 </dev/null")
+               var res = sys.system("{file.to_program_name}.bin > '{file}.out1' 2>&1 </dev/null")
                var f = new IFStream.open("{file}.out1")
                var msg = f.read_all
                f.close