_do_check_eq/_do_check_neq/do_print should put double-quotes around argument if the typeof argument is "string"

RESOLVED FIXED in mozilla24

Status

defect
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: jaws, Assigned: jaws)

Tracking

Trunk
mozilla24
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments)

When do_print is used and a string argument is passed to it, the output should be surrounded by double-quotes.

I ran into this today, where I had a string with the value "null". do_print outputted: null

However my tests for variable == null were failing, because variable was actually equal to "null". Quotes around the output would have helped me fix the test faster.
Posted patch PatchSplinter Review
We could do the same thing for _do_check_eq, but I'm not sure if that will confuse people or not.
Assignee: nobody → jaws
Status: NEW → ASSIGNED
Attachment #759585 - Flags: review?(ted)
... and here's a second patch that also includes changes to do_check_eq and do_check_neq for consistency.

I also noticed that there is some duplicate code between _do_check_neq and do_report_result. I'll file a separate bug to clean that up.
Attachment #759589 - Flags: review?(ted)
Filed bug 880573 for the de-duplication.
Attachment #759585 - Flags: review?(ted) → review+
Comment on attachment 759589 [details] [diff] [review]
Patch including changes to do_check_eq and do_check_neq

Review of attachment 759589 [details] [diff] [review]:
-----------------------------------------------------------------

::: testing/xpcshell/head.js
@@ +399,5 @@
>   * Prints a message to the output log.
>   */
>  function do_print(msg) {
>    var caller_stack = Components.stack.caller;
> +  msg = typeof msg == "string" ? '"' + msg + '"' : msg;

Feels like you probably want to put this into a helper function at this point, but it's not critical.
Attachment #759589 - Flags: review?(ted) → review+
Thanks! I pulled that out to this function...

function _wrap_with_quotes_if_necessary(val) {
  return typeof val == "string" ? '"' + val + '"' : val;
}

https://hg.mozilla.org/integration/mozilla-inbound/rev/606e6dbf61e1
Summary: do_print should put double-quotes around output if the typeof argument is "string" → _do_check_eq/_do_check_neq/do_print should put double-quotes around argument if the typeof argument is "string"
Hmm, we're using == and != for these things?  I filed bug 880798 to switch from == to SameValue-style comparisons (see the bug for a description of SameValue semantics).
https://hg.mozilla.org/mozilla-central/rev/606e6dbf61e1
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla24
You need to log in before you can comment on or make changes to this bug.