aboutsummaryrefslogtreecommitdiff
path: root/source/util.d
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2019-05-27 19:38:06 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2019-05-27 19:38:06 -0400
commitfba3ce4d5ba5ec9093a1cfa397e4432f24d7f44a (patch)
tree7a163d03b735778302712e948ba4f566d7915df1 /source/util.d
parentda0a1109fdfeb98fce2d870783fc24d9312e55a4 (diff)
downloaddm-fba3ce4d5ba5ec9093a1cfa397e4432f24d7f44a.tar.gz
handle xunit2
Diffstat (limited to 'source/util.d')
-rw-r--r--source/util.d61
1 files changed, 61 insertions, 0 deletions
diff --git a/source/util.d b/source/util.d
index 04b8be7..a33751e 100644
--- a/source/util.d
+++ b/source/util.d
@@ -2,6 +2,10 @@ module util;
import std.stdio;
import std.string;
import std.process;
+import std.algorithm;
+import std.file;
+import std.path;
+import std.conv : to;
enum byte MAXCOLS = 80;
@@ -93,3 +97,60 @@ string safe_install(string specs) {
}
return result.join(" ");
}
+
+
+string pytest_xunit2(string filename) {
+ string _data = readText(filename);
+ string data;
+ string result;
+ bool inject = false;
+ bool inject_wait = false;
+ bool has_section = false;
+ bool has_junit_family = false;
+ string section;
+ immutable string key = "junit_family";
+ immutable string cfgitem = key ~ " = xunit2";
+
+ if (filename.baseName == "setup.cfg") {
+ section = "[tool:pytest]";
+ } else if (filename.baseName == "pytest.ini") {
+ section = "[pytest]";
+ }
+
+ foreach (line; splitLines(_data)) {
+ string tmp = line.to!string;
+ if (canFind(tmp, section)) {
+ has_section = true;
+ }
+ if (canFind(tmp, key)) {
+ has_junit_family = true;
+ }
+ data ~= tmp ~ "\n";
+ }
+
+ if (!has_section) {
+ return data ~ format("\n%s\n%s\n", section, cfgitem);
+ }
+
+ foreach (rec; splitLines(data)) {
+ if (!has_section) {
+ break;
+ } else if (rec.strip == section && !has_junit_family) {
+ inject = true;
+ } else if (has_junit_family) {
+ inject_wait = true;
+ } else if (inject_wait) {
+ if (canFind(rec, key)) {
+ rec = cfgitem ~ "\n";
+ inject_wait = false;
+ }
+ } else if (inject) {
+ result ~= cfgitem ~ "\n";
+ inject = false;
+ }
+
+ result ~= rec ~ "\n";
+ }
+
+ return result;
+}