I've got a weird problem with the unit tests when I run them on my computer, which don't happen when I run them elsewhere (e.g. Github Actions)
This is using Moodle 3.11 (or 3.10), PHP 7.4 and CodeRunner 4.1.0+ (or 4.0.1).
The failures I get are all like:
$ vendor/bin/phpunit --testsuite qtype_coderunner_testsuite --filter qtype_coderunner_cpp_questions_test::test_good_sqr_function Moodle 3.10.4 (Build: 20210510), e7514424c252a524f29f7e6e8e5f8c887d7cd17f Php: 7.4.23, ou_pgsql: 11.4, OS: Windows NT 10.0 AMD64 PHPUnit 8.5.14 by Sebastian Bergmann and contributors. E 1 / 1 (100%) Time: 12.17 seconds, Memory: 130.00 MB There was 1 error: 1) qtype_coderunner_cpp_questions_test::test_good_sqr_function assert(): assert(!isset($this->prototype)) failed C:\Users\tjh238\workspace\moodle_ou_live\question\type\coderunner\question.php:876 C:\Users\tjh238\workspace\moodle_ou_live\question\type\coderunner\question.php:846 C:\Users\tjh238\workspace\moodle_ou_live\question\type\coderunner\classes\jobrunner.php:64 C:\Users\tjh238\workspace\moodle_ou_live\question\type\coderunner\question.php:547 C:\Users\tjh238\workspace\moodle_ou_live\question\type\coderunner\tests\cppquestions_test.php:43 C:\Users\tjh238\workspace\moodle_ou_live\lib\phpunit\classes\advanced_testcase.php:80 ERRORS! Tests: 1, Assertions: 0, Errors: 1.
The assert is in get_prototype on the question class. The problem is that not only is this bing called withing the question (via jobrunner and -> get files), but it is also called when the question is initialised by tests/helper.php.
Aha! found it. Please could you, where you run the unit tests yourself, check the output of:
If I turn off assertions, then the tests pass for me locally.
So, I think
- This assertion is currently having no effect for almost all CodeRunner developers because they have assertions disabled.
- Currently, either the assertion is wrong, or the code is wrong. (If it was me, would change the code to remove the assertion, and instead make get_prototype do nothing the second and subsequent time it is called on a particular question.