Skip to content

Commit 48c44aa

Browse files
committed
Manually list tets files as is recommended for using CMake
1 parent aee04cb commit 48c44aa

File tree

7 files changed

+16
-20
lines changed

7 files changed

+16
-20
lines changed

episodes/3-writing-your-first-unit-test/challenge/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ know that there is no function which does this direct conversion. With this is m
2222
a test, or tests, to give you confidence that temp_conversions can correctly convert
2323
Fahrenheit to Kelvin.
2424

25-
To get you started, the file [test_temp_conversions.f90](./test/test_temp_conversions.f90)
25+
To get you started, the file [test_temp_conversions.f90](./test/standard_fortran/test_temp_conversions.f90)
2626
has been provided. `test_temp_conversions.f90` contains some boilerplate to make writing a
2727
test easier. There is an empty test subroutine `test` provided which takes in a logical
2828
`passed` and a character array `failure_message`. The logical `passed` should indicate if
@@ -31,6 +31,9 @@ message that will be printed to the terminal in the event that `passed` is `.fal
3131
the test subroutine is written it should be called within the main body of the test program
3232
as indicated in `test_temp_conversions.f90`.
3333

34+
> Not: If you add a new test file or change the name of `test_temp_conversions.f90`, you will
35+
> need to update list of tests (`test_src`) in [test/pfunit/CMakeLists.txt](./test/pfunit/CMakeLists.txt)
36+
3437
### Part 2 - Convert tests to use pFUnit
3538

3639
Convert your tests from [Part 1](#part-1---test-with-standard-fortran), to use
@@ -41,7 +44,7 @@ for your pFUnit test(s) has been provided. Comments within this file indicate th
4144
the pFUnit test you must write.
4245

4346
> Note: This template has been written to facilitate conversion of
44-
> [test_temp_conversions.f90](./test/test_temp_conversions.f90) as provided with this repo
47+
> [test_temp_conversions.f90](./test/standard_fortran/test_temp_conversions.f90) as provided with this repo
4548
> to pFUnit. If your version of test_temp_conversions.f90, produced in Part 1, is significantly
4649
> different, You may prefer to use a different structure to the one provided in the template.
4750
@@ -54,4 +57,7 @@ cmake --build build
5457
ctest --test-dir build --output-on-failure
5558
```
5659

60+
If your test does not get built, ensure you have added it to the list of tests (`test_src`)
61+
in [test/pfunit/CMakeLists.txt](./test/pfunit/CMakeLists.txt)
62+
5763
> If you are using the devcontainer, there is an installation of pFUnit at /home/vscode/pfunit/build/installed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
find_package(PFUNIT QUIET)
22

3+
add_subdirectory("standard_fortran")
4+
35
if (PFUNIT_FOUND)
46
add_subdirectory("pfunit")
5-
else()
6-
add_subdirectory("standard_fortran")
77
endif()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.f90
2+
*.F90

episodes/3-writing-your-first-unit-test/challenge/test/pfunit/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,7 @@ set(TEST_DIR "${PROJECT_SOURCE_DIR}/test/pfunit")
66
add_library (sut STATIC ${PROJ_SRC_FILES})
77

88
# List all test files
9-
file(GLOB
10-
test_srcs
11-
"${TEST_DIR}/*.pf"
12-
)
13-
14-
list(LENGTH test_srcs num_test_srcs)
15-
if (num_test_srcs EQUAL 0)
16-
message(FATAL_ERROR "No .pf files found in: ${TEST_DIR}")
17-
endif()
9+
set(test_srcs "test_temp_conversions.pf")
1810

1911
add_pfunit_ctest (pfunit_test_temp_conversions_exec
2012
TEST_SOURCES ${test_srcs}

episodes/3-writing-your-first-unit-test/challenge/test/standard_fortran/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ message(STATUS "Using standard Fortran")
33
set(TEST_DIR "${PROJECT_SOURCE_DIR}/test/standard_fortran")
44

55
# Define test file(s)
6-
file(GLOB test_srcs "${TEST_DIR}/*.f90")
7-
8-
list(LENGTH test_srcs num_test_srcs)
9-
if (num_test_srcs EQUAL 0)
10-
message(FATAL_ERROR "No .f90 files found in: ${TEST_DIR}")
11-
endif()
6+
set(test_srcs "test_temp_conversions.f90")
127

138
# Build test executable
149
add_executable(test_temp_conversions_exec

episodes/3-writing-your-first-unit-test/solution/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ investigation would be required.
2323

2424
#### Parameterised tests
2525

26-
Each test subroutine in [test_temp_conversions.f90](./test_temp_conversions.f90) take in an `input` and an `expected_output`.
26+
Each test subroutine in [test_temp_conversions.f90](./test_temp_conversions.f90) takes in an `input` and an `expected_output`.
2727
This allows the same test subroutine to be called with multiple different inputs to test several scenarios with the same test
2828
code. Therefore, we are able to test edge cases and other key scenarios more easily.
2929

episodes/3-writing-your-first-unit-test/solution/test_temp_conversions.pf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ contains
108108
type(temp_conversions_test_params_t), intent(in) :: testParameter
109109
!> The test case to return after conversion from parameters
110110
type(temp_conversions_test_case_t) :: tst
111+
111112
tst%params = testParameter
112113
end function new_test_case
113114

@@ -116,6 +117,7 @@ contains
116117
!> The parameters to be converted to a string
117118
class(temp_conversions_test_params_t), intent(in) :: this
118119
character(:), allocatable :: string
120+
119121
string = trim(this%description)
120122
end function temp_conversions_test_params_t_toString
121123

0 commit comments

Comments
 (0)