From: Jean Privat Date: Fri, 2 Dec 2016 15:13:46 +0000 (-0500) Subject: Merge: mongo: More queries X-Git-Url: http://nitlanguage.org?hp=7ed183fb8c7bb0d245b725ba1fcb9ac9828f3d65 Merge: mongo: More queries * Fix query prefixes * Add Array related queries Pull-Request: #2336 --- diff --git a/lib/core/math.nit b/lib/core/math.nit index c8842fd..a7eefbe 100644 --- a/lib/core/math.nit +++ b/lib/core/math.nit @@ -126,9 +126,9 @@ redef class Int # 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 @@ -252,15 +252,15 @@ redef class Float # 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`. diff --git a/lib/github/api.nit b/lib/github/api.nit index dfa601c..1a9ed1a 100644 --- a/lib/github/api.nit +++ b/lib/github/api.nit @@ -527,6 +527,15 @@ class User # 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. diff --git a/share/man/nitunit.md b/share/man/nitunit.md index 73c5b3e..0ab13a5 100644 --- a/share/man/nitunit.md +++ b/share/man/nitunit.md @@ -274,6 +274,23 @@ fun after_module do 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... @@ -383,6 +400,10 @@ To solve this issue, `NIT_TESTING_ID` is initialized with a distinct integer ide 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 diff --git a/src/model/model_collect.nit b/src/model/model_collect.nit index d4e40f4..bfe5fdf 100644 --- a/src/model/model_collect.nit +++ b/src/model/model_collect.nit @@ -154,6 +154,18 @@ redef class MPackage 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 diff --git a/src/testing/testing_base.nit b/src/testing/testing_base.nit index 6281977..e035c9e 100644 --- a/src/testing/testing_base.nit +++ b/src/testing/testing_base.nit @@ -64,8 +64,8 @@ redef class ToolContext 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 @@ -108,7 +108,6 @@ ulimit -t {{{ulimit_usertime}}} 2> /dev/null # 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 @@ -167,6 +166,13 @@ ulimit -t {{{ulimit_usertime}}} 2> /dev/null 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. diff --git a/src/testing/testing_suite.nit b/src/testing/testing_suite.nit index 60265ab..e788067 100644 --- a/src/testing/testing_suite.nit +++ b/src/testing/testing_suite.nit @@ -122,13 +122,14 @@ class TestSuite # 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 @@ -214,6 +215,13 @@ class TestSuite 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 diff --git a/src/web/api_model.nit b/src/web/api_model.nit index 4f85161..7d3ea69 100644 --- a/src/web/api_model.nit +++ b/src/web/api_model.nit @@ -117,8 +117,8 @@ class APIRandom 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 diff --git a/tests/nitunit.args b/tests/nitunit.args index f0bc3ee..6474d63 100644 --- a/tests/nitunit.args +++ b/tests/nitunit.args @@ -7,3 +7,4 @@ test_nitunit3 --no-color -o $WRITE 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 diff --git a/tests/sav/nitunit_args10.res b/tests/sav/nitunit_args10.res new file mode 100644 index 0000000..5fdb314 --- /dev/null +++ b/tests/sav/nitunit_args10.res @@ -0,0 +1,8 @@ +==== 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. + \ No newline at end of file diff --git a/tests/test_nitunit5.nit b/tests/test_nitunit5.nit new file mode 100644 index 0000000..602648b --- /dev/null +++ b/tests/test_nitunit5.nit @@ -0,0 +1,29 @@ +# 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