From af98ff560121f0e6f0718b868436a96ad23434fa Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Sat, 4 Nov 2017 11:53:25 +0200 Subject: [PATCH 1/9] update dependency versions --- .travis.yml | 2 ++ dub.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ce0edbc..8301e79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,11 +24,13 @@ d: - ldc-1.2.0 - ldc-1.3.0 - ldc-1.4.0 + - ldc-1.5.0 - ldc-beta - dmd-2.073.2 - dmd-2.074.1 - dmd-2.075.1 - dmd-2.076.0 + - dmd-2.077.0 - dmd-beta matrix: diff --git a/dub.json b/dub.json index c2cb435..8a07808 100644 --- a/dub.json +++ b/dub.json @@ -25,7 +25,7 @@ "mainSourceFile": "source/app.d", "dependencies": { - "dub": "~>1.5.0", + "dub": "~>1.6.0", "fluent-asserts": "*", "libdparse": "~>0.7.2-alpha.1" } From 042642de2a528469628fe5cf250adedc3483c3f2 Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Sat, 4 Nov 2017 12:13:27 +0200 Subject: [PATCH 2/9] get the line for the new unittest mangling --- lifecycle/trial/discovery/unit.d | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lifecycle/trial/discovery/unit.d b/lifecycle/trial/discovery/unit.d index 12fae4b..1a7b823 100644 --- a/lifecycle/trial/discovery/unit.d +++ b/lifecycle/trial/discovery/unit.d @@ -352,19 +352,36 @@ class UnitTestDiscovery : ITestDiscovery } } - enum key = "__un" ~ "ittestL"; + static if(__VERSION__ >= 2.077) { + enum key = "__un" ~ "ittest_"; + } else { + enum key = "__un" ~ "ittestL"; + } + enum len = key.length; if (name == defaultName && name.indexOf(key) == 0) { try { - auto postFix = name[len .. $]; - auto idx = postFix.indexOf("_"); - if (idx != -1) - { - auto line = postFix[0 .. idx].to!long; - name = comments.getComment(line, defaultName); + static if(__VERSION__ >= 2.077) { + auto idx = name.indexOf("_d_") + 3; + auto lastIdx = name.lastIndexOf("_"); + + if (idx != -1) + { + auto line = name[idx .. lastIdx].to!long; + name = comments.getComment(line, defaultName); + } + } else { + auto postFix = name[len .. $]; + auto idx = postFix.indexOf("_"); + + if (idx != -1) + { + auto line = postFix[0 .. idx].to!long; + name = comments.getComment(line, defaultName); + } } } catch (Exception e) From 0b6fb6f585c57c8a4064b1fc80911a5bb01d3392 Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Sat, 4 Nov 2017 12:26:25 +0200 Subject: [PATCH 3/9] extract unit test key --- lifecycle/trial/discovery/unit.d | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lifecycle/trial/discovery/unit.d b/lifecycle/trial/discovery/unit.d index 1a7b823..e0e1758 100644 --- a/lifecycle/trial/discovery/unit.d +++ b/lifecycle/trial/discovery/unit.d @@ -20,6 +20,13 @@ import std.typecons; import trial.interfaces; import trial.discovery.code; + +static if(__VERSION__ >= 2.077) { + enum unitTestKey = "__un" ~ "ittest_"; +} else { + enum unitTestKey = "__un" ~ "ittestL"; +} + enum CommentType { none, @@ -317,10 +324,11 @@ class UnitTestDiscovery : ITestDiscovery if (lastName == "") { - lastName = "__unittestL" ~ token.line.to!string; + lastName = unitTestKey ~ token.line.to!string; } auto testCase = TestCase(moduleName, lastName, &noTest, labels); + testCase.location = SourceLocation(file, token.line); testCases ~= testCase; @@ -352,15 +360,9 @@ class UnitTestDiscovery : ITestDiscovery } } - static if(__VERSION__ >= 2.077) { - enum key = "__un" ~ "ittest_"; - } else { - enum key = "__un" ~ "ittestL"; - } - - enum len = key.length; + enum len = unitTestKey.length; - if (name == defaultName && name.indexOf(key) == 0) + if (name == defaultName && name.indexOf(unitTestKey) == 0) { try { @@ -396,8 +398,7 @@ class UnitTestDiscovery : ITestDiscovery { string name = test.stringof.to!string; - enum key = "__un" ~ "ittestL"; - enum len = key.length; + enum len = unitTestKey.length; size_t line; try @@ -609,6 +610,8 @@ unittest auto r = testDiscovery.testCases["trial.discovery.unit"].values.filter!( a => a.name == "It should find the line of this test"); + r.front.location.writeln; + r.empty.should.equal(false).because("the location should be present"); r.front.location.fileName.should.endWith("unit.d"); r.front.location.line.should.equal(line); @@ -722,7 +725,7 @@ unittest auto testDiscovery = new UnitTestDiscovery; testDiscovery.discoverTestCases(__FILE__).map!(a => a.name) - .array.should.contain("__unittestL" ~ line.to!string); + .array.should.contain(unitTestKey ~ line.to!string); } /// discoverTestCases should find the same tests like testCases @@ -736,9 +739,9 @@ unittest b) => a.location.line < b.location.line).array; foreach (index, test; allTests) { - if (test.name.indexOf("__unittestL701") == 0) + if (test.name.indexOf(unitTestKey ~ "701") == 0) { - allTests[index].name = "__unittestL701"; + allTests[index].name = unitTestKey ~ "701"; } } From d3d81aff390e3897959d03e7915026ebf3331203 Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Sat, 4 Nov 2017 13:14:21 +0200 Subject: [PATCH 4/9] fix broken tests on 77 --- lifecycle/trial/discovery/unit.d | 72 +++++++++++++++++++------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/lifecycle/trial/discovery/unit.d b/lifecycle/trial/discovery/unit.d index e0e1758..6764ade 100644 --- a/lifecycle/trial/discovery/unit.d +++ b/lifecycle/trial/discovery/unit.d @@ -324,7 +324,11 @@ class UnitTestDiscovery : ITestDiscovery if (lastName == "") { - lastName = unitTestKey ~ token.line.to!string; + static if(__VERSION__ >= 2.077) { + lastName = __MODULE__.replace(".", "_") ~ "_d_" ~ token.line.to!string; + } else { + lastName = unitTestKey ~ token.line.to!string; + } } auto testCase = TestCase(moduleName, lastName, &noTest, labels); @@ -366,24 +370,10 @@ class UnitTestDiscovery : ITestDiscovery { try { - static if(__VERSION__ >= 2.077) { - auto idx = name.indexOf("_d_") + 3; - auto lastIdx = name.lastIndexOf("_"); + auto line = extractLine(name); - if (idx != -1) - { - auto line = name[idx .. lastIdx].to!long; - name = comments.getComment(line, defaultName); - } - } else { - auto postFix = name[len .. $]; - auto idx = postFix.indexOf("_"); - - if (idx != -1) - { - auto line = postFix[0 .. idx].to!long; - name = comments.getComment(line, defaultName); - } + if(line != 0) { + name = comments.getComment(line, defaultName); } } catch (Exception e) @@ -394,6 +384,20 @@ class UnitTestDiscovery : ITestDiscovery return name; } + size_t extractLine(string name) { + static if(__VERSION__ >= 2.077) { + auto idx = name.indexOf("_d_") + 3; + auto lastIdx = name.lastIndexOf("_"); + + return idx != -1 ? name[idx .. lastIdx].to!long : 0; + } else { + auto postFix = name[len .. $]; + auto idx = postFix.indexOf("_"); + + return idx != -1 ? postFix[0 .. idx].to!long : 0; + } + } + SourceLocation testSourceLocation(alias test)(string fileName) { string name = test.stringof.to!string; @@ -403,13 +407,7 @@ class UnitTestDiscovery : ITestDiscovery try { - auto postFix = name[len .. $]; - auto idx = postFix.indexOf("_"); - - if (idx != -1) - { - line = postFix[0 .. idx].to!size_t; - } + line = extractLine(name); } catch (Exception e) { @@ -724,8 +722,13 @@ unittest immutable line = __LINE__ - 3; auto testDiscovery = new UnitTestDiscovery; - testDiscovery.discoverTestCases(__FILE__).map!(a => a.name) - .array.should.contain(unitTestKey ~ line.to!string); + static if(__VERSION__ >= 2.077) { + testDiscovery.discoverTestCases(__FILE__).map!(a => a.name) + .array.should.contain(__MODULE__.replace(".", "_") ~ "_d_" ~ line.to!string); + } else { + testDiscovery.discoverTestCases(__FILE__).map!(a => a.name) + .array.should.contain(unitTestKey ~ line.to!string); + } } /// discoverTestCases should find the same tests like testCases @@ -737,11 +740,20 @@ unittest auto allTests = testDiscovery.getTestCases.sort!((a, b) => a.location.line < b.location.line).array; + foreach (index, test; allTests) { - if (test.name.indexOf(unitTestKey ~ "701") == 0) - { - allTests[index].name = unitTestKey ~ "701"; + + static if(__VERSION__ >= 2.077) { + if (test.name.indexOf(__MODULE__.replace(".", "_") ~ "_d_719") != -1) + { + allTests[index].name = __MODULE__.replace(".", "_") ~ "_d_719"; + } + } else { + if (test.name.indexOf(unitTestKey ~ "719") != -1) + { + allTests[index].name = unitTestKey ~ "719"; + } } } From e8cea6239ab3730140955cc9f695330b9d80e77b Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Sat, 4 Nov 2017 13:41:43 +0200 Subject: [PATCH 5/9] fix 32bit build --- lifecycle/trial/discovery/unit.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lifecycle/trial/discovery/unit.d b/lifecycle/trial/discovery/unit.d index 6764ade..8f30368 100644 --- a/lifecycle/trial/discovery/unit.d +++ b/lifecycle/trial/discovery/unit.d @@ -384,7 +384,7 @@ class UnitTestDiscovery : ITestDiscovery return name; } - size_t extractLine(string name) { + long extractLine(string name) { static if(__VERSION__ >= 2.077) { auto idx = name.indexOf("_d_") + 3; auto lastIdx = name.lastIndexOf("_"); From a2e55a9b4344d6f813e5b035981159fb48400ecd Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Sat, 4 Nov 2017 14:29:06 +0200 Subject: [PATCH 6/9] update trial --- lifecycle/trial/discovery/unit.d | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lifecycle/trial/discovery/unit.d b/lifecycle/trial/discovery/unit.d index 8f30368..8407e13 100644 --- a/lifecycle/trial/discovery/unit.d +++ b/lifecycle/trial/discovery/unit.d @@ -384,17 +384,17 @@ class UnitTestDiscovery : ITestDiscovery return name; } - long extractLine(string name) { + size_t extractLine(string name) { static if(__VERSION__ >= 2.077) { auto idx = name.indexOf("_d_") + 3; auto lastIdx = name.lastIndexOf("_"); - return idx != -1 ? name[idx .. lastIdx].to!long : 0; + return idx != -1 ? name[idx .. lastIdx].to!size_t : 0; } else { auto postFix = name[len .. $]; auto idx = postFix.indexOf("_"); - return idx != -1 ? postFix[0 .. idx].to!long : 0; + return idx != -1 ? postFix[0 .. idx].to!size_t : 0; } } From c1b63bc82806006e2520eca9f7afcd02b1eb0b1e Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Sat, 4 Nov 2017 14:55:12 +0200 Subject: [PATCH 7/9] fix broken code --- lifecycle/trial/discovery/unit.d | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lifecycle/trial/discovery/unit.d b/lifecycle/trial/discovery/unit.d index 8407e13..8ae4636 100644 --- a/lifecycle/trial/discovery/unit.d +++ b/lifecycle/trial/discovery/unit.d @@ -21,7 +21,7 @@ import trial.interfaces; import trial.discovery.code; -static if(__VERSION__ >= 2.077) { +static if(__VERSION__ >= 2077) { enum unitTestKey = "__un" ~ "ittest_"; } else { enum unitTestKey = "__un" ~ "ittestL"; @@ -324,7 +324,7 @@ class UnitTestDiscovery : ITestDiscovery if (lastName == "") { - static if(__VERSION__ >= 2.077) { + static if(__VERSION__ >= 2077) { lastName = __MODULE__.replace(".", "_") ~ "_d_" ~ token.line.to!string; } else { lastName = unitTestKey ~ token.line.to!string; @@ -385,12 +385,13 @@ class UnitTestDiscovery : ITestDiscovery } size_t extractLine(string name) { - static if(__VERSION__ >= 2.077) { + static if(__VERSION__ >= 2077) { auto idx = name.indexOf("_d_") + 3; auto lastIdx = name.lastIndexOf("_"); return idx != -1 ? name[idx .. lastIdx].to!size_t : 0; } else { + enum len = unitTestKey.length; auto postFix = name[len .. $]; auto idx = postFix.indexOf("_"); @@ -608,8 +609,6 @@ unittest auto r = testDiscovery.testCases["trial.discovery.unit"].values.filter!( a => a.name == "It should find the line of this test"); - r.front.location.writeln; - r.empty.should.equal(false).because("the location should be present"); r.front.location.fileName.should.endWith("unit.d"); r.front.location.line.should.equal(line); @@ -722,7 +721,7 @@ unittest immutable line = __LINE__ - 3; auto testDiscovery = new UnitTestDiscovery; - static if(__VERSION__ >= 2.077) { + static if(__VERSION__ >= 2077) { testDiscovery.discoverTestCases(__FILE__).map!(a => a.name) .array.should.contain(__MODULE__.replace(".", "_") ~ "_d_" ~ line.to!string); } else { @@ -743,16 +742,15 @@ unittest foreach (index, test; allTests) { - - static if(__VERSION__ >= 2.077) { - if (test.name.indexOf(__MODULE__.replace(".", "_") ~ "_d_719") != -1) + static if(__VERSION__ >= 2077) { + if (test.name.indexOf(__MODULE__.replace(".", "_") ~ "_d_718") != -1) { - allTests[index].name = __MODULE__.replace(".", "_") ~ "_d_719"; + allTests[index].name = __MODULE__.replace(".", "_") ~ "_d_718"; } } else { - if (test.name.indexOf(unitTestKey ~ "719") != -1) + if (test.name.indexOf(unitTestKey ~ "718") != -1) { - allTests[index].name = unitTestKey ~ "719"; + allTests[index].name = unitTestKey ~ "718"; } } } From 0dacd0b3728a529ae63960791aac6be6d1cc9047 Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Sat, 4 Nov 2017 16:40:02 +0200 Subject: [PATCH 8/9] update unit discovery --- lifecycle/trial/discovery/unit.d | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lifecycle/trial/discovery/unit.d b/lifecycle/trial/discovery/unit.d index 8ae4636..4081f66 100644 --- a/lifecycle/trial/discovery/unit.d +++ b/lifecycle/trial/discovery/unit.d @@ -325,7 +325,7 @@ class UnitTestDiscovery : ITestDiscovery if (lastName == "") { static if(__VERSION__ >= 2077) { - lastName = __MODULE__.replace(".", "_") ~ "_d_" ~ token.line.to!string; + lastName = moduleName.replace(".", "_") ~ "_d_" ~ token.line.to!string; } else { lastName = unitTestKey ~ token.line.to!string; } @@ -743,14 +743,14 @@ unittest foreach (index, test; allTests) { static if(__VERSION__ >= 2077) { - if (test.name.indexOf(__MODULE__.replace(".", "_") ~ "_d_718") != -1) + if (test.name.indexOf(__MODULE__.replace(".", "_") ~ "_d_719") != -1) { - allTests[index].name = __MODULE__.replace(".", "_") ~ "_d_718"; + allTests[index].name = __MODULE__.replace(".", "_") ~ "_d_719"; } } else { - if (test.name.indexOf(unitTestKey ~ "718") != -1) + if (test.name.indexOf(unitTestKey ~ "719") != -1) { - allTests[index].name = unitTestKey ~ "718"; + allTests[index].name = unitTestKey ~ "719"; } } } From 6968638ab2431a23182005e337739264a2143681 Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Sat, 4 Nov 2017 16:57:37 +0200 Subject: [PATCH 9/9] fix test discovery --- lifecycle/trial/discovery/unit.d | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lifecycle/trial/discovery/unit.d b/lifecycle/trial/discovery/unit.d index 4081f66..1891089 100644 --- a/lifecycle/trial/discovery/unit.d +++ b/lifecycle/trial/discovery/unit.d @@ -743,14 +743,14 @@ unittest foreach (index, test; allTests) { static if(__VERSION__ >= 2077) { - if (test.name.indexOf(__MODULE__.replace(".", "_") ~ "_d_719") != -1) + if (test.name.indexOf(__MODULE__.replace(".", "_") ~ "_d_718") != -1) { - allTests[index].name = __MODULE__.replace(".", "_") ~ "_d_719"; + allTests[index].name = __MODULE__.replace(".", "_") ~ "_d_718"; } } else { - if (test.name.indexOf(unitTestKey ~ "719") != -1) + if (test.name.indexOf(unitTestKey ~ "718") != -1) { - allTests[index].name = unitTestKey ~ "719"; + allTests[index].name = unitTestKey ~ "718"; } } }