Closed Bug 880568 Opened 10 years ago Closed 10 years ago

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


(Testing :: XPCShell Harness, defect)

Not set


(Not tracked)



(Reporter: jaws, Assigned: jaws)



(2 files)

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.
Attached 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
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;
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).
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla24
You need to log in before you can comment on or make changes to this bug.