After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 775444 - Port tests to use an embedded copy of Jasmine
Port tests to use an embedded copy of Jasmine
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: Philip Chimento
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2016-12-01 06:02 UTC by Philip Chimento
Modified: 2016-12-28 01:32 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
coverage test: Fix copypasta errors (1.94 KB, patch)
2016-12-18 07:33 UTC, Philip Chimento
committed Details | Review
coverage test: Fix equality error (2.00 KB, patch)
2016-12-18 07:33 UTC, Philip Chimento
committed Details | Review
test everything: Enable int64 array test (1.25 KB, patch)
2016-12-18 07:33 UTC, Philip Chimento
committed Details | Review
tests: Move logError test to testExceptions.js (6.80 KB, patch)
2016-12-18 07:33 UTC, Philip Chimento
committed Details | Review
tests: Move GVariant overrides test to testGLib.js (4.78 KB, patch)
2016-12-18 07:33 UTC, Philip Chimento
committed Details | Review
tests: Move GType tests to testGTypeClass.js (3.37 KB, patch)
2016-12-18 07:33 UTC, Philip Chimento
committed Details | Review
test marshalling: Disable foreign struct test (1.74 KB, patch)
2016-12-18 07:33 UTC, Philip Chimento
committed Details | Review
test locale: Delete commented-out test (1.31 KB, patch)
2016-12-18 07:33 UTC, Philip Chimento
committed Details | Review
tests: Consolidate importer tests (1.93 KB, patch)
2016-12-18 07:33 UTC, Philip Chimento
committed Details | Review
tests: Delete redundant tests (7.17 KB, patch)
2016-12-18 07:33 UTC, Philip Chimento
committed Details | Review
tests: Use embedded copy of Jasmine to run tests (516.34 KB, patch)
2016-12-18 07:33 UTC, Philip Chimento
committed Details | Review
tests: Run testCommandLine.sh installed (3.14 KB, patch)
2016-12-18 07:34 UTC, Philip Chimento
committed Details | Review

Description Philip Chimento 2016-12-01 06:02:01 UTC
In order to make writing tests less of a pain, I'm working on porting the test suite to use an embedded copy of Jasmine [1].

[1] https://jasmine.github.io/2.5/introduction.html
Comment 1 Philip Chimento 2016-12-18 07:33:15 UTC
Created attachment 342141 [details] [review]
coverage test: Fix copypasta errors

A few coverage tests didn't test what they said the tested. One was
identical to a test a few lines above. The other had a trailing newline
whereas the description said it was testing the case without a trailing
newline.
Comment 2 Philip Chimento 2016-12-18 07:33:19 UTC
Created attachment 342142 [details] [review]
coverage test: Fix equality error

There was an error in the functionDeclarationsEqual() tester which caused
some tests not to fail that should have failed. I believe these are
errors in the expected values in the tests, rather than actual errors in
the code.
Comment 3 Philip Chimento 2016-12-18 07:33:23 UTC
Created attachment 342143 [details] [review]
test everything: Enable int64 array test

I implemented support for this, so the test can be uncommented.
Comment 4 Philip Chimento 2016-12-18 07:33:27 UTC
Created attachment 342144 [details] [review]
tests: Move logError test to testExceptions.js

This didn't really test stuff from the Regress library, so it should be
moved to the testExceptions file. As well, the test never asserted that
the expected messages were logged, so it would not have caught any test
failures.
Comment 5 Philip Chimento 2016-12-18 07:33:31 UTC
Created attachment 342145 [details] [review]
tests: Move GVariant overrides test to testGLib.js

This didn't really belong in testEverythingEncapsulated, which tests
boxed types from the Regress library. Instead we put it in a new file
which will hold any other tests of GLib overrides added in the future.
Comment 6 Philip Chimento 2016-12-18 07:33:35 UTC
Created attachment 342146 [details] [review]
tests: Move GType tests to testGTypeClass.js

These didn't belong in testGIMarshalling, since they are testing the
native GType object and/or the GObject overrides for GType.
Comment 7 Philip Chimento 2016-12-18 07:33:39 UTC
Created attachment 342147 [details] [review]
test marshalling: Disable foreign struct test

This test fails when running as an installed test. It seems that JSUnit
swallows the exception somehow during "make check".
Comment 8 Philip Chimento 2016-12-18 07:33:43 UTC
Created attachment 342148 [details] [review]
test locale: Delete commented-out test

This was supposed to have been commented out temporarily, but I'm not
aware of a way in which to create an invalid JSString that can't be
converted to UTF-8, at least not from Javascript. Probably the '\ud800'
triggered a bug in an earlier version of SpiderMonkey, but I don't think
this test can sensibly pass anymore.
Comment 9 Philip Chimento 2016-12-18 07:33:47 UTC
Created attachment 342149 [details] [review]
tests: Consolidate importer tests

test0020importer.js can be moved into testImporter.js, so that all
importer tests are in the same place.
Comment 10 Philip Chimento 2016-12-18 07:33:51 UTC
Created attachment 342150 [details] [review]
tests: Delete redundant tests

- 0010basic: This only tests 1 + 1 = 2. The internal consistency of the
  test harness is already tested more thoroughly in testself.js.
- 0030basicBoxed: This duplicates functionality which was tested more
  thoroughly in testEverythingEncapsulated.js.
- 0040mainloop: This duplicates functionality which was tested more
  thoroughly in testMainloop.js.
- JS1_8: This tests SpiderMonkey features, and has nothing to do with
  any code in GJS.
- ReflectObject: This also tests SpiderMonkey features.
- Unicode: This tests SpiderMonkey's ability to handle Unicode
  characters, also nothing to do with GJS.
Comment 11 Philip Chimento 2016-12-18 07:33:56 UTC
Created attachment 342151 [details] [review]
tests: Use embedded copy of Jasmine to run tests

This replaces the old JSUnit test harness with an embedded copy of
Jasmine [1], which makes writing tests less of a pain, includes more
handy test facilities, and produces better output.

jasmine.js is a copy of upstream Jasmine 2.5.2. minijasmine.js contains
code for starting up Jasmine, adapting it to the GJS environment, and
producing TAP output. minijasmine.cpp makes an executable which loads the
preceding two files from the unit test GResource.

All the tests in installed-tests/js are converted to use Jasmine's
describe()/it() style. Quite often this allows simplifying them since
Jasmine has features like array and object equality, spies, and clock
ticks.

[1] https://jasmine.github.io/2.5/introduction.html
Comment 12 Philip Chimento 2016-12-18 07:34:01 UTC
Created attachment 342152 [details] [review]
tests: Run testCommandLine.sh installed

This file can be run just as well as an installed test, so we install it
to the correct directory and add a .test file.

The script now checks for GJS_USE_UNINSTALLED_FILES and tests the
uninstalled copy of gjs-console if it is set to 1.
Comment 13 Cosimo Cecchi 2016-12-26 17:31:36 UTC
Review of attachment 342141 [details] [review]:

OK
Comment 14 Cosimo Cecchi 2016-12-26 17:32:40 UTC
Review of attachment 342142 [details] [review]:

OK
Comment 15 Cosimo Cecchi 2016-12-26 17:32:55 UTC
Review of attachment 342143 [details] [review]:

OK
Comment 16 Cosimo Cecchi 2016-12-26 17:33:54 UTC
Review of attachment 342144 [details] [review]:

Good catch
Comment 17 Cosimo Cecchi 2016-12-26 17:34:24 UTC
Review of attachment 342145 [details] [review]:

Sure
Comment 18 Cosimo Cecchi 2016-12-26 17:35:06 UTC
Review of attachment 342146 [details] [review]:

Sure
Comment 19 Cosimo Cecchi 2016-12-26 17:39:01 UTC
Review of attachment 342147 [details] [review]:

Maybe leave a comment? Does this go away when we port to Jasmine?
Comment 20 Cosimo Cecchi 2016-12-26 17:39:31 UTC
Review of attachment 342148 [details] [review]:

OK
Comment 21 Cosimo Cecchi 2016-12-26 17:39:53 UTC
Review of attachment 342149 [details] [review]:

Sure
Comment 22 Cosimo Cecchi 2016-12-26 17:40:52 UTC
Review of attachment 342150 [details] [review]:

OK
Comment 23 Cosimo Cecchi 2016-12-26 18:31:48 UTC
Review of attachment 342151 [details] [review]:

I did not look at all the tests in details, but I trust that they all pass after this :)

::: installed-tests/js/testClass.js
@@ +184,2 @@
+            _construct: function(one, two) {
+                return [one, two];

I did not know this worked!

::: installed-tests/minijasmine.cpp
@@ +60,3 @@
+    setlocale(LC_ALL, "");
+
+    if (g_getenv ("GJS_USE_UNINSTALLED_FILES") != NULL) {

Extra space before paren
Comment 24 Cosimo Cecchi 2016-12-26 18:32:53 UTC
Review of attachment 342152 [details] [review]:

Sure
Comment 25 Philip Chimento 2016-12-28 00:55:47 UTC
(In reply to Cosimo Cecchi from comment #19)
> Review of attachment 342147 [details] [review] [review]:
> 
> Maybe leave a comment? Does this go away when we port to Jasmine?

The test still fails under Jasmine, indicating a bug in GJS. In the Jasmine commit I'm skipping it with xit() and a custom message explaining why, so I don't think it's necessary to add a comment here. This commit was just so that it didn't look like I was taking a passing test and replacing it with a skipped test.

(In reply to Cosimo Cecchi from comment #23)
> Review of attachment 342151 [details] [review] [review]:
> ::: installed-tests/js/testClass.js
> @@ +184,2 @@
> +            _construct: function(one, two) {
> +                return [one, two];
> 
> I did not know this worked!

Do you mean returning a custom object from a constructor? It's one of the bizarre quirks of JS and probably not such a great idea to use since it's pretty obscure.

Here's a stack overflow post explaining it in some more detail:
http://stackoverflow.com/a/3350364/172999

But this is one reason why I like Jasmine: it makes it easier to read casually what is the desired behaviour of your code!

I'll go ahead and push everything with the comments fixed.
Comment 26 Philip Chimento 2016-12-28 01:30:59 UTC
Attachment 342141 [details] pushed as 2dec333 - coverage test: Fix copypasta errors
Attachment 342142 [details] pushed as 18c99a8 - coverage test: Fix equality error
Attachment 342143 [details] pushed as 8eb23fa - test everything: Enable int64 array test
Attachment 342144 [details] pushed as cb45cf3 - tests: Move logError test to testExceptions.js
Attachment 342145 [details] pushed as aa267dc - tests: Move GVariant overrides test to testGLib.js
Attachment 342146 [details] pushed as 4c93f88 - tests: Move GType tests to testGTypeClass.js
Attachment 342147 [details] pushed as 7ae93af - test marshalling: Disable foreign struct test
Attachment 342148 [details] pushed as 8484748 - test locale: Delete commented-out test
Attachment 342149 [details] pushed as 96dfa29 - tests: Consolidate importer tests
Attachment 342150 [details] pushed as bf11496 - tests: Delete redundant tests
Attachment 342151 [details] pushed as 3d6e9fa - tests: Use embedded copy of Jasmine to run tests
Attachment 342152 [details] pushed as 413bd40 - tests: Run testCommandLine.sh installed