Skip to content

Commit aa8dbf2

Browse files
authored
Merge pull request #69 from bonachea/ci-lfortran
Workaround some lingering problems with LFortran and deploy CI
2 parents 8a788db + 32c340a commit aa8dbf2

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ jobs:
7373
error_stop_code: 128
7474
container: intel/fortran-essentials:2025.0.0-0-devel-ubuntu22.04
7575

76+
# --- LFortran coverage ---
77+
78+
# https://hub.docker.com/r/phhargrove/lfortran/tags
79+
- os: ubuntu-24.04
80+
compiler: lfortran
81+
version: 0.54.0
82+
container: phhargrove/lfortran:0.54.0-1
83+
7684
container:
7785
image: ${{ matrix.container }}
7886

@@ -122,6 +130,9 @@ jobs:
122130
echo "FPM_FC=flang-new" >> "$GITHUB_ENV" ; \
123131
elif test "$FC" = "ifx" ; then \
124132
echo "FPM_FC=ifx" >> "$GITHUB_ENV" ; \
133+
elif test "$FC" = "lfortran" ; then \
134+
echo "FPM_FC=lfortran" >> "$GITHUB_ENV" ; \
135+
echo "FFLAGS=--cpp $FFLAGS" >> "$GITHUB_ENV" ; \
125136
else \
126137
echo "FPM_FC=gfortran-${COMPILER_VERSION}" >> "$GITHUB_ENV" ; \
127138
echo "FFLAGS=-ffree-line-length-0 $FFLAGS" >> "$GITHUB_ENV" ; \
@@ -163,21 +174,26 @@ jobs:
163174
set -x
164175
fpm test ${FPM_FLAGS} --flag "$FFLAGS"
165176
fpm run --example false-assertion ${FPM_FLAGS} --flag "$FFLAGS"
177+
fpm run --example simple-assertions ${FPM_FLAGS} --flag "$FFLAGS"
166178
fpm run --example invoke-via-macro ${FPM_FLAGS} --flag "$FFLAGS"
167179
168180
- name: Build and Test (Assertions ON)
169181
env:
170182
FPM_FLAGS: ${{ env.FPM_FLAGS }} --flag -DASSERTIONS
171183
run: |
172184
set -x
173-
fpm test ${FPM_FLAGS} --flag "$FFLAGS"
174-
( set +e ; fpm run --example false-assertion ${FPM_FLAGS} --flag "$FFLAGS" ; test $? = $ERROR_STOP_CODE )
175-
( set +e ; fpm run --example invoke-via-macro ${FPM_FLAGS} --flag "$FFLAGS" ; test $? = $ERROR_STOP_CODE )
185+
fpm test ${FPM_FLAGS} --flag "$FFLAGS"
186+
( set +e ; fpm run --example false-assertion ${FPM_FLAGS} --flag "$FFLAGS" ; test $? = $ERROR_STOP_CODE )
187+
( set +e ; fpm run --example simple-assertions ${FPM_FLAGS} --flag "$FFLAGS" ; test $? = $ERROR_STOP_CODE )
188+
( set +e ; fpm run --example invoke-via-macro ${FPM_FLAGS} --flag "$FFLAGS" ; test $? = $ERROR_STOP_CODE )
176189
177190
- name: Test Assertions w/ Parallel Callbacks
191+
if: ${{ matrix.compiler != 'lfortran' }} # issue #68
178192
env:
179-
FPM_FLAGS: ${{ env.FPM_FLAGS }} --flag -DASSERTIONS --flag -DASSERT_MULTI_IMAGE --flag -DASSERT_PARALLEL_CALLBACKS
193+
FPM_FLAGS: ${{ env.FPM_FLAGS }} --flag -DASSERT_MULTI_IMAGE --flag -DASSERT_PARALLEL_CALLBACKS
180194
run: |
181195
set -x
182-
( set +e ; fpm run --example false-assertion ${FPM_FLAGS} --flag "$FFLAGS" ; test $? = $ERROR_STOP_CODE )
183-
( set +e ; fpm run --example invoke-via-macro ${FPM_FLAGS} --flag "$FFLAGS" ; test $? = $ERROR_STOP_CODE )
196+
fpm run --example false-assertion ${FPM_FLAGS} --flag "$FFLAGS"
197+
fpm run --example invoke-via-macro ${FPM_FLAGS} --flag "$FFLAGS"
198+
( set +e ; fpm run --example false-assertion ${FPM_FLAGS} --flag "$FFLAGS -DASSERTIONS" ; test $? = $ERROR_STOP_CODE )
199+
( set +e ; fpm run --example invoke-via-macro ${FPM_FLAGS} --flag "$FFLAGS -DASSERTIONS" ; test $? = $ERROR_STOP_CODE )

example/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fpm run --example invoke-via-macro --flag "-DASSERTIONS"
2323
Simple examples
2424
---------------
2525

26-
The [simple_assertions.f90] example demonstrates a precondition and a
26+
The [simple-assertions.f90] example demonstrates a precondition and a
2727
postcondition, each with an assertion that checks the truth of a logical
2828
expression based on scalar, real values.
2929

@@ -32,20 +32,20 @@ Running the examples
3232

3333
### Single-image execution
3434
```
35-
fpm run --example simple_assertions
35+
fpm run --example simple-assertions --flag "-DASSERTIONS"
3636
```
3737
where `fpm run` automatically invokes `fpm build` if necessary, .e.g., if the package's source code
3838
has changed since the most recent build. If `assert` is working correctly, the `fpm run` above
3939
will error-terminate with the character stop code similar to the following
4040
```
41-
Assertion failure on image 1: reciprocal: abs(error) < tolerance
41+
Assertion failure on image 1: All residuals within tolerance
4242
```
4343

4444
### Multi-image execution with `gfortran` and OpenCoarrays
4545
```
4646
git clone [email protected]/sourceryinstitute/assert
4747
cd assert
48-
fpm run --compiler caf --runner "cafrun -n 2" --example simple_assertions
48+
fpm run --compiler caf --runner "cafrun -n 2" --example simple-assertions --flag "-DASSERTIONS"
4949
```
5050
Replace either instance of `2` above with the desired number of images to run for parallel execution.
5151
If `assert` is working correctly, both of the latter `fpm run` commands will error-terminate with one
@@ -55,7 +55,7 @@ or more images providing stop codes analogous to those quoted in the [Single-ima
5555
[OpenCoarrays]: https://github.com/sourceryinstitute/opencoarrays
5656
[Enforcing programming contracts]: #enforcing-programming-contracts
5757
[Single-image execution]: #single-image-execution
58-
[simple_assertions.f90]: ./simple_assertions.f90
58+
[simple-assertions.f90]: ./simple-assertions.f90
5959
[invoke-via-macro.F90]: ./invoke-via-macro.F90
6060
[UML]: https://en.wikipedia.org/wiki/Unified_Modeling_Language
6161
[OCL]: https://en.wikipedia.org/wiki/Object_Constraint_Language

example/simple-assertions.f90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ pure function roots(a,b,c) result(zeros)
1818

1919
associate(discriminant => b**2 - 4*a*c)
2020
call assert(assertion = discriminant >= 0., description = "discriminant >= 0") ! precondition
21+
allocate(zeros(2))
22+
! there's a deliberate math bug in the following line, to help demonstrate assertion failure
2123
zeros = -b + [sqrt(discriminant), -sqrt(discriminant)]
2224
end associate
2325

26+
! This assertion will fail (due to the defect above) when ASSERTIONS are enabled:
2427
call assert(all(abs(a*zeros**2 + b*zeros + c) < tolerance), "All residuals within tolerance.") ! postcondition
2528
end function
2629

src/assert_m.F90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pure subroutine assert_always(assertion, description, file, line)
104104
allocate(character(len=0)::message)
105105
allocate(character(len=0)::location)
106106

107+
107108
! format source location, if known
108109
location = ''
109110
if (present(file)) then
@@ -146,7 +147,13 @@ pure subroutine assert_always(assertion, description, file, line)
146147
; ! deliberate fall-thru
147148
endif
148149
#endif
150+
#ifdef __LFORTRAN__
151+
! workaround a defect observed in LFortran 0.54:
152+
! error stop with an allocatable character argument prints garbage
153+
error stop message//'', QUIET=.false.
154+
#else
149155
error stop message, QUIET=.false.
156+
#endif
150157

151158
end if check_assertion
152159

0 commit comments

Comments
 (0)