Skip to content

Commit 0435e2d

Browse files
heijp06vaeng
authored andcommitted
ci: configure CMake to also build concept exercises (#915)
* Make a function that iterates the exercises and call it for the practice exercises. * Also iterate the concept exercises. * Remove GCC specific code from last_will_test. * Run clang-tidy.
1 parent 0cab5fa commit 0435e2d

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

CMakeLists.txt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
cmake_minimum_required(VERSION 3.5.1)
22
project(exercism CXX)
33

4-
set(alt_exercise_tree ${CMAKE_CURRENT_SOURCE_DIR}/build_exercises/practice)
5-
6-
function(build_fixup exercise_dir alt_exercise_root)
4+
function(build_fixup exercise_dir alt_exercise_root exercise_type example_name)
75
string(REPLACE "-" "_" file ${exercise_dir})
8-
set(source ${CMAKE_CURRENT_SOURCE_DIR}/exercises/practice/${exercise_dir})
6+
set(source ${CMAKE_CURRENT_SOURCE_DIR}/exercises/${exercise_type}/${exercise_dir})
97
if(EXISTS ${source})
108
set(alt_exercise_dir ${alt_exercise_root}/${exercise_dir})
119
file(COPY ${source} DESTINATION ${alt_exercise_root})
12-
if(EXISTS ${alt_exercise_dir}/.meta/example.h)
13-
file(RENAME ${alt_exercise_dir}/.meta/example.h ${alt_exercise_dir}/${file}.h)
10+
if(EXISTS ${alt_exercise_dir}/.meta/${example_name}.h)
11+
file(RENAME ${alt_exercise_dir}/.meta/${example_name}.h ${alt_exercise_dir}/${file}.h)
1412
endif()
15-
if(EXISTS ${alt_exercise_dir}/.meta/example.cpp)
16-
file(RENAME ${alt_exercise_dir}/.meta/example.cpp ${alt_exercise_dir}/${file}.cpp)
13+
if(EXISTS ${alt_exercise_dir}/.meta/${example_name}.cpp)
14+
file(RENAME ${alt_exercise_dir}/.meta/${example_name}.cpp ${alt_exercise_dir}/${file}.cpp)
1715
endif()
1816
endif()
1917
endfunction()
2018

19+
function(add_exercises exercise_type example_name)
20+
file(GLOB exercise_list ${CMAKE_CURRENT_SOURCE_DIR}/exercises/${exercise_type}/*)
21+
set(alt_exercise_tree ${CMAKE_CURRENT_SOURCE_DIR}/build_exercises/${exercise_type})
22+
foreach(exercise_dir ${exercise_list})
23+
get_filename_component(exercise ${exercise_dir} NAME)
24+
build_fixup(${exercise} ${alt_exercise_tree} ${exercise_type} ${example_name})
25+
add_subdirectory(${alt_exercise_tree}/${exercise})
26+
endforeach()
27+
endfunction()
28+
2129
option(EXERCISM_RUN_ALL_TESTS "Run all Exercism tests" On)
2230
option(EXERCISM_COMMON_CATCH "Link against a common Catch2 main lib." On)
2331

@@ -30,10 +38,5 @@ if(EXERCISM_COMMON_CATCH)
3038
)
3139
endif()
3240

33-
file(GLOB exercise_list ${CMAKE_CURRENT_SOURCE_DIR}/exercises/practice/*)
34-
35-
foreach(exercise_dir ${exercise_list})
36-
get_filename_component(exercise ${exercise_dir} NAME)
37-
build_fixup(${exercise} ${alt_exercise_tree})
38-
add_subdirectory(${alt_exercise_tree}/${exercise})
39-
endforeach()
41+
add_exercises("concept" "exemplar")
42+
add_exercises("practice" "example")

exercises/concept/freelancer-rates/.meta/exemplar.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ int monthly_rate(double hourly_rate, double discount) {
1919
int workdays_per_month{22};
2020
double per_month{per_day * workdays_per_month};
2121
double after_discount{apply_discount(per_month, discount)};
22-
int rounded_up{std::ceil(after_discount)};
2322

24-
return rounded_up;
23+
return std::ceil(after_discount);
2524
}
2625

2726
// days_in_budget calculates the number of workdays given a budget, hourly rate,

exercises/concept/last-will/last_will_test.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
// Trick to let the code compile, even if the function has not been implemented:
2-
namespace estate_executor {
3-
int assemble_account_number(int) __attribute__((weak));
4-
int assemble_code() __attribute__((weak));
5-
}
6-
71
#include "last_will.cpp"
82
#ifdef EXERCISM_TEST_SUITE
93
#include <catch2/catch.hpp>
@@ -14,9 +8,9 @@ namespace estate_executor {
148
using namespace std;
159

1610
TEST_CASE("Family secrets have not been altered", "[task_1]") {
17-
// We cannot test the existence of a namespace in the compiled
11+
// We cannot test the existence of a namespace in the compiled
1812
// Code.
19-
// This test merely checks if the numbers in the file have
13+
// This test merely checks if the numbers in the file have
2014
// been changed. They have to be correct for the test to work.
2115

2216
REQUIRE(zhang::bank_number_part(1) == 8541);
@@ -35,7 +29,8 @@ TEST_CASE("Family secrets have not been altered", "[task_1]") {
3529
REQUIRE(garcia::blue::code_fragment() == 923);
3630
}
3731

38-
TEST_CASE("Account number assembly function exists in correct namespace", "[task_2]") {
32+
TEST_CASE("Account number assembly function exists in correct namespace",
33+
"[task_2]") {
3934
REQUIRE_NOTHROW(estate_executor::assemble_account_number(0));
4035
}
4136

@@ -45,11 +40,14 @@ TEST_CASE("Account number assembly works correctly", "[task_2]") {
4540
int account_with_secret_1{16706};
4641
int account_with_secret_23{14238};
4742

48-
REQUIRE(estate_executor::assemble_account_number(1) == account_with_secret_1);
49-
REQUIRE(estate_executor::assemble_account_number(23) == account_with_secret_23);
43+
REQUIRE(estate_executor::assemble_account_number(1) ==
44+
account_with_secret_1);
45+
REQUIRE(estate_executor::assemble_account_number(23) ==
46+
account_with_secret_23);
5047
}
5148

52-
TEST_CASE("Code fragment number assembly function exists in correct namespace", "[task_3]") {
49+
TEST_CASE("Code fragment number assembly function exists in correct namespace",
50+
"[task_3]") {
5351
REQUIRE_NOTHROW(estate_executor::assemble_code());
5452
}
5553

0 commit comments

Comments
 (0)