diff --git a/source/trial/interfaces.d b/source/trial/interfaces.d index a04ad5c..475907b 100644 --- a/source/trial/interfaces.d +++ b/source/trial/interfaces.d @@ -64,7 +64,7 @@ string toJsonString(Throwable throwable) { /// convert a Throwable to json unittest { auto exception = new Exception("some message", __FILE__, 58); - exception.toJsonString.should.equal(`{"file":"source/interfaces.d","line":"58","msg":"some message","info":"null","raw":"object.Exception@source/interfaces.d(58): some message"}`); + exception.toJsonString.should.equal(`{"file":"source/trial/interfaces.d","line":"58","msg":"some message","info":"null","raw":"object.Exception@source/trial/interfaces.d(58): some message"}`); } /// A listener that provides test cases to be executed diff --git a/source/trial/reporters/allure.d b/source/trial/reporters/allure.d index 5573a13..ee4dd20 100644 --- a/source/trial/reporters/allure.d +++ b/source/trial/reporters/allure.d @@ -35,8 +35,7 @@ private string escape(string data) { /// The Allure reporter creates a xml containing the test results, the steps /// and the attachments. http://allure.qatools.ru/ -class AllureReporter : ILifecycleListener -{ +class AllureReporter : ILifecycleListener { private { immutable string destination; } @@ -46,24 +45,24 @@ class AllureReporter : ILifecycleListener } void begin(ulong testCount) { - if(exists(destination)) { + if (exists(destination)) { std.file.rmdirRecurse(destination); } } - void update() {} + void update() { + } - void end(SuiteResult[] result) - { - if(!exists(destination)) { + void end(SuiteResult[] result) { + if (!exists(destination)) { destination.mkdirRecurse; } - foreach(item; result) { + foreach (item; result) { string uuid = randomUUID.toString; string xml = AllureSuiteXml(destination, item, uuid).toString; - std.file.write(buildPath(destination, uuid ~ "-testsuite.xml"), xml); + std.file.write(buildPath(destination, uuid ~ "-testsuite.xml"), xml); } } } @@ -91,24 +90,34 @@ struct AllureSuiteXml { /// Converts the suiteResult to a xml string string toString() { auto epoch = SysTime.fromUnixTime(0); - string tests = result.tests.map!(a => AllureTestXml(destination, a, uuid).toString).array.join("\n"); + string tests = result.tests.map!(a => AllureTestXml(destination, a, uuid) + .toString).array.join("\n"); - if(tests != "") { + if (tests != "") { tests = "\n" ~ tests; } auto xml = ` - - ` ~ result.name.escape ~ ` - ` ~ result.name.escape ~ ` + + ` + ~ result.name.escape ~ ` + ` + ~ result.name.escape ~ ` ` - ~ tests ~ ` + ~ tests ~ ` `; - if(result.attachments.length > 0) { + if (result.attachments.length > 0) { xml ~= " \n"; - xml ~= result.attachments.map!(a => AllureAttachmentXml(destination, a, 6, uuid)).map!(a => a.toString).array.join('\n') ~ "\n"; + xml ~= result.attachments + .map!(a => AllureAttachmentXml(destination, a, 6, uuid)) + .map!(a => a.toString) + .array + .join('\n') ~ "\n"; xml ~= " \n"; } @@ -122,13 +131,12 @@ struct AllureSuiteXml { } } -version(unittest) { +version (unittest) { import fluent.asserts; } @("AllureSuiteXml should transform an empty suite") -unittest -{ +unittest { auto epoch = SysTime.fromUnixTime(0); auto result = SuiteResult("Test Suite"); result.begin = Clock.currTime; @@ -140,16 +148,24 @@ unittest result.end = Clock.currTime; - result.tests = [ test ]; + result.tests = [test]; auto allure = AllureSuiteXml("allure", result, ""); allure.toString.should.equal(` - - ` ~ result.name ~ ` - ` ~ result.name ~ ` + + ` + ~ result.name ~ ` + ` + ~ result.name ~ ` - + Test @@ -161,8 +177,7 @@ unittest } @("AllureSuiteXml should transform a suite with a success test") -unittest -{ +unittest { auto epoch = SysTime.fromUnixTime(0); auto result = SuiteResult("Test Suite"); result.begin = Clock.currTime; @@ -171,9 +186,14 @@ unittest auto allure = AllureSuiteXml("allure", result, ""); allure.toString.should.equal(` - - ` ~ result.name ~ ` - ` ~ result.name ~ ` + + ` + ~ result.name ~ ` + ` + ~ result.name ~ ` @@ -183,16 +203,14 @@ unittest `); } - /// AllureSuiteXml should add the attachments -unittest -{ +unittest { string resource = buildPath(getcwd(), "some_text.txt"); std.file.write(resource, ""); auto uuid = randomUUID.toString; - scope(exit) { + scope (exit) { remove(resource); remove("allure/" ~ uuid ~ "/title.0.some_text.txt"); } @@ -202,19 +220,25 @@ unittest auto result = SuiteResult("Test Suite"); result.begin = Clock.currTime; result.end = Clock.currTime; - result.attachments = [ Attachment("title", resource, "plain/text") ]; + result.attachments = [Attachment("title", resource, "plain/text")]; auto allure = AllureSuiteXml("allure", result, uuid); allure.toString.should.equal( - ` - - ` ~ result.name ~ ` - ` ~ result.name ~ ` + ` + + ` + ~ result.name ~ ` + ` + ~ result.name ~ ` - +