|
| 1 | +(function(){ |
| 2 | + |
| 3 | + /*global YUITest, CSSLint*/ |
| 4 | + var Assert = YUITest.Assert; |
| 5 | + |
| 6 | + YUITest.TestRunner.add(new YUITest.TestCase({ |
| 7 | + |
| 8 | + name: "JUNIT XML formatter test", |
| 9 | + |
| 10 | + "File with no problems should say so": function(){ |
| 11 | + |
| 12 | + var result = { messages: [], stats: [] }, |
| 13 | + expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><testsuites></testsuites>"; |
| 14 | + Assert.areEqual(expected, CSSLint.format(result, "FILE", "junit-xml")); |
| 15 | + |
| 16 | + }, |
| 17 | + |
| 18 | + "File with problems should list them": function(){ |
| 19 | + |
| 20 | + var result = { messages: [ |
| 21 | + { type: "warning", line: 1, col: 1, message: "BOGUS", evidence: "ALSO BOGUS", rule: { name: "A Rule"} }, |
| 22 | + { type: "error", line: 2, col: 1, message: "BOGUS", evidence: "ALSO BOGUS", rule: { name: "Some Other Rule"} } |
| 23 | + ], stats: [] }, |
| 24 | + |
| 25 | + file = "<testsuite time=\"0\" tests=\"2\" skipped=\"0\" errors=\"2\" failures=\"0\" package=\"net.csslint\" name=\"FILE\">", |
| 26 | + error1 = "<testcase time=\"0\" name=\"net.csslint.ARule\"><error message=\"BOGUS\"><![CDATA[1:1:ALSO BOGUS]]></error></testcase>", |
| 27 | + error2 = "<testcase time=\"0\" name=\"net.csslint.SomeOtherRule\"><error message=\"BOGUS\"><![CDATA[2:1:ALSO BOGUS]]></error></testcase>", |
| 28 | + expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><testsuites>" + file + error1 + error2 + "</testsuite></testsuites>", |
| 29 | + actual = CSSLint.format(result, "FILE", "junit-xml"); |
| 30 | + |
| 31 | + Assert.areEqual(expected, actual); |
| 32 | + |
| 33 | + }, |
| 34 | + |
| 35 | + "Formatter should escape special characters": function() { |
| 36 | + |
| 37 | + var specialCharsSting = 'sneaky, "sneaky", <sneaky>', |
| 38 | + result = { messages: [ |
| 39 | + { type: "warning", line: 1, col: 1, message: specialCharsSting, evidence: "ALSO BOGUS", rule: [] }, |
| 40 | + { type: "error", line: 2, col: 1, message: specialCharsSting, evidence: "ALSO BOGUS", rule: [] } |
| 41 | + ], stats: [] }, |
| 42 | + |
| 43 | + file = "<testsuite time=\"0\" tests=\"2\" skipped=\"0\" errors=\"2\" failures=\"0\" package=\"net.csslint\" name=\"FILE\">", |
| 44 | + error1 = "<testcase time=\"0\" name=\"\"><error message=\"sneaky, 'sneaky', <sneaky>\"><![CDATA[1:1:ALSO BOGUS]]></error></testcase>", |
| 45 | + error2 = "<testcase time=\"0\" name=\"\"><error message=\"sneaky, 'sneaky', <sneaky>\"><![CDATA[2:1:ALSO BOGUS]]></error></testcase>", |
| 46 | + expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><testsuites>" + file + error1 + error2 + "</testsuite></testsuites>", |
| 47 | + actual = CSSLint.format(result, "FILE", "junit-xml"); |
| 48 | + |
| 49 | + Assert.areEqual(expected, actual); |
| 50 | + |
| 51 | + } |
| 52 | + |
| 53 | + })); |
| 54 | +})(); |
0 commit comments