Skip to content

Commit

Permalink
Codecoverage appveyor (agauniyal#75)
Browse files Browse the repository at this point in the history
* Add opencppcoverage to appveyor.yml

* Add tests for winTerm::Ansi and winTerm::Native

* Upgrade tests
  • Loading branch information
tkhurana96 authored and agauniyal committed Jan 20, 2018
1 parent 9dd62ba commit ac370f3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
8 changes: 6 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ install:

- cmd: set OPENCPPPATH="C:\\Program Files\\OpenCppCoverage"
- cmd: set PATH=C:\glib\bin\;C:\gettext\bin\;C:\pkg_config\bin\;%OPENCPPPATH%;%PATH%
- cmd: python -m pip install meson conan
- cmd: python -m pip install meson conan codecov

- cmd: if %compiler%==msvc2015 ( call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %arch% )
- cmd: if %compiler%==msvc2017 ( if %arch%==x64 ( call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"))
- cmd: conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan


build_script:
- cmd: echo Building on %arch% with %compiler%
- cmd: mkdir build && cd build
- cmd: conan install ..
- cmd: conan build ..
Expand All @@ -48,3 +47,8 @@ build_script:
- cmd: visualTest.exe
- cmd: mainTest.exe
- cmd: colorTest.exe
- cmd: OpenCppCoverage --sources C:\projects\rang --export_type=binary:visualTestReport.bin -- visualTest.exe
- cmd: OpenCppCoverage --sources C:\projects\rang --export_type=binary:mainTestReport.bin -- mainTest.exe
- cmd: OpenCppCoverage --sources C:\projects\rang --export_type=binary:colorTestReport.bin -- colorTest.exe
- cmd: OpenCppCoverage --sources C:\projects\rang --export_type=cobertura:overallReport.xml --input_coverage=mainTestReport.bin --input_coverage=visualTestReport.bin --input_coverage=colorTestReport.bin
- cmd: codecov --root ../.. --no-color --disable gcov -f overallReport.xml
13 changes: 8 additions & 5 deletions include/rang.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,18 +441,21 @@ namespace rang_implementation {
{
if (isTerminal(os.rdbuf())) {
if (winTermMode() == winTerm::Auto) {
if (supportsAnsi(os.rdbuf()))
if (supportsAnsi(os.rdbuf())) {
setWinColorAnsi(os, value);
else
} else {
setWinColorNative(os, value);
} else if (winTermMode() == winTerm::Ansi)
}
} else if (winTermMode() == winTerm::Ansi) {
setWinColorAnsi(os, value);
else
} else {
setWinColorNative(os, value);
}
} else {
// force ANSI output to non terminal streams if set
if (controlMode() == control::forceColor)
if (controlMode() == control::forceColor) {
setWinColorAnsi(os, value);
}
}
return os;
}
Expand Down
23 changes: 21 additions & 2 deletions test/colorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
using namespace std;
using namespace rang;

int main()
void test_colors(const winTerm opt)
{
rang::setControlMode(control::forceColor); // For appveyor terminal
setWinTermMode(opt);

// Visual test for background colors
cout << bg::green << "This text has green background." << bg::reset << endl
<< bg::red << "This text has red background." << bg::reset << endl
Expand Down Expand Up @@ -81,3 +82,21 @@ int main()
<< style::conceal << "This text is concealed." << style::reset << endl
<< style::crossed << "This text is crossed." << style::reset << endl;
}

int main()
{
setControlMode(control::autoColor);
test_colors(winTerm::Auto);
test_colors(winTerm::Ansi);
test_colors(winTerm::Native);

setControlMode(control::forceColor);
test_colors(winTerm::Auto);
test_colors(winTerm::Ansi);
test_colors(winTerm::Native);

setControlMode(control::offColor);
test_colors(winTerm::Auto);
test_colors(winTerm::Ansi);
test_colors(winTerm::Native);
}
7 changes: 1 addition & 6 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
using namespace std;
using namespace rang;

/*
The control::forceColor is used to write to terminal here in order to work
with appveyor terminal
*/

TEST_CASE("Rang printing to non-terminals")
{
const string s = "Hello World";
Expand Down Expand Up @@ -71,7 +66,7 @@ TEST_CASE("Rang printing to stdout/err")

SUBCASE("output is to terminal")
{
rang::setControlMode(control::forceColor);
setControlMode(control::forceColor);
cout << fg::green << s << "cout" << style::reset << endl;
clog << fg::blue << s << "clog" << style::reset << endl;
cerr << fg::red << s << "cerr" << style::reset << endl;
Expand Down
2 changes: 1 addition & 1 deletion test/visualTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using namespace rang;

int main()
{
rang::setControlMode(control::forceColor); // For appveyor terminal
setControlMode(control::forceColor); // For appveyor terminal
cout << endl
<< style::reset << bg::green << fg::gray
<< "If you're seeing green background, then rang works!"
Expand Down

0 comments on commit ac370f3

Please sign in to comment.