| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 Loading... | |
| 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]"); |
|
hub
2017/11/28 19:49:45
Another alternative is:
let msgMatch = new RegExp
Wladimir Palant
2017/11/28 20:00:57
So, what about looking at s.message only?
| |
| 439 let errorHandler = console.error; | 441 let errorHandler = console.error; |
| 440 console.error = s => | 442 console.error = (...args) => |
|
Wladimir Palant
2017/11/28 20:00:57
Nit: Why is this parameter called s? It's not nece
sergei
2017/11/28 20:34:24
It's Error.prototype.stack (https://github.com/adb
hub
2017/11/28 20:54:33
Oh. I see.
In our code, assert2() will always cal
| |
| 441 { | 443 { |
| 442 let match = s.match(msgMatch); | 444 let s = (args[0] instanceof Error ? args[0].message : args[0]); |
| 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 Loading... | |
| 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 }; |
| LEFT | RIGHT |