Skip to content
Open
22 changes: 13 additions & 9 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ jobs:
brew install gnuplot
- name: Install Gnuplot for Windows
if: runner.os == 'Windows'
run: choco install gnuplot
run: |
choco install gnuplot
Add-Content $env:GITHUB_PATH "C:\Program Files\gnuplot\bin"

- name: Check Gnuplot version
run: gnuplot --version

# Setup the build machine with the most recent versions of CMake and Ninja. Both are cached if not already: on subsequent runs both will be quickly restored from GitHub cache service.
- uses: lukka/get-cmake@latest
Expand All @@ -53,16 +58,15 @@ jobs:
# Run CMake to generate project files
- name: Generate project files
run: |
cmake -B "${{ env.CMAKE_BUILD_DIR }}"
mkdir build
cd build
cmake -B ..
# Build the whole project
- name: Build
working-directory: "${{ env.CMAKE_BUILD_DIR }}/build"
run: |
cmake --build "${{ env.CMAKE_BUILD_DIR }}"
cmake --build .
# Run the tests
- name: Run tests
if: runner.os != 'Windows' # On Windows, Chocolatey does not add Gnuplot to PATH
working-directory: "${{ env.CMAKE_BUILD_DIR }}"
run: ctest -C Debug --output-on-failure
- name: Show content of workspace at its completion
run: find $RUNNER_WORKSPACE
shell: bash
working-directory: "${{ env.CMAKE_BUILD_DIR }}/build"
run: ctest -C Debug --build-and-test --output-on-failure
19 changes: 4 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,6 @@ project(gplotpp
LANGUAGES CXX
)

enable_testing()

add_test(NAME run_tests
COMMAND run_tests
)

add_executable(run_tests
tests/run_tests.cpp
)

target_include_directories(run_tests PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)

add_executable(example-3d
example-3d.cpp
)
Expand Down Expand Up @@ -67,3 +52,7 @@ add_executable(example-vec3d
add_executable(example-dumb
example-dumb.cpp
)

enable_testing ()

add_subdirectory (tests)
22 changes: 13 additions & 9 deletions gplot++.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Gnuplot {

// See
// https://stackoverflow.com/questions/28152719/how-to-make-gnuplot-use-the-unicode-minus-sign-for-negative-numbers
sendcommand("set encoding utf8\n");
sendcommand("set encoding utf8");
sendcommand("set minussign");
}

Expand Down Expand Up @@ -184,8 +184,12 @@ class Gnuplot {
if (!ok())
return false;

fputs(str, connection);
fputc('\n', connection);
std::stringstream os;

// We need to use "std::endl" here, because it might either be
// a LR or a CRLF
os << str << std::endl;
fputs(os.str().c_str(), connection);
fflush(connection);

return true;
Expand All @@ -203,7 +207,7 @@ class Gnuplot {
const std::string &size = "800,600") {
std::stringstream os;

os << "set terminal pngcairo color enhanced size " << size << "\n"
os << "set terminal pngcairo color enhanced size " << size << std::endl
<< "set output '" << filename << "'\n";
return sendcommand(os);
}
Expand All @@ -213,7 +217,7 @@ class Gnuplot {
std::string size = "16cm,12cm") {
std::stringstream os;

os << "set terminal pdfcairo color enhanced size " << size << "\n"
os << "set terminal pdfcairo color enhanced size " << size << std::endl
<< "set output '" << filename << "'\n";
return sendcommand(os);
}
Expand All @@ -223,7 +227,7 @@ class Gnuplot {
const std::string &size = "800,600") {
std::stringstream os;

os << "set terminal svg enhanced mouse standalone size " << size << "\n"
os << "set terminal svg enhanced mouse standalone size " << size << std::endl
<< "set output '" << filename << "'\n";
return sendcommand(os);
}
Expand All @@ -245,7 +249,7 @@ class Gnuplot {
default: os << "mono";
}

os << "\n";
os << std::endl;

if (! filename.empty()) {
os << "set output '" << filename << "'\n";
Expand Down Expand Up @@ -377,7 +381,7 @@ class Gnuplot {

std::stringstream of;
for (size_t i{}; i < nbins; ++i) {
of << min + binwidth * (i + 0.5) << " " << bins[i] << "\n";
of << min + binwidth * (i + 0.5) << " " << bins[i] << std::endl;
}

series.push_back(GnuplotSeries{of.str(), style, label, "1:2"});
Expand Down Expand Up @@ -471,7 +475,7 @@ class Gnuplot {
std::stringstream fmtstring;
for (size_t i{}; i < v.size(); ++i) {
_print_ith_elements(of, fmtstring, 1, i, v, args...);
of << "\n";
of << std::endl;
}

series.push_back(GnuplotSeries{of.str(), style, label, fmtstring.str()});
Expand Down
19 changes: 19 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set (TARGET "${PROJECT_NAME}-test" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wmissing-include-dirs -Wfloat-equal -Wshadow")
set (TARGET "${PROJECT_NAME}-test" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Weffc++ -Woverloaded-virtual -Wsign-promo")
set (TARGET "${PROJECT_NAME}-test" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvla -Winvalid-pch -Winline -Wredundant-decls -Wcast-align")
set (TARGET "${PROJECT_NAME}-test" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual -Wpointer-arith -Wold-style-cast")

add_executable (run_tests
run_tests.cpp
)

target_include_directories (run_tests PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)

enable_testing ()

add_test (NAME run_tests
COMMAND run_tests
)