nitunit: set the envvar NIT_TESTING
authorJean Privat <jean@pryen.org>
Tue, 17 May 2016 11:19:49 +0000 (07:19 -0400)
committerJean Privat <jean@pryen.org>
Tue, 17 May 2016 11:19:49 +0000 (07:19 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

share/man/nitunit.md
src/nitunit.nit

index e01dbd2..4f9ad61 100644 (file)
@@ -118,6 +118,15 @@ Finally, standard markdown documents can be checked with:
 
     $ nitunit foo.md
 
+When testing, the environment variable `NIT_TESTING` is set to `true`.
+This flag can be used by libraries and program to prevent (or limit) the execution of dangerous pieces of code.
+
+~~~~~
+# NIT_TESTING is automatically set.
+#
+#     assert "NIT_TESTING".environ == "true"
+~~~~
+
 ## Working with `TestSuites`
 
 TestSuites are Nit files that define a set of TestCases for a particular module.
index 522591d..cc9ea85 100644 (file)
@@ -63,6 +63,8 @@ if toolcontext.opt_gen_unit.value then
        exit(0)
 end
 
+"NIT_TESTING".setenv("true")
+
 var page = new HTMLTag("testsuites")
 
 if toolcontext.opt_full.value then mmodules = model.mmodules