Skip to content

Commit

Permalink
c++/matching-brackets: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Sep 29, 2023
1 parent 2d32551 commit de5ecb1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 57 deletions.
19 changes: 7 additions & 12 deletions cpp/matching-brackets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,18 @@ endif()
# Use the common Catch library?
if(EXERCISM_COMMON_CATCH)
# For Exercism track development only
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp
$<TARGET_OBJECTS:catchlib>)
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp $<TARGET_OBJECTS:catchlib>)
elseif(EXERCISM_TEST_SUITE)
# The Exercism test suite is being run, the Docker image already includes a
# pre-built version of Catch.
# The Exercism test suite is being run, the Docker image already includes a pre-built version of Catch.
find_package(Catch2 REQUIRED)
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp)
target_link_libraries(${exercise} PRIVATE Catch2::Catch2WithMain)
# When Catch is installed system wide we need to include a different header,
# we need this define to use the correct one.
# When Catch is installed system wide we need to include a different header, we need this define to use the correct
# one.
target_compile_definitions(${exercise} PRIVATE EXERCISM_TEST_SUITE)
else()
# Build executable from sources and headers
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp
test/tests-main.cpp)
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp test/tests-main.cpp)
endif()

set_target_properties(
Expand All @@ -46,8 +43,7 @@ set_target_properties(
set(CMAKE_BUILD_TYPE Debug)

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
set_target_properties(
${exercise} PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Wpedantic -Werror")
set_target_properties(${exercise} PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Wpedantic -Werror")
endif()

# Configure to run all the tests?
Expand All @@ -57,8 +53,7 @@ endif()

# Tell MSVC not to warn us about unchecked iterators in debug builds
if(${MSVC})
set_target_properties(${exercise} PROPERTIES COMPILE_DEFINITIONS_DEBUG
_SCL_SECURE_NO_WARNINGS)
set_target_properties(${exercise} PROPERTIES COMPILE_DEFINITIONS_DEBUG _SCL_SECURE_NO_WARNINGS)
endif()

# Run the tests on every build
Expand Down
10 changes: 5 additions & 5 deletions cpp/matching-brackets/matching_brackets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ bool check(std::string text) {
}

bracket_stack.pop();
continue;
}
}

return bracket_stack.empty();
}

bool bracket_match(char open_bracket, char close_bracket) {
bool bracket_match(const char open_bracket, const char close_bracket) {
if (open_bracket == '[' and close_bracket == ']') {
return true;
}
Expand All @@ -51,15 +50,16 @@ bool bracket_match(char open_bracket, char close_bracket) {
return false;
}

bool bracket_open(char bracket) {
bool bracket_open(const char bracket) {
return bracket == '[' or bracket == '(' or bracket == '{';
}

bool bracket_close(char bracket) {
bool bracket_close(const char bracket) {
return bracket == ']' or bracket == ')' or bracket == '}';
}

bool bracket_either(char bracket) {
bool bracket_either(const char bracket) {
return bracket_open(bracket) or bracket_close(bracket);
}

} // namespace matching_brackets
2 changes: 1 addition & 1 deletion cpp/matching-brackets/matching_brackets.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>clang_version</key>
<string>Debian clang version 16.0.6 (++20230610113348+7cbf1a259152-1~exp1~20230610233446.99)</string>
<string>Debian clang version 16.0.6 (++20230710041823+7cbf1a259152-1~exp1~20230710161844.102)</string>
<key>diagnostics</key>
<array>
</array>
Expand Down
2 changes: 1 addition & 1 deletion cpp/matching-brackets/matching_brackets_test.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>clang_version</key>
<string>Debian clang version 16.0.6 (++20230610113348+7cbf1a259152-1~exp1~20230610233446.99)</string>
<string>Debian clang version 16.0.6 (++20230710041823+7cbf1a259152-1~exp1~20230710161844.102)</string>
<key>diagnostics</key>
<array>
</array>
Expand Down
80 changes: 42 additions & 38 deletions cpp/matching-brackets/run-tests-cpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Running automated test file(s):
Running: make clean
rm -rf ./build

real 0m0.017s
user 0m0.002s
sys 0m0.014s
real 0m0.013s
user 0m0.001s
sys 0m0.012s

===============================================================================

Expand Down Expand Up @@ -55,12 +55,16 @@ make[1]: Leaving directory '/home/vpayno/git_vpayno/exercism-workspace/cpp/match

=== All Tests Passed ===

find . -regextype posix-egrep -regex "^.*(tests-main|CompilerId).*[.](gcda|gcno)$" -print -delete
find . -regextype posix-egrep -regex '^.*(tests-main|CompilerId).*[.](gcda|gcno)$' -print -delete
./build/CMakeFiles/3.22.2/CompilerIdCXX/CMakeCXXCompilerId.gcno
./build/CMakeFiles/matching-brackets.dir/test/tests-main.cpp.gcno
./build/CMakeFiles/matching-brackets.dir/test/tests-main.cpp.gcda

find . -regextype posix-egrep -regex "^.*[.](gcda|gcno)16251"
find . -regextype posix-egrep -regex '^.*[.](gcda|gcno)$'
./build/CMakeFiles/matching-brackets.dir/matching_brackets_test.cpp.gcno
./build/CMakeFiles/matching-brackets.dir/matching_brackets.cpp.gcno
./build/CMakeFiles/matching-brackets.dir/matching_brackets.cpp.gcda
./build/CMakeFiles/matching-brackets.dir/matching_brackets_test.cpp.gcda

gcovr --print-summary
------------------------------------------------------------------------------
Expand All @@ -69,72 +73,72 @@ Directory: .
------------------------------------------------------------------------------
File Lines Exec Cover Missing
------------------------------------------------------------------------------
matching_brackets.cpp 31 31 100%
matching_brackets.cpp 30 30 100%
matching_brackets_test.cpp 34 34 100%
test/catch.hpp 34 29 85% 1642-1643,2301-2302,2560
------------------------------------------------------------------------------
TOTAL 99 94 94%
TOTAL 98 93 94%
------------------------------------------------------------------------------
lines: 94.9% (94 out of 99)
lines: 94.9% (93 out of 98)
branches: 46.0% (126 out of 274)

real 0m10.380s
user 0m9.457s
sys 0m0.918s
real 0m9.098s
user 0m8.428s
sys 0m0.590s

===============================================================================

cmake-format --in-place CMakeLists.txt
WARNING config_util.py:307: The following configuration options were ignored:
max_subargs_per_line

real 0m0.259s
user 0m0.149s
sys 0m0.113s
real 0m0.206s
user 0m0.118s
sys 0m0.074s

===============================================================================

cmake-lint CMakeLists.txt
WARNING The following configuration options were ignored:
max_subargs_per_line
CMakeLists.txt
==============
CMakeLists.txt:15,06: [C0103] Invalid directory variable name "exercise_cpp" doesn't match `[A-Z][0-9A-Z_]+|_[0-9a-z_]+`
CMakeLists.txt:17,06: [C0103] Invalid directory variable name "exercise_cpp" doesn't match `[A-Z][0-9A-Z_]+|_[0-9a-z_]+`
CMakeLists.txt:61,70: [C0307] Bad indentation:
)
^----BodyNode: 1:0->IfBlockNode: 59:0->BodyNode: 59:11->StatementNode: 60:2->TreeNode: 61:70

CMakeLists.txt:66,02: [C0113] Missing COMMENT in statement which allows it
CMakeLists.txt:61,02: [C0113] Missing COMMENT in statement which allows it

Summary
=======
files scanned: 1
found lint:
Convention: 4
Convention: 3


real 0m0.221s
user 0m0.140s
sys 0m0.083s
real 0m0.193s
user 0m0.135s
sys 0m0.050s

===============================================================================

Running: clang-format-16 -style=file -i ./matching_brackets.cpp ./matching_brackets_test.cpp ./matching_brackets.hpp

real 0m0.021s
user 0m0.012s
real 0m0.018s
user 0m0.009s
sys 0m0.009s

===============================================================================

Running: ../../.github/citools/cpp/clang-check
clang-check-16 --analyze ./matching_brackets.cpp ./matching_brackets_test.cpp ./matching_brackets.hpp
Running: clang-check-16 --analyze ./matching_brackets.cpp ./matching_brackets_test.cpp ./matching_brackets.hpp

real 0m0.683s
user 0m0.639s
sys 0m0.043s
real 0m0.609s
user 0m0.572s
sys 0m0.037s


real 0m0.685s
user 0m0.640s
sys 0m0.045s
real 0m0.611s
user 0m0.573s
sys 0m0.038s

===============================================================================

Expand All @@ -145,15 +149,15 @@ Running: ../../.github/citools/cpp/clang-tidy | head -n 100
Suppressed 62141 warnings (62136 in non-user code, 5 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

real 0m8.435s
user 0m8.351s
sys 0m0.082s
real 0m7.621s
user 0m7.544s
sys 0m0.075s
Running: clang-tidy-16 ./matching_brackets.cpp ./matching_brackets_test.cpp ./matching_brackets.hpp


real 0m8.437s
user 0m8.352s
sys 0m0.085s
real 0m7.623s
user 0m7.546s
sys 0m0.077s

===============================================================================

0 comments on commit de5ecb1

Please sign in to comment.