Skip to content

Commit

Permalink
c++/prime-factors: 2nd iteration - c header -> c++ header
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Jul 22, 2023
1 parent d51d4fd commit 1d6e043
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 67 deletions.
6 changes: 3 additions & 3 deletions cpp/prime-factors/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
2 changes: 1 addition & 1 deletion cpp/prime-factors/prime_factors.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "prime_factors.h"
#include "prime_factors.hpp"

namespace prime_factors {

Expand Down
14 changes: 0 additions & 14 deletions cpp/prime-factors/prime_factors.h

This file was deleted.

12 changes: 12 additions & 0 deletions cpp/prime-factors/prime_factors.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#if !defined(PRIME_FACTORS_HPP)
#define PRIME_FACTORS_HPP

#include <vector>

namespace prime_factors {

std::vector<int> of(int number);

} // namespace prime_factors

#endif // PRIME_FACTORS_HPP
2 changes: 1 addition & 1 deletion cpp/prime-factors/prime_factors_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "prime_factors.h"
#include "prime_factors.hpp"
#ifdef EXERCISM_TEST_SUITE
#include <catch2/catch.hpp>
#else
Expand Down
82 changes: 34 additions & 48 deletions cpp/prime-factors/run-tests-cpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Running automated test file(s):
Running: make clean
rm -rf ./build

real 0m0.015s
user 0m0.001s
real 0m0.018s
user 0m0.004s
sys 0m0.014s

===============================================================================
Expand Down Expand Up @@ -78,17 +78,17 @@ TOTAL 118 97 82%
lines: 82.2% (97 out of 118)
branches: 37.3% (84 out of 225)

real 0m10.124s
user 0m9.174s
sys 0m0.945s
real 0m9.884s
user 0m8.948s
sys 0m0.928s

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

cmake-format --in-place CMakeLists.txt

real 0m0.233s
user 0m0.142s
sys 0m0.093s
real 0m0.245s
user 0m0.148s
sys 0m0.092s

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

Expand All @@ -110,64 +110,50 @@ found lint:
Convention: 4


real 0m0.224s
user 0m0.144s
sys 0m0.082s
real 0m0.269s
user 0m0.202s
sys 0m0.068s

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

Running: clang-format-16 -style=file -i ./prime_factors.cpp ./prime_factors_test.cpp ./prime_factors.h
Running: clang-format-16 -style=file -i ./prime_factors.cpp ./prime_factors_test.cpp ./prime_factors.hpp

real 0m0.019s
user 0m0.012s
sys 0m0.006s
real 0m0.044s
user 0m0.019s
sys 0m0.025s

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

Running: ../../.github/citools/cpp/clang-check
clang-check-16 --analyze ./prime_factors.cpp ./prime_factors_test.cpp ./prime_factors.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/prime-factors/prime_factors.h:6:10: fatal error: 'vector' file not found
#include <vector>
^~~~~~~~
1 error generated.
Error while processing /home/vpayno/git_vpayno/exercism-workspace/cpp/prime-factors/prime_factors.h.
clang-check-16 --analyze ./prime_factors.cpp ./prime_factors_test.cpp ./prime_factors.hpp

real 0m0.502s
user 0m0.464s
sys 0m0.038s
real 0m0.595s
user 0m0.539s
sys 0m0.056s


real 0m0.504s
user 0m0.464s
sys 0m0.040s
real 0m0.600s
user 0m0.539s
sys 0m0.060s

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

Running: ../../.github/citools/cpp/clang-tidy | head -n 100
6271 warnings generated.
41659 warnings generated.
41659 warnings and 3 errors generated.
Error while processing /home/vpayno/git_vpayno/exercism-workspace/cpp/prime-factors/prime_factors.h.
Suppressed 41664 warnings (41659 in non-user code, 5 NOLINT).
47892 warnings generated.
Suppressed 47897 warnings (47892 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.074s
user 0m5.994s
sys 0m0.080s
Running: clang-tidy-16 ./prime_factors.cpp ./prime_factors_test.cpp ./prime_factors.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/prime-factors/prime_factors.h:6:10: error: 'vector' file not found [clang-diagnostic-error]
#include <vector>
^~~~~~~~


real 0m6.077s
user 0m5.997s
sys 0m0.080s

real 0m6.440s
user 0m6.371s
sys 0m0.068s
Running: clang-tidy-16 ./prime_factors.cpp ./prime_factors_test.cpp ./prime_factors.hpp


real 0m6.442s
user 0m6.373s
sys 0m0.070s

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

0 comments on commit 1d6e043

Please sign in to comment.