# Is self a prime number ?
#
- # assert 3.is_prime
- # assert not 1.is_prime
- # assert not 15.is_prime
+ # assert 3.is_prime
+ # assert not 1.is_prime
+ # assert not 15.is_prime
fun is_prime: Bool
do
if self == 2 then
# Returns `self` raised at `e` power.
#
- # #assert 2.0.pow(0.0) == 1.0
- # #assert 2.0.pow(3.0) == 8.0
- # #assert 0.0.pow(9.0) == 0.0
+ # assert 2.0.pow(0.0) == 1.0
+ # assert 2.0.pow(3.0) == 8.0
+ # assert 0.0.pow(9.0) == 0.0
fun pow(e: Float): Float `{ return pow(self, e); `}
# Natural logarithm of `self`.
#
# assert 0.0.log.is_inf == -1
- # #assert 1.0.log == 0.0
+ # assert 1.0.log == 0.0
fun log: Float `{ return log(self); `}
# Logarithm of `self` to base `base`.
# Avatar image url for this user.
var avatar_url: nullable String is writable
+
+ # User public name if any.
+ var name: nullable String is writable
+
+ # User public email if any.
+ var email: nullable String is writable
+
+ # User public blog if any.
+ var blog: nullable String is writable
end
# A Github repository.
end
~~~~
+## Accessing the test suite environment
+
+The `NIT_TESTING_PATH` environment variable contains the current test suite
+file path.
+Nitunit define this variable before the execution of each test suite.
+It can be used to access files based on the current test_suite location:
+
+~~~
+class TestWithPath
+ super TestSuite
+
+ fun test_suite_path do
+ assert "NIT_TESTING_PATH".environ != ""
+ end
+end
+~~~
+
## Generating test suites
Write test suites for big modules can be a repetitive and boring task...
Note: `rand` is not a recommended way to get a distinct identifier because its randomness is disabled by default. See `SRAND`.
+### `NIT_TESTING_PATH`
+
+Only available for test suites.
+Contains the module test suite path.
# SEE ALSO
end
return res
end
+
+ # `MModules` contained in `self`.
+ fun collect_mmodules(view: ModelView): HashSet[MModule] do
+ var res = new HashSet[MModule]
+ for mgroup in mgroups do
+ for mmodule in mgroup.mmodules do
+ if not view.accept_mentity(mmodule) then continue
+ res.add(mmodule)
+ end
+ end
+ return res
+ end
end
redef class MGroup
return nitc
end
- var nit_dir = nit_dir
- nitc = nit_dir/"bin/nitc"
+ var nit_dir = nit_dir or else "."
+ nitc = nit_dir / "bin/nitc"
if not nitc.file_exists then
fatal_error(null, "Error: cannot find nitc. Set envvar NIT_DIR or NITC or use the --nitc option.")
abort
# If `has_progress_bar` is false, then only the first and last state is shown
fun show_unit_status(name: String, tests: SequenceRead[UnitTest])
do
- var esc = 27.code_point.to_s
var line = "\r\x1B[K==== {name} ["
var done = tests.length
var fails = 0
fun show_unit(test: UnitTest, more_message: nullable String) do
print test.to_screen(more_message, not opt_no_color.value)
end
+
+ # Set the `NIT_TESTING_PATH` environment variable with `path`.
+ #
+ # If `path == null` then `NIT_TESTING_PATH` is set with the empty string.
+ fun set_testing_path(path: nullable String) do
+ "NIT_TESTING_PATH".setenv(path or else "")
+ end
end
# A unit test is an elementary test discovered, run and reported by nitunit.
# Test to be executed after the whole test suite.
var after_module: nullable TestCase = null
- fun show_status
- do
+ # Display test suite status in std-out.
+ fun show_status do
toolcontext.show_unit_status("Test-suite of module " + mmodule.full_name, test_cases)
end
# Execute the test suite
fun run do
+ set_env
show_status
if not toolcontext.test_dir.file_exists then
toolcontext.test_dir.mkdir
end
end
+ # Set environment variables for test suite execution
+ fun set_env do
+ var loc = mmodule.location.file
+ if loc == null then return
+ toolcontext.set_testing_path(loc.filename)
+ end
+
# Error occured during test-suite compilation.
var failure: nullable String = null
end
redef fun get(req, res) do
var mentities = list_mentities(req)
- mentities = limit_mentities(req, mentities)
mentities = randomize_mentities(req, mentities)
+ mentities = limit_mentities(req, mentities)
res.json new JsonArray.from(mentities)
end
end
test_nitunit_md.md --no-color -o $WRITE
test_doc3.nit --no-color -o $WRITE
test_nitunit4 --no-color -o $WRITE
+test_nitunit5.nit --no-color -o $WRITE
--- /dev/null
+==== Test-suite of module test_nitunit5::test_nitunit5 | tests: 2
+[OK] test_nitunit5$TestNitunit5$test_path_is_set
+[OK] test_nitunit5$TestNitunit5$test_path_is_suite_path
+
+Docunits: Entities: 4; Documented ones: 0; With nitunits: 0
+Test suites: Classes: 1; Test Cases: 2; Failures: 0
+[SUCCESS] All 2 tests passed.
+<testsuites><testsuite package="test_nitunit5::test_nitunit5"></testsuite><testsuite package="test_nitunit5"><testcase classname="nitunit.test_nitunit5.TestNitunit5" name="test_path_is_set" time="0.0"><system-err></system-err></testcase><testcase classname="nitunit.test_nitunit5.TestNitunit5" name="test_path_is_suite_path" time="0.0"><system-err></system-err></testcase></testsuite></testsuites>
\ No newline at end of file
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+module test_nitunit5 is test_suite
+
+import test_suite
+
+class TestNitunit5
+ super TestSuite
+
+ fun test_path_is_set do
+ assert "NIT_TESTING_PATH".environ != ""
+ end
+
+ fun test_path_is_suite_path do
+ assert "NIT_TESTING_PATH".environ.basename == "test_nitunit5.nit"
+ end
+end