Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: run cctests as part of test-ci target #8034

Merged
merged 3 commits into from
Oct 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ test-ci-js:
$(TEST_CI_ARGS) $(CI_JS_SUITES)

test-ci: | build-addons
out/Release/cctest --gtest_output=tap:cctest.tap
$(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \
--mode=release --flaky-tests=$(FLAKY_TESTS) \
$(TEST_CI_ARGS) $(CI_NATIVE_SUITES) $(CI_JS_SUITES)
Expand Down
124 changes: 123 additions & 1 deletion deps/gtest/src/gtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3498,6 +3498,125 @@ std::string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(
// </testsuite>
// </testsuites>

class TapUnitTestResultPrinter : public EmptyTestEventListener {
public:
TapUnitTestResultPrinter();
explicit TapUnitTestResultPrinter(const char* output_file);
virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);

private:
static void PrintTapUnitTest(::std::ostream* stream,
const UnitTest& unit_test);
static void PrintTapTestCase(int* count,
::std::ostream* stream,
const TestCase& test_case);
static void OutputTapTestInfo(int* count,
::std::ostream* stream,
const char* test_case_name,
const TestInfo& test_info);
static void OutputTapComment(::std::ostream* stream, const char* comment);

const std::string output_file_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(TapUnitTestResultPrinter);
};

TapUnitTestResultPrinter::TapUnitTestResultPrinter() {}

TapUnitTestResultPrinter::TapUnitTestResultPrinter(const char* output_file)
: output_file_(output_file) {
if (output_file_.c_str() == NULL || output_file_.empty()) {
fprintf(stderr, "TAP output file may not be null\n");
fflush(stderr);
exit(EXIT_FAILURE);
}
}

void TapUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
int /*iteration*/) {
FILE* tapout = stdout;

if (!output_file_.empty()) {
FilePath output_file(output_file_);
FilePath output_dir(output_file.RemoveFileName());

tapout = NULL;
if (output_dir.CreateDirectoriesRecursively())
tapout = posix::FOpen(output_file_.c_str(), "w");

if (tapout == NULL) {
fprintf(stderr, "Unable to open file \"%s\"\n", output_file_.c_str());
fflush(stderr);
exit(EXIT_FAILURE);
}
}

std::stringstream stream;
PrintTapUnitTest(&stream, unit_test);
fprintf(tapout, "%s", StringStreamToString(&stream).c_str());
fflush(tapout);

if (tapout != stdout)
fclose(tapout);
}

void TapUnitTestResultPrinter::PrintTapUnitTest(std::ostream* stream,
const UnitTest& unit_test) {
*stream << "TAP version 13\n";
*stream << "1.." << unit_test.reportable_test_count() << "\n";

int count = 1;
for (int i = 0; i < unit_test.total_test_case_count(); ++i) {
const TestCase& test_case = *unit_test.GetTestCase(i);
if (test_case.reportable_test_count() > 0)
PrintTapTestCase(&count, stream, test_case);
}

*stream << "# failures: " << unit_test.failed_test_count() << "\n";
}

void TapUnitTestResultPrinter::PrintTapTestCase(int* count,
std::ostream* stream,
const TestCase& test_case) {
for (int i = 0; i < test_case.total_test_count(); ++i) {
const TestInfo& test_info = *test_case.GetTestInfo(i);
if (test_info.is_reportable())
OutputTapTestInfo(count, stream, test_case.name(), test_info);
}
}

void TapUnitTestResultPrinter::OutputTapTestInfo(int* count,
::std::ostream* stream,
const char* test_case_name,
const TestInfo& test_info) {
const TestResult& result = *test_info.result();
const char* status = result.Passed() ? "ok" : "not ok";

*stream << status << " " << *count << " - " <<
test_case_name << "." << test_info.name() << "\n";
*stream << " ---\n";
*stream << " duration_ms: " <<
FormatTimeInMillisAsSeconds(result.elapsed_time()) << "\n";
*stream << " ...\n";

for (int i = 0; i < result.total_part_count(); ++i) {
const TestPartResult& part = result.GetTestPartResult(i);
OutputTapComment(stream, part.message());
}

*count += 1;
}

void TapUnitTestResultPrinter::OutputTapComment(::std::ostream* stream,
const char* comment) {
const char* start = comment;
while (const char* end = strchr(start, '\n')) {
*stream << "# " << std::string(start, end) << "\n";
start = end + 1;
}
if (*start)
*stream << "# " << start << "\n";
}

// Formats the given time in milliseconds as seconds.
std::string FormatTimeInMillisAsSeconds(TimeInMillis ms) {
::std::stringstream ss;
Expand Down Expand Up @@ -4314,7 +4433,7 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent)
#endif
// Will be overridden by the flag before first use.
catch_exceptions_(false) {
listeners()->SetDefaultResultPrinter(new PrettyUnitTestResultPrinter);
listeners()->SetDefaultResultPrinter(new TapUnitTestResultPrinter);
}

UnitTestImpl::~UnitTestImpl() {
Expand Down Expand Up @@ -4365,6 +4484,9 @@ void UnitTestImpl::ConfigureXmlOutput() {
if (output_format == "xml") {
listeners()->SetDefaultXmlGenerator(new XmlUnitTestResultPrinter(
UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
} else if (output_format == "tap") {
listeners()->SetDefaultXmlGenerator(new TapUnitTestResultPrinter(
UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
} else if (output_format != "") {
printf("WARNING: unrecognized output format \"%s\" ignored.\n",
output_format.c_str());
Expand Down
1 change: 0 additions & 1 deletion deps/gtest/src/gtest_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "gtest/gtest.h"

GTEST_API_ int main(int argc, char **argv) {
printf("Running main() from gtest_main.cc\n");
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
6 changes: 3 additions & 3 deletions test/cctest/test_inspector_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static void check_data_cb(read_expects* expectation, ssize_t nread,
c = expectation->expected[expectation->pos++];
actual = buf->base[i];
if (c != actual) {
fprintf(stderr, "Unexpected character at position %ld\n",
fprintf(stderr, "Unexpected character at position %zd\n",
expectation->pos - 1);
GTEST_ASSERT_EQ(c, actual);
}
Expand Down Expand Up @@ -171,7 +171,7 @@ static void fail_callback(uv_stream_t* stream, ssize_t nread,
if (nread < 0) {
fprintf(stderr, "IO error: %s\n", uv_strerror(nread));
} else {
fprintf(stderr, "Read %ld bytes\n", nread);
fprintf(stderr, "Read %zd bytes\n", nread);
}
ASSERT_TRUE(false); // Shouldn't have been called
}
Expand Down Expand Up @@ -262,7 +262,7 @@ static void expect_on_server(const char* data, size_t len) {
char actual = expects->actual_data[expects->actual_offset++];
char expected = data[i];
if (expected != actual) {
fprintf(stderr, "Character %ld:\n", i);
fprintf(stderr, "Character %zu:\n", i);
GTEST_ASSERT_EQ(expected, actual);
}
}
Expand Down
7 changes: 4 additions & 3 deletions vcbuild.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set noprojgen=
set nobuild=
set nosign=
set nosnapshot=
set cctest_args=
set test_args=
set package=
set msi=
Expand Down Expand Up @@ -56,7 +57,7 @@ if /i "%1"=="noetw" set noetw=1&goto arg-ok
if /i "%1"=="noperfctr" set noperfctr=1&goto arg-ok
if /i "%1"=="licensertf" set licensertf=1&goto arg-ok
if /i "%1"=="test" set test_args=%test_args% addons doctool known_issues message parallel sequential -J&set jslint=1&set build_addons=1&goto arg-ok
if /i "%1"=="test-ci" set test_args=%test_args% %test_ci_args% -p tap --logfile test.tap addons doctool inspector known_issues message sequential parallel&set build_addons=1&goto arg-ok
if /i "%1"=="test-ci" set test_args=%test_args% %test_ci_args% -p tap --logfile test.tap addons doctool inspector known_issues message sequential parallel&set cctest_args=%cctest_args% --gtest_output=tap:cctest.tap&set build_addons=1&goto arg-ok
if /i "%1"=="test-addons" set test_args=%test_args% addons&set build_addons=1&goto arg-ok
if /i "%1"=="test-simple" set test_args=%test_args% sequential parallel -J&goto arg-ok
if /i "%1"=="test-message" set test_args=%test_args% message&goto arg-ok
Expand Down Expand Up @@ -333,8 +334,8 @@ goto run-tests
if "%test_args%"=="" goto jslint
if "%config%"=="Debug" set test_args=--mode=debug %test_args%
if "%config%"=="Release" set test_args=--mode=release %test_args%
echo running 'cctest'
"%config%\cctest"
echo running 'cctest %cctest_args%'
"%config%\cctest" %cctest_args%
echo running 'python tools\test.py %test_args%'
python tools\test.py %test_args%
goto jslint
Expand Down