Skip to content

Commit

Permalink
Improve tests, Add cppcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
agauniyal committed Jan 21, 2018
1 parent ac370f3 commit 20458d8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ before_script:
- cd ..

script:
- cd release && ./test/visualTest && ./test/mainTest && ./test/colorTest && cd ..
- cd release && ./test/visualTest && ./test/mainTest && ./test/colorTest && ./test/envTermMissing
- ninja cppcheck && cd ..

after_success:
- cd debug && ./test/visualTest && ./test/mainTest && ./test/colorTest
- cd debug && ./test/visualTest && ./test/mainTest && ./test/colorTest && ./test/envTermMissing
- bash <(curl -s https://codecov.io/bash)
- cd .. && cd release-sanitize && ./test/visualTest && ./test/mainTest && ./test/colorTest && cd ..
- cd .. && cd release-sanitize && ./test/visualTest && ./test/mainTest && ./test/colorTest && ./test/envTermMissing

notifications:
email: false
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ build_script:
- cmd: visualTest.exe
- cmd: mainTest.exe
- cmd: colorTest.exe
- cmd: envTermMissing.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
Expand Down
17 changes: 9 additions & 8 deletions test/colorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,21 @@ void test_colors(const winTerm opt)
<< style::crossed << "This text is crossed." << style::reset << endl;
}

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

int main()
{
setControlMode(control::autoColor);
enumerateWinTerms();

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

setControlMode(control::offColor);
test_colors(winTerm::Auto);
test_colors(winTerm::Ansi);
test_colors(winTerm::Native);
enumerateWinTerms();
}
24 changes: 24 additions & 0 deletions test/envTermMissing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "rang.hpp"
#include <cstdlib>

using std::cout;
using std::endl;
using std::getenv;

int main()
{
#if defined(WIN32) || defined(_WIN32) || defined(_WIN64)
return 0;
#else
const auto TERM = getenv("TERM");
if (TERM != nullptr) {
cout << "Unsetting $PATH: " << TERM << '\n';
unsetenv("TERM");
}
cout << rang::fg::green << "No colors as fallback" << endl;
if (TERM != nullptr) {
cout << "Setting $PATH: " << TERM << '\n';
setenv("TERM", TERM, 1);
}
#endif
}
3 changes: 3 additions & 0 deletions test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ test('colorTest', colorTest)

visualTest = executable('visualTest', 'visualTest.cpp', include_directories : inc)
test('visualTest', visualTest)

envTermMissing = executable('envTermMissing', 'envTermMissing.cpp', include_directories : inc)
test('envTermMissing', envTermMissing)
18 changes: 0 additions & 18 deletions test/test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#if defined(__MINGW32__) || defined(__MINGW64__)
#define _WIN32_WINNT 0x0600
#endif

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"

Expand Down Expand Up @@ -59,17 +55,3 @@ TEST_CASE("Rang printing to non-terminals")
REQUIRE(s.size() < output.size());
}
}

TEST_CASE("Rang printing to stdout/err")
{
const string s = "Rang works with ";

SUBCASE("output is to terminal")
{
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;
REQUIRE(1 == 1);
}
}

0 comments on commit 20458d8

Please sign in to comment.