diff --git a/tools/tool-testing/selftest.js b/tools/tool-testing/selftest.js index dea0092989..0ab76a721e 100644 --- a/tools/tool-testing/selftest.js +++ b/tools/tool-testing/selftest.js @@ -242,25 +242,25 @@ var newSelfTestCatalog = function () { // Handles the job of waiting until text is seen that matches a // regular expression. -var Matcher = function (run) { - var self = this; - self.buf = ""; - self.fullBuffer = ""; - self.ended = false; - self.resetMatch(); - self.run = run; // used only to set a field on exceptions - self.endPromise = new Promise(resolve => { - self.resolveEndPromise = resolve; - }); -}; +class Matcher { + constructor(run) { + var self = this; + self.buf = ""; + self.fullBuffer = ""; + self.ended = false; + self.resetMatch(); + self.run = run; // used only to set a field on exceptions + self.endPromise = new Promise(resolve => { + self.resolveEndPromise = resolve; + }); + } -_.extend(Matcher.prototype, { - write: function (data) { + write(data) { var self = this; self.buf += data; self.fullBuffer += data; self._tryMatch(); - }, + } resetMatch() { const mp = this.matchPromise; @@ -271,7 +271,7 @@ _.extend(Matcher.prototype, { this.matchFullBuffer = false; return mp; - }, + } rejectMatch(error) { const mp = this.resetMatch(); @@ -282,18 +282,18 @@ _.extend(Matcher.prototype, { // error, so we must throw it instead. throw error; } - }, + } resolveMatch(value) { const mp = this.resetMatch(); if (mp) { mp.resolve(value); } - }, + } match(pattern, timeout, strict) { return this.matchAsync(pattern, { timeout, strict }).await(); - }, + } // Like match, but returns a Promise without calling .await(). matchAsync(pattern, { @@ -330,22 +330,22 @@ _.extend(Matcher.prototype, { clearTimeout(timer); throw error; }); - }, + } matchBeforeEnd(pattern, timeout) { return this._beforeEnd(() => this.matchAsync(pattern, { timeout: timeout || 15, matchFullBuffer: true, })); - }, + } _beforeEnd(promiseCallback) { return this.endPromise = this.endPromise.then(promiseCallback); - }, + } end() { return this.endAsync().await(); - }, + } endAsync() { var self = this; @@ -355,18 +355,18 @@ _.extend(Matcher.prototype, { self._tryMatch(); return self.matchPromise; }); - }, + } - matchEmpty: function () { + matchEmpty() { var self = this; if (self.buf.length > 0) { Console.info("Extra junk is :", self.buf); throw new TestFailure('junk-at-end', { run: self.run }); } - }, + } - _tryMatch: function () { + _tryMatch() { var self = this; var mp = self.matchPromise; @@ -424,8 +424,7 @@ _.extend(Matcher.prototype, { })); } } -}); - +} /////////////////////////////////////////////////////////////////////////////// // OutputLog