Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tweaked the XML generator a bit.

  • Loading branch information...
commit 0295bfa8f4da3bd5189787f083aa5e48af016080 1 parent 25e5a6c
@atesgoral authored
Showing with 27 additions and 11 deletions.
  1. +27 −11 jsunity/test/runner.html
View
38 jsunity/test/runner.html
@@ -40,21 +40,37 @@
var results = jsUnity.run(AssertionTestSuite, CoreTestSuite);
- var xml = [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ];
+ function xmlEscape(s) {
+ return s.replace(/[<>&"]/g, function (c) {
+ return "&"
+ + { "<": "lt", ">": "gt", "&": "amp", "\"": "quot" }[c]
+ + ";";
+ });
+ }
+
+ var xml = [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ];
+
+ xml.text = function (s) {
+ Array.prototype.push.call(this, s);
+ return this;
+ };
xml.elem = function (tagName, attrs, close) {
- var out = [];
- out.$ = function (s) { this.push(s); return this; };
- out.$("<").$(tagName);
+ this.text("<").text(tagName);
+
for (var a in attrs || {}) {
- out.$(" ").$(a).$("=\"").$(attrs[a]).$("\""); // encode!!
+ this.text(" ").text(a).text("=\"")
+ .text(xmlEscape(String(attrs[a]))).text("\"");
}
- close && out.$("/");
- out.$(">");
- this.push(out.join(""));
+
+ close && this.text("/");
+ this.text(">\n");
+
return this;
};
+ xml.toString = function () { return this.join(""); }
+
xml.elem("testsuite", {
errors: 0,
failures: results.failed,
@@ -72,14 +88,14 @@
}, test.passed);
if (!test.passed) {
- xml.elem("failure", { message: test.failureMessage });
- xml.elem("/testcase");
+ xml.elem("failure", { message: test.failureMessage })
+ .elem("/testcase");
}
}
xml.elem("/testsuite");
- document.getElementById("results").value = xml.join("\n");
+ document.getElementById("results").value = xml;
//document.getElementById("save").submit();
};
</script>
Please sign in to comment.
Something went wrong with that request. Please try again.