Skip to content

Commit

Permalink
c++/reverse-string: 2nd iteration - c header -> c++ header
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Jul 17, 2023
1 parent 9440c6a commit 715272f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 69 deletions.
6 changes: 3 additions & 3 deletions cpp/reverse-string/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ endif()
# Use the common Catch library?
if(EXERCISM_COMMON_CATCH)
# For Exercism track development only
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h
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.
find_package(Catch2 REQUIRED)
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)
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.
target_compile_definitions(${exercise} PRIVATE EXERCISM_TEST_SUITE)
else()
# Build executable from sources and headers
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp
test/tests-main.cpp)
endif()

Expand Down
6 changes: 2 additions & 4 deletions cpp/reverse-string/reverse_string.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include "reverse_string.h"

#include <iterator>
#include <string>
#include "reverse_string.hpp"

namespace reverse_string {

std::string reverse_string(std::string text) {

std::string reversed;

if (text.empty()) {
Expand Down
15 changes: 0 additions & 15 deletions cpp/reverse-string/reverse_string.h

This file was deleted.

13 changes: 13 additions & 0 deletions cpp/reverse-string/reverse_string.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#if !defined(REVERSE_STRING_HPP)
#define REVERSE_STRING_HPP

#include <iterator>
#include <string>

namespace reverse_string {

std::string reverse_string(std::string text);

} // namespace reverse_string

#endif // REVERSE_STRING_HPP
2 changes: 1 addition & 1 deletion cpp/reverse-string/reverse_string_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "reverse_string.h"
#include "reverse_string.hpp"
#ifdef EXERCISM_TEST_SUITE
#include <catch2/catch.hpp>
#else
Expand Down
78 changes: 32 additions & 46 deletions cpp/reverse-string/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.014s
user 0m0.002s
sys 0m0.012s
real 0m0.016s
user 0m0.006s
sys 0m0.010s

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

Expand Down Expand Up @@ -78,17 +78,17 @@ TOTAL 55 48 87%
lines: 87.3% (48 out of 55)
branches: 37.7% (40 out of 106)

real 0m10.027s
user 0m9.203s
sys 0m0.814s
real 0m10.882s
user 0m10.102s
sys 0m0.761s

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

cmake-format --in-place CMakeLists.txt

real 0m0.154s
user 0m0.112s
sys 0m0.042s
real 0m0.175s
user 0m0.119s
sys 0m0.055s

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

Expand All @@ -111,58 +111,44 @@ found lint:


real 0m0.165s
user 0m0.120s
sys 0m0.046s
user 0m0.117s
sys 0m0.045s

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

Running: clang-format-16 -style=file -i ./reverse_string.cpp ./reverse_string_test.cpp ./reverse_string.h
Running: clang-format-16 -style=file -i ./reverse_string.cpp ./reverse_string_test.cpp

real 0m0.020s
user 0m0.013s
sys 0m0.007s
real 0m0.028s
user 0m0.009s
sys 0m0.019s

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

Running: ../../.github/citools/cpp/clang-check
clang-check-16 --analyze ./reverse_string.cpp ./reverse_string_test.cpp ./reverse_string.h
error: argument unused during compilation: '-stdlib=libstdc++' [-Werror,-Wunused-command-line-argument]
error: invalid argument '-std=c++17' not allowed with 'C'
/home/vpayno/git_vpayno/exercism-workspace/cpp/reverse-string/reverse_string.h:6:10: fatal error: 'iterator' file not found
#include <iterator>
^~~~~~~~~~
1 error generated.
Error while processing /home/vpayno/git_vpayno/exercism-workspace/cpp/reverse-string/reverse_string.h.
clang-check-16 --analyze ./reverse_string.cpp ./reverse_string_test.cpp ./reverse_string.hpp

real 0m0.534s
user 0m0.495s
sys 0m0.039s
real 0m0.738s
user 0m0.693s
sys 0m0.043s


real 0m0.536s
user 0m0.497s
sys 0m0.039s
real 0m0.740s
user 0m0.695s
sys 0m0.043s

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

Running: ../../.github/citools/cpp/clang-tidy | head -n 100
12523 warnings generated.
47957 warnings generated.
47957 warnings and 3 errors generated.
Error while processing /home/vpayno/git_vpayno/exercism-workspace/cpp/reverse-string/reverse_string.h.
Suppressed 47960 warnings (47955 in non-user code, 5 NOLINT).
60471 warnings generated.
Suppressed 60474 warnings (60469 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.
Found compiler error(s).

real 0m6.967s
user 0m6.889s
sys 0m0.077s
Running: clang-tidy-16 ./reverse_string.cpp ./reverse_string_test.cpp ./reverse_string.h
error: invalid argument '-std=c++17' not allowed with 'C' [clang-diagnostic-error]
error: argument unused during compilation: '-stdlib=libstdc++' [clang-diagnostic-unused-command-line-argument]
/home/vpayno/git_vpayno/exercism-workspace/cpp/reverse-string/reverse_string.h:6:10: error: 'iterator' file not found [clang-diagnostic-error]
#include <iterator>
^~~~~~~~~~

real 0m8.601s
user 0m8.513s
sys 0m0.080s
Running: clang-tidy-16 ./reverse_string.cpp ./reverse_string_test.cpp ./reverse_string.hpp
/home/vpayno/git_vpayno/exercism-workspace/cpp/reverse-string/reverse_string_test.cpp:9:13: warning: the 'empty' method should be used to check for emptiness instead of comparing to an empty object [readability-container-size-empty]
REQUIRE("" == reverse_string::reverse_string(""));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -181,9 +167,9 @@ error: argument unused during compilation: '-stdlib=libstdc++' [clang-diagnostic
^


real 0m6.970s
user 0m6.891s
sys 0m0.080s
real 0m8.604s
user 0m8.514s
sys 0m0.083s

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

0 comments on commit 715272f

Please sign in to comment.