Skip to content

Commit 9553ea6

Browse files
authored
gh-49: Add exercises into lesson (#48)
* Add exercises into lesson * Use prek not pre-commit in workflow * Use correct path the docker files * Rename dockerfile to remove episode reference * Test using aleskxyz/build-push to run tests * Login before running tests * Remove linting * Use podman for build as this is what we logged in with * Refer to the parent image for this repo rather than intro-to-modern-fortran * Update links to old ucl-arc repo to the new repo * Add accidentally deleted index.md back in
1 parent 479c530 commit 9553ea6

121 files changed

Lines changed: 6232 additions & 38 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
name: "Exercise tests"
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
types:
10+
- opened
11+
- ready_for_review
12+
- reopened
13+
- synchronize
14+
15+
concurrency:
16+
cancel-in-progress: true
17+
group: >-
18+
${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
19+
20+
jobs:
21+
testing:
22+
if: github.event.pull_request.draft == false
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
packages: read
27+
attestations: read
28+
# This is used to complete the identity challenge
29+
# with sigstore/fulcio when running outside of PRs.
30+
id-token: write
31+
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
35+
36+
- name: Log in to ghcr.io
37+
uses: redhat-actions/podman-login@4934294ad0449894bcd1e9f191899d7292469603 # v1
38+
with:
39+
username: ${{ github.actor }}
40+
password: ${{ github.token }}
41+
registry: ghcr.io
42+
43+
- name: Test episode 1
44+
run: podman build . -f docker-tests/Dockerfile.01
45+
46+
- name: Test episode 2
47+
run: podman build . -f docker-tests/Dockerfile.02
48+
49+
- name: Test episode 2
50+
run: podman build . -f docker-tests/Dockerfile.03
51+
52+
- name: Test episode 4
53+
run: podman build . -f docker-tests/Dockerfile.04
54+
55+
- name: Test episode 5
56+
run: podman build . -f docker-tests/Dockerfile.05
57+
58+
- name: Test episode 6
59+
run: podman build . -f docker-tests/Dockerfile.06

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Vale linter
2+
!.github/styles/config/
3+
!.github/styles/config/vocabularies/
4+
!.github/styles/config/vocabularies/Base
5+
.github/styles/*
6+
.github/styles/config/*
7+
.github/styles/config/vocabularies/*
8+
19
# sandpaper files
210
episodes/*html
311
site/*
@@ -49,3 +57,17 @@ docs/
4957
# translation temp files
5058
po/*~
5159

60+
# pFUnit source code repo
61+
./pfunit
62+
63+
# vscode configuration
64+
.vscode
65+
66+
# exercise build artifacts
67+
**.mod
68+
**build
69+
**build-cmake
70+
71+
# Python environment and artifacts
72+
*.egg-info
73+
.venv

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,29 @@ sandpaper::build_lesson()
1818
```
1919

2020
This will create a local build of the site at [site/docs/index.html](./site/docs/index.html).
21+
22+
## Dependencies
23+
24+
This repo utilises [fortitude](https://fortitude.readthedocs.io/en/stable/) alongside [pre-commit](https://pre-commit.com/) for
25+
linting. To install these tools we use pip therefore contributors will require python version 3.9 or above.
26+
27+
To setup pre-commit and fortitude
28+
29+
1. Create a python virtual environment and activate it
30+
31+
```sh
32+
python3 -m venv .venv
33+
source .venv/bin/activate # or `source .venv/scripts/activate` on windows
34+
```
35+
36+
2. Install the dev dependencies
37+
38+
```sh
39+
python -m pip install -r requirements.txt
40+
```
41+
42+
3. Turn on pre-commit
43+
44+
```sh
45+
pre-commit install
46+
```

config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ life_cycle: 'pre-alpha'
3434
license: 'CC-BY 4.0'
3535

3636
# Link to the source repository for this lesson
37-
source: 'https://github.com/UCL-ARC/fortran-unit-testing-lesson'
37+
source: 'https://github.com/carpentries-incubator/fortran-unit-testing'
3838

3939
# Default branch of your lesson
4040
branch: 'main'

docker-tests/Dockerfile.01

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM ghcr.io/carpentries-incubator/fortran-unit-testing:main
2+
3+
COPY --chown=vscode exercises/1-into-to-unit-tests /home/vscode/1-into-to-unit-tests
4+
5+
WORKDIR /home/vscode/1-into-to-unit-tests/challenge
6+
7+
# Build challenge's tests with cmake
8+
RUN cmake -B build && \
9+
cmake --build build
10+
# Run test with ctest
11+
RUN ctest --test-dir build --output-on-failure
12+
13+
# clean build
14+
RUN rm -rf build
15+
16+
# Build solution's tests with cmake
17+
RUN mv ../solution/test_maths_solution.f90 test/test_maths.f90 && \
18+
cmake -B build && \
19+
cmake --build build
20+
# Run test with ctest
21+
RUN ctest --test-dir build --output-on-failure

docker-tests/Dockerfile.02

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ghcr.io/carpentries-incubator/fortran-unit-testing:main
2+
3+
COPY --chown=vscode exercises/2-refactoring-fortran /home/vscode/2-refactoring-fortran
4+
5+
# Build challenge with cmake
6+
WORKDIR /home/vscode/2-refactoring-fortran/challenge
7+
RUN cmake -B build && \
8+
cmake --build build
9+
10+
# Build solution with cmake
11+
WORKDIR /home/vscode/2-refactoring-fortran/solution
12+
RUN cmake -B build && \
13+
cmake --build build

docker-tests/Dockerfile.03

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
FROM ghcr.io/carpentries-incubator/fortran-unit-testing:main
2+
3+
COPY --chown=vscode exercises/3-writing-your-first-unit-test /home/vscode/3-writing-your-first-unit-test
4+
5+
# Test the Challenge code
6+
7+
WORKDIR /home/vscode/3-writing-your-first-unit-test/challenge
8+
9+
# Build with CMake
10+
RUN cmake -B build-std && \
11+
cmake --build build-std
12+
13+
# Test with CMake
14+
RUN ctest --test-dir build-std --output-on-failure
15+
16+
# Build with Make
17+
RUN FC=/usr/bin/f95 make tests
18+
19+
# Test with Make
20+
RUN ./build/standard_fortran_tests
21+
22+
23+
# Test the Solution code
24+
25+
# Copy solution code
26+
RUN cp ../solution/standard_fortran/test_temp_conversions.f90 test/standard_fortran/test_temp_conversions.f90 && \
27+
cp ../solution/pfunit/* test/pfunit/
28+
29+
# Build with make
30+
31+
# Uncomment pfunit comments
32+
RUN sed -i -E 's/tests: standard_fortran_tests \#\| pfunit_tests/tests: standard_fortran_tests \| pfunit_tests/g' Makefile
33+
RUN sed -i -E 's/clean: \#clean_pfunit/clean: clean_pfunit/g' Makefile
34+
35+
# Clean up anything from the previous builds
36+
RUN make clean
37+
RUN rm -rf build-std
38+
39+
# Build
40+
RUN FC=/usr/bin/f95 make tests
41+
42+
# Run pFUnit tests
43+
RUN ./test/pfunit/tests
44+
45+
# Run standard_fortran tests
46+
RUN ./build/standard_fortran_tests
47+
48+
# Run cleanup again
49+
RUN make clean
50+
51+
52+
# Build with CMake
53+
54+
# Build without pFUnit
55+
RUN cmake -B build-std && \
56+
cmake --build build-std
57+
58+
# Rebuild with pFUnit
59+
RUN cmake -B build-pf -DCMAKE_PREFIX_PATH=/home/vscode/pfunit/build/installed && \
60+
cmake --build build-pf
61+
62+
# Test without pFUnit
63+
RUN ctest --test-dir build-std --output-on-failure
64+
65+
# Test with pFUnit
66+
RUN ctest --test-dir build-pf --output-on-failure

docker-tests/Dockerfile.04

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ghcr.io/carpentries-incubator/fortran-unit-testing:main
2+
3+
COPY --chown=vscode exercises/4-fortran-unit-test-syntax /home/vscode/4-fortran-unit-test-syntax
4+
5+
WORKDIR /home/vscode/4-fortran-unit-test-syntax/solution
6+
7+
# build tests with cmake
8+
RUN cmake -B build -DCMAKE_PREFIX_PATH=/home/vscode/pfunit/build/installed && \
9+
cmake --build build
10+
11+
# test pfunit with ctest
12+
RUN ctest --test-dir build --output-on-failure
13+

docker-tests/Dockerfile.05

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ghcr.io/carpentries-incubator/fortran-unit-testing:main
2+
3+
COPY --chown=vscode exercises/5-debugging-a-failing-test /home/vscode/5-debugging-a-failing-test
4+
5+
WORKDIR /home/vscode/5-debugging-a-failing-test/challenge
6+
7+
# Fix intentional bug in code
8+
RUN sed -i -E 's/.*matrix\(row, col\) = temp_matrix\(row, col\)/matrix\(col, row\) = temp_matrix\(row, col\)/g' src/matrix_transforms.f90
9+
10+
# build tests with cmake
11+
RUN cmake -B build -DCMAKE_PREFIX_PATH=/home/vscode/pfunit/build/installed && \
12+
cmake --build build
13+
14+
# test pfunit with ctest
15+
RUN ctest --test-dir build --output-on-failure

docker-tests/Dockerfile.06

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM ghcr.io/carpentries-incubator/fortran-unit-testing:main
2+
3+
COPY --chown=vscode exercises/6-testing-parallel-code /home/vscode/6-testing-parallel-code
4+
5+
WORKDIR /home/vscode/6-testing-parallel-code/challenge
6+
7+
# Fix intentional bug in code
8+
RUN mv ../solution/test_find_steady_state.pf ./test/ && \
9+
mv ../solution/test_exchange_boundaries.pf ./test/ && \
10+
echo "add_pfunit_ctest (pfunit_find_steady_state_tests\n\
11+
TEST_SOURCES \"\${PROJECT_SOURCE_DIR}/test/test_find_steady_state.pf\"\n\
12+
LINK_LIBRARIES sut\n\
13+
MAX_PES 8\n\
14+
)\n\
15+
\n\
16+
add_pfunit_ctest (pfunit_exchange_boundaries\n\
17+
TEST_SOURCES \"\${PROJECT_SOURCE_DIR}/test/test_exchange_boundaries.pf\"\n\
18+
LINK_LIBRARIES sut\n\
19+
MAX_PES 4\n\
20+
)\n\
21+
" >> test/CMakeLists.txt && \
22+
sed -i -E 's/TEST_FLAGS = -I\$\(BUILD_DIR\) \$\(PFUNIT_EXTRA_FFLAGS\)/TEST_FLAGS = -I\$\(BUILD_DIR\) \$\(PFUNIT_EXTRA_FFLAGS\) -lpfunit/g' test/Makefile && \
23+
sed -i -E 's/test_get_local_grid_info.pf/test_get_local_grid_info.pf \\\n test_find_steady_state.pf \\\n test_exchange_boundaries.pf/g' test/Makefile
24+
25+
# build tests with cmake
26+
RUN cmake -B build-cmake -DCMAKE_PREFIX_PATH=/home/vscode/pfunit/build/installed && \
27+
cmake --build build-cmake
28+
29+
# test with ctest, allowing MPI to oversubscribe
30+
RUN ctest --test-dir build-cmake --output-on-failure
31+
32+
# Remove any generated code
33+
RUN make clean
34+
35+
# Build tests with make
36+
RUN make tests
37+
38+
# Run make tests
39+
RUN mpirun -np 8 ./test/tests

0 commit comments

Comments
 (0)