Skip to content

Commit 0b45437

Browse files
committed
Adding warning on shadow variables for gcc / clang and starting to replace the tmpnam with c++ 17 features for our tests to remove the warnings
1 parent 9aec8b0 commit 0b45437

6 files changed

Lines changed: 30 additions & 15 deletions

File tree

.github/workflows/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
5858
- name: Build tests + lib
5959
working-directory: ${{runner.workspace}}
60-
run: cmake --build build
60+
run: cmake --build build --parallel `nproc`
6161

6262
- name: Run tests
6363
env:

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ endif()
6565

6666
list(APPEND GCC_CLANG_COMPILE_FLAGS
6767
-Wall -Wextra -Wpedantic
68-
-Wconversion -Wint-in-bool-context
68+
-Wconversion -Wint-in-bool-context -Wshadow
6969
-Wmissing-declarations -Wmissing-field-initializers
7070
-Werror
7171
)

test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ FetchContent_Declare(
1010
FetchContent_MakeAvailable(Catch2)
1111
include(Catch)
1212

13+
# Need filesystem for testing
14+
set(CMAKE_CXX_STANDARD 17)
15+
1316
if (MSVC)
1417
add_compile_options(/W4 /WX)
1518
else()

test/common.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "common.hpp"
22
#include "defines.hpp"
3+
#include <filesystem>
4+
#include <fstream>
5+
#include <iostream>
36

47
bool create_tmp_dbc_with(const char* filename, const char* content) {
58
auto* file = std::fopen(filename, "w");
@@ -12,3 +15,18 @@ bool create_tmp_dbc_with(const char* filename, const char* content) {
1215
std::fclose(file);
1316
return true;
1417
}
18+
19+
std::string create_temporary_dbc_with(const char* contents) {
20+
std::filesystem::path temp_dir = std::filesystem::temp_directory_path();
21+
22+
// Generate a unique temporary file name
23+
std::filesystem::path temp_file = temp_dir / "temp_file_XXXXXX"; // "XXXXXX" is a placeholder for a unique name
24+
25+
std::ofstream file(temp_file);
26+
if (file.is_open()) {
27+
file << contents << std::endl;
28+
file.close();
29+
}
30+
31+
return temp_file;
32+
}

test/common.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#ifndef COMMON_H
22
#define COMMON_H
33

4+
#include <string>
5+
46
bool create_tmp_dbc_with(const char* filename, const char* content);
7+
std::string create_temporary_dbc_with(const char* contents);
58

69
#endif // COMMON_H

test/test_dbc.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,13 @@ TEST_CASE("Testing dbc file loading", "[fileio]") {
6363
}
6464

6565
TEST_CASE("Testing big endian, little endian") {
66-
const auto* filename = std::tmpnam(NULL);
67-
68-
auto* file = std::fopen(filename, "w");
69-
CHECK(file);
70-
71-
std::fputs(PRIMITIVE_DBC.c_str(), file);
72-
// first big endian
73-
// second little endian
74-
std::fputs(R"(BO_ 234 MSG1: 8 Vector__XXX
66+
std::string dbc_contents = PRIMITIVE_DBC + R"(BO_ 234 MSG1: 8 Vector__XXX
7567
SG_ Sig1 : 55|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX
76-
SG_ Sig2 : 39|16@1- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX)",
77-
file);
78-
std::fclose(file);
68+
SG_ Sig2 : 39|16@1- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX)";
69+
const auto filename = create_temporary_dbc_with(dbc_contents.c_str());
7970

8071
auto parser = libdbc::DbcParser();
81-
parser.parse_file(filename);
72+
parser.parse_file(filename.c_str());
8273

8374
REQUIRE(parser.get_messages().size() == 1);
8475
REQUIRE(parser.get_messages().at(0).name() == "MSG1");

0 commit comments

Comments
 (0)