Closed Bug 602422 Opened 16 years ago Closed 3 years ago

Replace mochitest checks of the form ok(foo == bar, "description") with is(foo, bar, "description")

Categories

(Core :: General, defect)

defect

Tracking

()

RESOLVED WONTFIX

People

(Reporter: dholbert, Unassigned)

Details

(Keywords: good-first-bug, Whiteboard: [file blocking bugs])

Attachments

(8 files, 4 obsolete files)

70.40 KB, patch
Details | Diff | Splinter Review
2.44 KB, patch
ehsan.akhgari
: review+
Details | Diff | Splinter Review
76.28 KB, patch
Details | Diff | Splinter Review
4.98 KB, patch
Margaret
: review+
Details | Diff | Splinter Review
1.52 KB, patch
jgriffin
: review+
Details | Diff | Splinter Review
11.16 KB, patch
ehsan.akhgari
: review+
Details | Diff | Splinter Review
46.80 KB, patch
tranj23
: review+
Details | Diff | Splinter Review
19.93 KB, patch
tranj23
: review+
Details | Diff | Splinter Review
Filing this bug on replacing checks of the form: ok(foo == bar, "foo should equal bar"); with is(foo, bar, "foo should equal bar"); in our mochitests. This makes mochitest failures way easier to debug, because when the check fails, the harness will display the values of both |foo| and |bar|, instead of just displaying that foo==bar failed. Here's a regular-expression MXR search for these that I just hacked up to find candidates for this: http://mxr.mozilla.org/mozilla-central/search?string=ok\%28[^%26]*[^%3D]%3D%3D[^%3D][^%26]*%2C&regexp=1&find=.html%24&findi=&filter=^[^\0]*%24&hitlimit=&tree=mozilla-central (I've set the regexp to filter out "===" checks, since IIUC that's a stronger test than what "is()" would do. I've also filtered out checks such as "ok(foo == bar && someOthercondition", since those aren't directly translatable into "is()" checks. I tried to filter out "ok(foo == bar || someOtherCondition", too, but I couldn't get that to work in the regexp, so (unless someone else posts a better link), those can just be skipped over by hand.
This should be pretty easy to fix -- or at least, to fix a subset of, since there are a lot of places that need fixing. :) [adding "good first bug" whiteboard status]
Whiteboard: [good first bug]
Whiteboard: [good first bug] → [good first bug][file blocking bugs]
Good places to start would be these two files: http://mxr.mozilla.org/mozilla-central/source/content/canvas/test/test_canvas.html http://mxr.mozilla.org/mozilla-central/source/content/base/test/test_bug415860.html Together, those contain about 2/5 the lines that my MXR search catches. :)
(In reply to comment #0) > (I've set the regexp to filter out "===" checks, since IIUC that's a stronger > test than what "is()" would do. Need to filter out !== checks too. > I've also filtered out checks such as "ok(foo == bar && someOthercondition", > since those aren't directly translatable into "is()" checks. In theory these can be replaced as follows: is(foo, bar, ...); ok(someOtherCondition, ...); And todo(foo == bar || someOtherCondition, ...); would become todo_is(foo, bar, ...); todo(someOtherCondition, ...); although only six tests used the first pattern and none used the second. > I tried to filter out "ok(foo == bar || someOtherCondition," too, > but I couldn't get that to work in the regexp, so (unless someone > else posts a better link), those can just be skipped over by hand. This is what I came up with; it does todo as well as ok, and all types of test: http://mxr.mozilla.org/mozilla-central/search?string=%28ok%7Ctodo%29%5C%28%5B%5E%26%7C%5D*%5B%5E%21%3D%5D%3D%3D%5B%5E%3D%5D%5B%5E%26%7C%5D*%2C&regexp=1&find=test&findi=&filter=%5E%5B%5E%5C0%5D*%24&hitlimit=&tree=mozilla-central
Oof, mammoth patch. I'm not sure of the best way to get the correct people to sign off on this.
Attachment #582564 - Attachment is obsolete: true
Hello all! I'd like to work on this bug. Can I be assigned to it?
Hi Raneer! You probably want to start on a different bug -- it looks like Thomas (:prip) already worked on this & posted a patch, but then nothing happened after that. (Some of the patch doesn't apply anymore, since so much time has passed, but the majority of it still does.) Thomas, did you mean to ask for review on your patch? (Someone probably should have suggested that; sorry that that didn't happen!) If you're still around, it'd be great if you could: (a) update your patch to make it apply on current mozilla-central (b) split it into sub-patches based on top-level directory (one /content/ patch, one /dom/ patch, one /toolkit/ patch, etc.) (c) Request review from folks, based on what "hg log [filename]" tells you about who's most recently reviewed (or perhaps wrote) one of the tests in each sub-patch.
Flags: needinfo?(thomas)
Hi Daniel! I stumbled upon this bug in my search for a good first bug and didn't realize it was that old. Could you suggest me similar ones to get started?
Bug 977396 shouldn't be too hard and is pretty similar to this bug. Or if that's not a good fit, http://www.joshmatthews.net/bugsahoy/ should be able to help you out. I'll CC you on bug 977396 with a bit more info.
Flags: needinfo?(thomas)
[Thomas, I'm interpreting your needinfo-canceling (after comment 11) to mean "no longer interested in working on this bug". That's totally fine if that's the case, but if I'm misinterpreting, please correct me.]
I think have a good enough grasp on C++ to help out on this bug. I have only worked on 1 bug that was pushed to the central source, and that was just editing a function's parameters in Javascript. How would I go about fixing this one?
Note, no C++ is required, only JavaScript. However, it looks like most of the work remaining here is updating the patch that Thomas wrote to apply on a more recent version of mozilla-central and then getting it reviewed.
Hi, I would like to work on this bug. I have set up my firefox build env and have seen the previous patches.Should I apply those patches to a newer version and submit a new patch ?
That would be great, Yash!
(In reply to Josh Matthews [:jdm] from comment #16) > That would be great, Yash! I have a small doubt, should I change ok(f==b) to is(f,b) everywhere ? If no, which all files need to be changed ? About half of the files submitted in the last patch do not exist anymore. Thanks.
(In reply to Yash Mehrotra from comment #17) > I have a small doubt, should I change ok(f==b) to is(f,b) everywhere ? I can't think of any reason why we'd want to leave any "ok(f==b)" checks; seems like "is(f, b)" is strictly better, for the reason described in comment 0 -- when there's a test-failure, the harness will tell us what each of the not-equal values are.) Though: we don't necessarily have to fix *every instance* at once. Fixing some is better than fixing none at all. :) And as noted in comment 9, different areas of the code have different ownership, so splitting things up into a different patch per top-level-directory would be helpful. > About half of the files submitted > in the last patch do not exist anymore. I think the files just moved, actually -- it's pretty rare that we actually *delete* a test. Given a test filename, http://mxr.mozilla.org/mozilla-central/find can help you figure out where that file lives in our current source tree. e.g. from a quick skim, it looks like some (all?) of the tests in this patch that lived in /content/ have now mostly moved into the same path within /dom/. To fix this, you may want to hand-edit the existing patch file (with search-and-replace in a text editor, perhaps) to adjust those file-paths manually, at least for the files that have moved.
(In reply to Daniel Holbert [:dholbert] from comment #18) Ok, Thanks Daniel. I will begin working on it and submit a patch in 3-4 days.
Ok I submitted patches corresponding to changes made in different top-level directories (e.g. toolkit, mobile, etc). I requested reviews from people that recently made changes to the files that I changed in each directory. I limited my changes to only .js files since the number of changes was getting really massive. But I could also make changes to .html files if requested.
Comment on attachment 8709495 [details] [diff] [review] rev1 - Changes made to .js files in toolkit directory Review of attachment 8709495 [details] [diff] [review]: ----------------------------------------------------------------- Thanks!
Attachment #8709495 - Flags: review?(ehsan) → review+
Comment on attachment 8709481 [details] [diff] [review] rev1 - Changes made to .js files in devtools directory Review of attachment 8709481 [details] [diff] [review]: ----------------------------------------------------------------- ::: devtools/client/netmonitor/test/browser_net_raw_headers.js @@ +60,5 @@ > let requestTextarea = document.getElementById("raw-request-headers-textarea"); > let responseTextare = document.getElementById("raw-response-headers-textarea"); > ok(rawHeadersHidden, "raw headers textareas are hidden"); > + is(requestTextarea.value, '', "raw request headers textarea is empty"); > + is(responseTextare.value, '', "raw response headers textarea is empty"); Please change these to double quotes while you're here.
Attachment #8709481 - Flags: review?(jaws) → review+
Comment on attachment 8709479 [details] [diff] [review] rev1 - Changes made to .js files in browser directory Review of attachment 8709479 [details] [diff] [review]: ----------------------------------------------------------------- Did you push these patches to tryserver? browser_blocklist.js will fail currently since `ok` was changed to `is` but the arguments weren't adjusted. r+ with the issues below addressed. ::: browser/base/content/test/general/browser_bug822367.js @@ +54,5 @@ > function MixedTest1B() { > waitForCondition(() => content.document.getElementById('p1').innerHTML == "hello", MixedTest1C, "Waited too long for mixed script to run in Test 1"); > } > function MixedTest1C() { > + is(content.document.getElementById('p1').innerHTML, "hello","Mixed script didn't load in Test 1"); Please insert a space after `"hello",` while you're here. @@ +95,5 @@ > waitForCondition(() => content.document.getElementById('p2').innerHTML == "bye", MixedTest3D, "Waited too long for mixed image to load in Test 3"); > } > function MixedTest3D() { > + is(content.document.getElementById('p1').innerHTML, "hello","Mixed script didn't load in Test 3"); > + is(content.document.getElementById('p2').innerHTML, "bye","Mixed image didn't load in Test 3"); Ditto for both of these lines. @@ +128,5 @@ > let {gIdentityHandler} = gTestBrowser.ownerGlobal; > waitForCondition(() => content.document.getElementById('p1').innerHTML == "", MixedTest4D, "Mixed script loaded in test 4 after location change!"); > } > function MixedTest4D() { > + is(content.document.getElementById('p1').innerHTML, "","p1.innerHTML changed; mixed script loaded after location change in Test 4"); Ditto. @@ +152,5 @@ > function MixedTest5B() { > waitForCondition(() => content.document.getElementById('p1').innerHTML == "hello", MixedTest5C, "Waited too long for mixed script to run in Test 5"); > } > function MixedTest5C() { > + is(content.document.getElementById('p1').innerHTML, "hello","Mixed script didn't load in Test 5"); Ditto. @@ +189,5 @@ > } > }, MixedTest6D, "Waited too long for mixed script to run in Test 6"); > } > function MixedTest6D() { > + is(content.document.getElementById('f1').contentDocument.getElementById('p1').innerHTML, "hello","Mixed script didn't load in Test 6"); Ditto. ::: browser/base/content/test/general/browser_gestureSupport.js @@ +509,5 @@ > test_utils.sendSimpleGestureEvent("MozSwipeGesture", 0, 0, combos[i], 0, 0); > + is(cmdUp.callCount, 0, "Step 5-"+i+": Up command was triggered"); > + is(cmdDown.callCount, 0, "Step 5-"+i+": Down command was triggered"); > + is(cmdLeft.callCount, 0, "Step 5-"+i+": Left command was triggered"); > + is(cmdRight.callCount, 0, "Step 5-"+i+": Right command was triggered"); Please put spaces around binary-plus while you're here. ::: browser/base/content/test/social/browser_blocklist.js @@ +175,5 @@ > return; > SocialService.unregisterProviderListener(providerListener); > is(origin, provider.origin, "provider disabled"); > SocialService.getProvider(provider.origin, function(p) { > + is(p == null, "blocklisted provider disabled"); This is wrong. is(p, null, "blocklisted provider disabled"); ::: browser/base/content/test/social/browser_social_errorPage.js @@ +61,5 @@ > var tests = { > testSidebar: function(next) { > let sbrowser = document.getElementById("social-sidebar-browser"); > onSidebarLoad(function() { > + is(sbrowser.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly"),0, "sidebar is on social error page"); Please insert a space after commas while you're here. @@ +66,5 @@ > gc(); > // Add a new load listener, then find and click the "try again" button. > onSidebarLoad(function() { > // should still be on the error page. > + is(sbrowser.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly"),0, "sidebar is still on social error page"); Ditto. @@ +97,5 @@ > }, > function() { // the "load" callback. > todo_is(panelCallbackCount, 0, "Bug 833207 - should be no callback when error page loads."); > let href = panel.firstChild.contentDocument.documentURI; > + is(href.indexOf("about:socialerror?mode=compactInfo"),0, "flyout is on social error page"); Ditto. @@ +109,5 @@ > }, > function() { // the "load" callback. > todo_is(panelCallbackCount, 0, "Bug 833207 - should be no callback when error page loads."); > let href = panel.firstChild.contentDocument.documentURI; > + is(href.indexOf("about:socialerror?mode=compactInfo"),0, "flyout is on social error page"); Ditto. ::: browser/base/content/test/social/browser_social_workercrash.js @@ +62,5 @@ > info("Saw the process crash.") > Services.obs.removeObserver(observer, 'ipc:content-shutdown'); > // Add another sidebar load listener - it should be the error page. > onSidebarLoad(function() { > + is(sbrowser.contentDocument.location.href.indexOf("about:socialerror?mode=workerFailure"),0, "is on social error page"); Please insert a space after commas while you're here.
Attachment #8709479 - Flags: review?(jaws) → review+
Attachment #8709494 - Flags: review?(jgriffin) → review+
Comment on attachment 8709492 [details] [diff] [review] rev1 - Changes made to .js files in mobile directory Review of attachment 8709492 [details] [diff] [review]: ----------------------------------------------------------------- Hi Jeffrey, not sure why i got this since i'm not really a developer. So canceling this review request here
Attachment #8709492 - Flags: review?(cbook)
Attachment #8709484 - Flags: review?(cbook)
Comment on attachment 8709492 [details] [diff] [review] rev1 - Changes made to .js files in mobile directory Review of attachment 8709492 [details] [diff] [review]: ----------------------------------------------------------------- Let's try Margaret!
Attachment #8709492 - Flags: review?(margaret.leibovic)
Comment on attachment 8709484 [details] [diff] [review] rev1 - Changes made to .js files in docshell directory Review of attachment 8709484 [details] [diff] [review]: ----------------------------------------------------------------- r=me
Attachment #8709484 - Flags: review+
Comment on attachment 8709492 [details] [diff] [review] rev1 - Changes made to .js files in mobile directory Review of attachment 8709492 [details] [diff] [review]: ----------------------------------------------------------------- Thanks for fixing our tests!
Attachment #8709492 - Flags: review?(margaret.leibovic) → review+
Comment on attachment 8709489 [details] [diff] [review] rev1 - Changes made to .js files in dom directory Review of attachment 8709489 [details] [diff] [review]: ----------------------------------------------------------------- This seems like a nice change. Has this patch been run through try? The only test I actually know here is coiws_child.js, and I think the changes are incorrect there. That file doesn't have SimpleTest.js in scope, so is() isn't defined there. I actually haven't tried running it though. Maybe we're somehow getting is() from somewhere else? I'm also a little worried because is() uses Object.is, which is not the same as ==. Mostly I expect they'll be the same, but there may be cases where we're relying on coercions.
This new patch makes changes to rev1 based on review feedback.
Attachment #8709479 - Attachment is obsolete: true
Attachment #8710065 - Flags: review+
This patch makes changes to rev1 patch based on review feedback.
Attachment #8709481 - Attachment is obsolete: true
Attachment #8710067 - Flags: review+
(In reply to Bill McCloskey (:billm) from comment #35) > Comment on attachment 8709489 [details] [diff] [review] > rev1 - Changes made to .js files in dom directory > > Review of attachment 8709489 [details] [diff] [review]: > ----------------------------------------------------------------- > > This seems like a nice change. Has this patch been run through try? The only > test I actually know here is coiws_child.js, and I think the changes are > incorrect there. That file doesn't have SimpleTest.js in scope, so is() > isn't defined there. I actually haven't tried running it though. Maybe we're > somehow getting is() from somewhere else? > > I'm also a little worried because is() uses Object.is, which is not the same > as ==. Mostly I expect they'll be the same, but there may be cases where > we're relying on coercions. None of the patches have been run through try because I don't have commit access. Can you push them all to try for me?
Please apply for try access by following the steps at https://www.mozilla.org/en-US/about/governance/policies/commit/ . I'll vouch for you.
(In reply to Josh Matthews [:jdm] from comment #39) > Please apply for try access by following the steps at > https://www.mozilla.org/en-US/about/governance/policies/commit/ . I'll vouch > for you. Thanks Josh. Here's my request: https://bugzilla.mozilla.org/show_bug.cgi?id=1241482
Can you please push this to try?
Assignee: nobody → tranj23
(In reply to Bill McCloskey (:billm) from comment #41) > Can you please push this to try? Sorry for the delay, I pushed the patch to try but I'm not sure how to interpret the results.
Comment on attachment 8709489 [details] [diff] [review] rev1 - Changes made to .js files in dom directory Hi Jeff, It looks like there are a good number of places where "is" is not defined. The try push should give you some pointers in figuring out where these are. I would suggest switching these tests back to "ok" for now. We can address them in a separate bug. Also, please let me know if you need help interpreting the try results or in running the tests on your own. There are general instructions here: https://developer.mozilla.org/en-US/docs/Mochitest
Attachment #8709489 - Flags: review?(wmccloskey)
Keywords: good-first-bug
Whiteboard: [good first bug][file blocking bugs] → [file blocking bugs]

This good-first-bug hasn't had any activity for 6 months, it is automatically unassigned.
For more information, please visit auto_nag documentation.

Assignee: tranj23 → nobody

Hi, I'm interested in helping out with this bug. This is my first time contributing to a programming project so any tips are greatly appreciated.
Thanks!

Severity: normal → S3

Is this still an active issue - I would be interested in patching it

Thanks for asking. I originally filed this bug (12 years ago) on a category of minor-test-improvement which might theoretically make failures a bit easier to reason about, when the tests in question fail. But I don't think it's worth bothering with doing this cleanup (at a massive scale across all potentially-improvable mochitests) at this point, except in select cases where the tests are actually failing and we need more information to understand the failure.

I'm closing this as WONTFIX; we can file individual bugs for cases where there's a test failure that'd benefit from this style of cleanup.

Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: