diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/modules/tests/xpcshell/test_structuredlog.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/modules/tests/xpcshell/test_structuredlog.js')
-rw-r--r-- | testing/modules/tests/xpcshell/test_structuredlog.js | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/testing/modules/tests/xpcshell/test_structuredlog.js b/testing/modules/tests/xpcshell/test_structuredlog.js new file mode 100644 index 000000000..3a6fbb8ed --- /dev/null +++ b/testing/modules/tests/xpcshell/test_structuredlog.js @@ -0,0 +1,145 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +function run_test () { + Components.utils.import("resource://testing-common/StructuredLog.jsm"); + + let testBuffer = []; + + let appendBuffer = function (msg) { + testBuffer.push(JSON.stringify(msg)); + } + + let assertLastMsg = function (refData) { + // Check all fields in refData agree with those in the + // last message logged, and pop that message. + let lastMsg = JSON.parse(testBuffer.pop()); + for (let field in refData) { + deepEqual(lastMsg[field], refData[field]); + } + // The logger should always set the source to the logger name. + equal(lastMsg.source, "test_log"); + // The source_file field is always set by the mutator function. + equal(lastMsg.source_file, "test_structuredlog.js"); + } + + let addFileName = function (data) { + data.source_file = "test_structuredlog.js"; + } + + let logger = new StructuredLogger("test_log", appendBuffer, [addFileName]); + + // Test unstructured logging + logger.info("Test message"); + assertLastMsg({ + action: "log", + message: "Test message", + level: "INFO", + }); + + logger.info("Test message", + extra={foo: "bar"}); + assertLastMsg({ + action: "log", + message: "Test message", + level: "INFO", + extra: {foo: "bar"}, + }); + + // Test end / start actions + logger.testStart("aTest"); + assertLastMsg({ + test: "aTest", + action: "test_start", + }); + + logger.testEnd("aTest", "OK"); + assertLastMsg({ + test: "aTest", + action: "test_end", + status: "OK" + }); + + // A failed test populates the "expected" field. + logger.testStart("aTest"); + logger.testEnd("aTest", "FAIL", "PASS"); + assertLastMsg({ + action: "test_end", + test: "aTest", + status: "FAIL", + expected: "PASS" + }); + + // A failed test populates the "expected" field. + logger.testStart("aTest"); + logger.testEnd("aTest", "FAIL", "PASS", null, "Many\nlines\nof\nstack\n"); + assertLastMsg({ + action: "test_end", + test: "aTest", + status: "FAIL", + expected: "PASS", + stack: "Many\nlines\nof\nstack\n" + }); + + // Skipped tests don't log failures + logger.testStart("aTest"); + logger.testEnd("aTest", "SKIP", "PASS"); + ok(!JSON.parse(testBuffer[testBuffer.length - 1]).hasOwnProperty("expected")); + assertLastMsg({ + action: "test_end", + test: "aTest", + status: "SKIP" + }); + + logger.testStatus("aTest", "foo", "PASS", "PASS", "Passed test"); + ok(!JSON.parse(testBuffer[testBuffer.length - 1]).hasOwnProperty("expected")); + assertLastMsg({ + action: "test_status", + test: "aTest", + subtest: "foo", + status: "PASS", + message: "Passed test" + }); + + logger.testStatus("aTest", "bar", "FAIL"); + assertLastMsg({ + action: "test_status", + test: "aTest", + subtest: "bar", + status: "FAIL", + expected: "PASS" + }); + + logger.testStatus("aTest", "bar", "FAIL", "PASS", null, + "Many\nlines\nof\nstack\n"); + assertLastMsg({ + action: "test_status", + test: "aTest", + subtest: "bar", + status: "FAIL", + expected: "PASS", + stack: "Many\nlines\nof\nstack\n" + }); + + // Skipped tests don't log failures + logger.testStatus("aTest", "baz", "SKIP"); + ok(!JSON.parse(testBuffer[testBuffer.length - 1]).hasOwnProperty("expected")); + assertLastMsg({ + action: "test_status", + test: "aTest", + subtest: "baz", + status: "SKIP" + }); + + // Suite start and end messages. + logger.suiteStart(["aTest"]); + assertLastMsg({ + action: "suite_start", + tests: ["aTest"], + }); + + logger.suiteEnd(); + assertLastMsg({ + action: "suite_end", + }); +} |