Skip to content
This repository has been archived by the owner on Dec 21, 2020. It is now read-only.

Commit

Permalink
TW-1936: Tweak tests to have fuller TAP compliance
Browse files Browse the repository at this point in the history
- Thanks to Paul J. Fenwick.
  • Loading branch information
pbeckingham committed Dec 10, 2017
1 parent 5b67a49 commit 3caa7db
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 41 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The following submitted code, packages or analysis, and deserve special thanks:

Jörg Krause
Ben Boeckel
Paul J. Fenwick

Thanks to the following, who submitted detailed bug reports and excellent
suggestions:
Expand Down
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
(Thanks to Jörg Krause, Ben Boeckel).
- TW-1845 Cygwin build fails, missing get_current_dir_name
(thanks to hosaka).
- TW-1936 Tweak tests to have fuller TAP compliance
(thanks to Paul J. Fenwick)
- Added libshared.git as a submodule.
- Rewritten to address performance, security and functionality.
- Added summary report.
Expand Down
45 changes: 30 additions & 15 deletions test/problems
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ if __name__ == "__main__":

file = re.compile("^# (?:./)?(\S+\.t)(?:\.exe)?$")
timestamp = re.compile("^# (\d+(?:\.\d+)?) ==>.*$")

expected_fail = re.compile(r"^not ok.*?#\s*TODO", re.I)
unexpected_pass = re.compile(r"^ok .*?#\s*TODO", re.I)
skip = re.compile(r"^ok .*?#\s*skip", re.I)
ok = re.compile(r"^ok ", re.I)
not_ok = re.compile(r"^not ok", re.I)
comment = re.compile(r"^#")
plan = re.compile(r"^1..\d+\s*(?:#.*)?$")

start = None
stop = None

Expand All @@ -68,31 +77,37 @@ if __name__ == "__main__":
if match:
filename = match.group(1)

if line.startswith("ok "):
elif expected_fail.match(line):
expected[filename] += 1

elif unexpected_pass.match(line):
unexpected[filename] += 1

elif skip.match(line):
skipped[filename] += 1

# It's important these come last, since they're subpatterns of the above

elif ok.match(line):
passed[filename] += 1

if line.startswith("not "):
elif not_ok.match(line):
errors[filename] += 1

if line.startswith("skip "):
skipped[filename] += 1
elif comment.match(line):
pass

if line.startswith("# EXPECTED_FAILURE:"):
expected[filename] += 1
elif plan.match(line):
pass

if line.startswith("# UNEXPECTED_SUCCESS:"):
unexpected[filename] += 1
else:
# Uncomment if you want to see malformed things we caught as well...
# print(color("Malformed TAP (" + filename + "): " + line, "red"))
pass

# Last line contains the ending timestamp
stop = float(timestamp.match(line).group(1))

# Remove expected failures from the skipped tests category
for filename, value in expected.items():
if skipped[filename] == value:
del skipped[filename]
else:
skipped[filename] -= value

v = "{0:>5d}"
passed_str = "Passed:" + pad(24)
passed_int = v.format(sum(passed.values()))
Expand Down
53 changes: 27 additions & 26 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ UnitTest::UnitTest (int planned)
, _failed (0)
, _skipped (0)
{
std::cout << "1.." << _planned << "\n";
std::cout << "1.." << _planned << '\n';
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -99,14 +99,14 @@ void UnitTest::plan (int planned)
_failed = 0;
_skipped = 0;

std::cout << "1.." << _planned << "\n";
std::cout << "1.." << _planned << '\n';
}

///////////////////////////////////////////////////////////////////////////////
void UnitTest::planMore (int extra)
{
_planned += extra;
std::cout << "1.." << _planned << "\n";
std::cout << "1.." << _planned << '\n';
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -122,7 +122,7 @@ void UnitTest::ok (bool expression, const std::string& name)
<< _counter
<< " - "
<< name
<< "\n";
<< '\n';
}
else
{
Expand All @@ -132,7 +132,7 @@ void UnitTest::ok (bool expression, const std::string& name)
<< _counter
<< " - "
<< name
<< "\n";
<< '\n';
}
}

Expand All @@ -149,7 +149,7 @@ void UnitTest::notok (bool expression, const std::string& name)
<< _counter
<< " - "
<< name
<< "\n";
<< '\n';
}
else
{
Expand All @@ -159,7 +159,7 @@ void UnitTest::notok (bool expression, const std::string& name)
<< _counter
<< " - "
<< name
<< "\n";
<< '\n';
}
}

Expand All @@ -175,7 +175,7 @@ void UnitTest::is (bool actual, bool expected, const std::string& name)
<< _counter
<< " - "
<< name
<< "\n";
<< '\n';
}
else
{
Expand All @@ -189,7 +189,7 @@ void UnitTest::is (bool actual, bool expected, const std::string& name)
<< expected
<< "\n# got: "
<< actual
<< "\n";
<< '\n';
}
}

Expand All @@ -205,7 +205,7 @@ void UnitTest::is (size_t actual, size_t expected, const std::string& name)
<< _counter
<< " - "
<< name
<< "\n";
<< '\n';
}
else
{
Expand All @@ -219,7 +219,7 @@ void UnitTest::is (size_t actual, size_t expected, const std::string& name)
<< expected
<< "\n# got: "
<< actual
<< "\n";
<< '\n';
}
}

Expand All @@ -235,7 +235,7 @@ void UnitTest::is (int actual, int expected, const std::string& name)
<< _counter
<< " - "
<< name
<< "\n";
<< '\n';
}
else
{
Expand All @@ -249,7 +249,7 @@ void UnitTest::is (int actual, int expected, const std::string& name)
<< expected
<< "\n# got: "
<< actual
<< "\n";
<< '\n';
}
}

Expand All @@ -265,7 +265,7 @@ void UnitTest::is (double actual, double expected, const std::string& name)
<< _counter
<< " - "
<< name
<< "\n";
<< '\n';
}
else
{
Expand All @@ -279,7 +279,7 @@ void UnitTest::is (double actual, double expected, const std::string& name)
<< expected
<< "\n# got: "
<< actual
<< "\n";
<< '\n';
}
}

Expand All @@ -295,7 +295,7 @@ void UnitTest::is (double actual, double expected, double tolerance, const std::
<< _counter
<< " - "
<< name
<< "\n";
<< '\n';
}
else
{
Expand All @@ -309,7 +309,7 @@ void UnitTest::is (double actual, double expected, double tolerance, const std::
<< expected
<< "\n# got: "
<< actual
<< "\n";
<< '\n';
}
}

Expand All @@ -325,7 +325,7 @@ void UnitTest::is (unsigned char actual, unsigned char expected, const std::stri
<< _counter
<< " - "
<< name
<< "\n";
<< '\n';
}
else
{
Expand All @@ -339,7 +339,7 @@ void UnitTest::is (unsigned char actual, unsigned char expected, const std::stri
<< expected
<< "\n# got: "
<< actual
<< "\n";
<< '\n';
}
}

Expand All @@ -358,7 +358,7 @@ void UnitTest::is (
<< _counter
<< " - "
<< name
<< "\n";
<< '\n';
}
else
{
Expand Down Expand Up @@ -392,7 +392,7 @@ void UnitTest::is (
<< _counter
<< " - "
<< name
<< "\n";
<< '\n';
}
else
{
Expand All @@ -418,7 +418,7 @@ void UnitTest::diag (const std::string& text)
auto end = text.find_last_not_of (" \t\n\r\f");
if (start != std::string::npos &&
end != std::string::npos)
std::cout << "# " << text.substr (start, end - start + 1) << "\n";
std::cout << "# " << text.substr (start, end - start + 1) << '\n';
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -431,7 +431,7 @@ void UnitTest::pass (const std::string& text)
<< _counter
<< " - "
<< text
<< "\n";
<< '\n';
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -444,20 +444,21 @@ void UnitTest::fail (const std::string& text)
<< _counter
<< " - "
<< text
<< "\n";
<< '\n';
}

///////////////////////////////////////////////////////////////////////////////
void UnitTest::skip (const std::string& text)
{
++_counter;
++_skipped;
std::cout << yellow ("skip")
std::cout << yellow ("ok")
<< " "
<< _counter
<< " - "
<< text
<< "\n";
<< " # skip"
<< '\n';
}

///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 3caa7db

Please sign in to comment.