Skip to content

Commit

Permalink
Merge pull request #2693 from qorelanguage/bugfix/2680_QUnit_output_fix
Browse files Browse the repository at this point in the history
refs #2680 improved QUnit output in assertion failures for strings wi…
  • Loading branch information
sejvlond committed Mar 12, 2018
2 parents 41c00d5 + eabfbbd commit 3d6bc37
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doxygen/lang/900_release_notes.dox.tmpl
Expand Up @@ -9,6 +9,8 @@

@subsection qore_08133_bug_fixes Bug Fixes in Qore
- module fixes:
- <a href="../../modules/QUnit/html/index.html">QUnit</a>:
- improved output in assertion failures for strings with special whitespace and for multi-line data structures (<a href="https://github.com/qorelanguage/qore/issues/2680">issue 2680</a>)
- <a href="../../modules/WebUtil/html/index.html">WebUtil</a>:
- made it possible for FileHandler subclasses to add headers to response (<a href="https://github.com/qorelanguage/qore/issues/2686">issue 2686</a>)
- fixed a bug where a crash would result when evaluting certain expressions in the @ref background "brackground operator" due to a memory error (<a href="https://github.com/qorelanguage/qore/issues/2679">issue 2679</a>)
Expand Down
13 changes: 13 additions & 0 deletions examples/test/qlib/QUnit/tests.qtest
Expand Up @@ -222,6 +222,19 @@ public class QUnitTest inherits QUnit::Test {
# force the test that failed to pass
assertionOk();
}

{
list l1 = ("hello\nworld",);
list l2 = ("hello\nmars",);
try {
assertEq(l1, l2);
}
catch (hash<ExceptionInfo> ex) {
#printf("desc: %y\n", ex.desc);
assertTrue(ex.desc =~ /hello\\\\nworld/);
assertTrue(ex.desc =~ /hello\\\\nmars/);
}
}
}

testInjectedClass() {
Expand Down
21 changes: 19 additions & 2 deletions qlib/QUnit.qm
Expand Up @@ -14,7 +14,7 @@
%requires Util

module QUnit {
version = "0.3.2";
version = "0.3.3";
desc = "User module for unit testing with dependency injection support";
author = "Zdenek Behan <zdenek.behan@qoretechnologies.com>";
url = "http://qore.org";
Expand Down Expand Up @@ -130,6 +130,9 @@ public class MyTestClass inherits QUnit::DependencyInjectedTest {

@section unittest_relnotes Release Notes

@subsection qunit_v0_3_3 Version 0.3.3
- improved output in assertion failures for strings with special whitespace and for multi-line data structures (<a href="https://github.com/qorelanguage/qore/issues/2680">issue 2680</a>)

@subsection qunit_v0_3_2 Version 0.3.2
- improved error location reporting by providing all stack location information up until the QUnit call to cover the case when multiple code layers are used such as one or more test modules (<a href="https://github.com/qorelanguage/qore/issues/1720">issue 1720</a>)
- overloaded testAssertionValue supports auto/number/float
Expand Down Expand Up @@ -1080,8 +1083,22 @@ addTestCase(obj);
}

private string shorten(auto value) {
# issue #2680: convert special whitespace in strings to escaped chars
if (value.typeCode() == NT_STRING) {
value =~ s/\n/\n/g;
value =~ s/\r/\r/g;
value =~ s/\t/\t/g;
}
string v = sprintf("%N", value);
return sprintf("%s (%s)", v.split("\n")[0], value.type());
# issue #2680: when truncating complex data structures, indicate the truncation
list l = v.split("\n");
v = l[0];
if (l.size() > 1) {
return v + sprintf("...\" (%s truncated from %d lines)", value.type(), l.size());
}
else {
return sprintf("%s (%s)", v, value.type());
}
}

private compare(auto v1, auto v2, reference<list<string>> out, string path, *bool soft_comparisons) {
Expand Down

0 comments on commit 3d6bc37

Please sign in to comment.