Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/_common.js

Issue 29622595: Issue 6090 - Properly use regexp for message matching and proper console override (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created Nov. 28, 2017, 3:28 p.m.
Right Patch Set: Properly handle args Created Nov. 29, 2017, 3:21 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 now: () => currentTime 411 now: () => currentTime
412 } 412 }
413 }; 413 };
414 }; 414 };
415 415
416 console.warn = console.log; 416 console.warn = console.log;
417 417
418 exports.silenceWarnOutput = function(test, msg) 418 exports.silenceWarnOutput = function(test, msg)
419 { 419 {
420 let warnHandler = console.warn; 420 let warnHandler = console.warn;
421 console.warn = s => 421 console.warn = (...args) =>
422 { 422 {
423 let s = (args[0] instanceof Error ? args[0].message : args[0]);
424
423 if (s != msg) 425 if (s != msg)
424 warnHandler(s); 426 warnHandler(...args);
425 }; 427 };
426 try 428 try
427 { 429 {
428 return test(); 430 return test();
429 } 431 }
430 finally 432 finally
431 { 433 {
432 console.warn = warnHandler; 434 console.warn = warnHandler;
433 } 435 }
434 }; 436 };
435 437
436 exports.silenceAssertionOutput = function(test, msg) 438 exports.silenceAssertionOutput = function(test, msg)
437 { 439 {
438 let msgMatch = new RegExp("^Error: (.*)[\r\n]"); 440 let msgMatch = new RegExp("^Error: (.*)[\r\n]");
439 let errorHandler = console.error; 441 let errorHandler = console.error;
440 console.error = s => 442 console.error = (...args) =>
sergei 2017/11/28 15:46:22 should not we wrap even a single argument of the l
hub 2017/11/28 15:54:20 This follow our code style.
441 { 443 {
442 let match = msgMatch.match(s); 444 let s = (args[0] instanceof Error ? args[0].message : args[0]);
sergei 2017/11/28 15:46:22 AFAIR regexp does not have method `match`, it shou
hub 2017/11/28 15:54:20 Already fixed in the patch update. I have no idea
445 let match = s && s.match(msgMatch);
443 if (!match || match[1] != msg) 446 if (!match || match[1] != msg)
444 errorHandler(s); 447 errorHandler(...args);
445 }; 448 };
446 try 449 try
447 { 450 {
448 return test(); 451 return test();
449 } 452 }
450 finally 453 finally
451 { 454 {
452 console.error = errorHandler; 455 console.error = errorHandler;
453 } 456 }
454 }; 457 };
(...skipping 13 matching lines...) Expand all
468 } 471 }
469 }) 472 })
470 }; 473 };
471 }; 474 };
472 475
473 exports.unexpectedError = function(error) 476 exports.unexpectedError = function(error)
474 { 477 {
475 console.error(error); 478 console.error(error);
476 this.ok(false, "Unexpected error: " + error); 479 this.ok(false, "Unexpected error: " + error);
477 }; 480 };
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld