Skip to content

Commit b5c14b4

Browse files
committed
Merge branch 'master' into open
2 parents 576b4f7 + 84c75fb commit b5c14b4

16 files changed

+192
-82
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ jobs:
7171
if: contains(matrix.os, 'ubuntu') && contains(matrix.gcc_v, '9')
7272
run: |
7373
make -f Makefile.manual
74+
make -f Makefile.manual test
75+
make -f Makefile.manual clean

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ enable_testing()
55
# this avoids stdlib and projects using stdlib from having to introspect stdlib's directory structure
66
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR})
77

8+
# compiler feature checks
9+
include(CheckFortranSourceCompiles)
10+
check_fortran_source_compiles("error stop i; end" f18errorstop SRC_EXT f90)
11+
812
add_subdirectory(src)

Makefile.manual

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# Fortran stdlib Makefile
22

33
FC = gfortran
4-
FCFLAGS=-O0
4+
FFLAGS = -Wall -Wextra -Wimplicit-interface -fPIC -g -fcheck=all
55

6-
.PHONY: all clean
6+
export FC
7+
export FFLAGS
78

8-
all: stdlib tests
9+
.PHONY: all clean test
910

10-
stdlib:
11-
$(MAKE) -f Makefile.manual FC=${FC} FCFLAGS=${FCFLAGS} --directory=src
11+
all:
12+
$(MAKE) -f Makefile.manual --directory=src
13+
$(MAKE) -f Makefile.manual --directory=src/tests
1214

13-
tests: stdlib
14-
$(MAKE) -f Makefile.manual FC=${FC} FCFLAGS=${FCFLAGS} --directory=src/tests
15+
test:
16+
$(MAKE) -f Makefile.manual --directory=src/tests test
17+
@echo
18+
@echo "All tests passed."
1519

1620
clean:
1721
$(MAKE) -f Makefile.manual clean --directory=src

src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ set(SRC
66

77
add_library(fortran_stdlib ${SRC})
88

9+
if(f18errorstop)
10+
target_sources(fortran_stdlib PRIVATE f18estop.f90)
11+
else()
12+
target_sources(fortran_stdlib PRIVATE f08estop.f90)
13+
endif()
14+
915
add_subdirectory(tests)
1016

1117
install(TARGETS fortran_stdlib

src/Makefile.manual

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
OBJS = stdlib_experimental_ascii.o \
2-
stdlib_experimental_error.o \
3-
stdlib_experimental_io.o \
1+
SRC = stdlib_experimental_ascii.f90 \
2+
stdlib_experimental_error.f90 \
3+
stdlib_experimental_io.f90 \
4+
f18estop.f90
5+
6+
LIB = libstdlib.a
47

5-
.PHONY: all clean
6-
.SUFFIXES: .f90 .o
78

8-
all: $(OBJS)
99

10-
.f90.o:
11-
$(FC) $(FCFLAGS) -c $<
10+
OBJS = $(SRC:.f90=.o)
11+
MODS = $(OBJS:.o=.mod)
12+
SMODS = $(OBJS:.o=*.smod)
13+
14+
.PHONY: all clean
1215

13-
%.o: %.mod
16+
all: $(LIB)
1417

15-
stdlib_experimental_ascii.o: stdlib_experimental_ascii.f90
16-
stdlib_experimental_error.o: stdlib_experimental_error.f90
17-
stdlib_experimental_io.o: stdlib_experimental_io.f90
18+
$(LIB): $(OBJS)
19+
ar rcs $@ $(OBJS)
1820

1921
clean:
20-
$(RM) *.o *.mod
22+
$(RM) $(LIB) $(OBJS) $(MODS) $(SMODS)
23+
24+
%.o: %.f90
25+
$(FC) $(FFLAGS) -c $<
26+
27+
28+
# Fortran module dependencies
29+
f18estop.o: stdlib_experimental_error.o

src/f08estop.f90

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
submodule (stdlib_experimental_error) estop
2+
3+
contains
4+
5+
module procedure error_stop
6+
! Aborts the program with nonzero exit code
7+
! this is a fallback for Fortran 2008 error stop (e.g. Intel 19.1/2020 compiler)
8+
!
9+
! The "stop <character>" statement generally has return code 0.
10+
! To allow non-zero return code termination with character message,
11+
! error_stop() uses the statement "error stop", which by default
12+
! has exit code 1 and prints the message to stderr.
13+
! An optional integer return code "code" may be specified.
14+
!
15+
! Example
16+
! -------
17+
!
18+
! call error_stop("Invalid argument")
19+
20+
write(stderr,*) msg
21+
22+
if(present(code)) then
23+
select case (code)
24+
case (1)
25+
error stop 1
26+
case (2)
27+
error stop 2
28+
case (77)
29+
error stop 77
30+
case default
31+
write(stderr,*) 'ERROR: code ',code,' was specified.'
32+
error stop
33+
end select
34+
else
35+
error stop
36+
endif
37+
end procedure
38+
39+
end submodule

src/f18estop.f90

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
submodule (stdlib_experimental_error) estop
2+
3+
contains
4+
5+
module procedure error_stop
6+
! Aborts the program with nonzero exit code
7+
!
8+
! The "stop <character>" statement generally has return code 0.
9+
! To allow non-zero return code termination with character message,
10+
! error_stop() uses the statement "error stop", which by default
11+
! has exit code 1 and prints the message to stderr.
12+
! An optional integer return code "code" may be specified.
13+
!
14+
! Example
15+
! -------
16+
!
17+
! call error_stop("Invalid argument")
18+
19+
if(present(code)) then
20+
write(stderr,*) msg
21+
error stop code
22+
else
23+
error stop msg
24+
endif
25+
end procedure
26+
27+
end submodule estop

src/stdlib_experimental_error.f90

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,34 @@
11
module stdlib_experimental_error
2+
use, intrinsic :: iso_fortran_env, only: stderr=>error_unit
23
implicit none
34
private
5+
6+
interface ! f{08,18}estop.f90
7+
module subroutine error_stop(msg, code)
8+
character(*), intent(in) :: msg
9+
integer, intent(in), optional :: code
10+
end subroutine error_stop
11+
end interface
12+
413
public :: assert, error_stop
514

615
contains
716

8-
subroutine assert(condition)
17+
subroutine assert(condition, code)
918
! If condition == .false., it aborts the program.
1019
!
1120
! Arguments
1221
! ---------
1322
!
1423
logical, intent(in) :: condition
24+
integer, intent(in), optional :: code
1525
!
1626
! Example
1727
! -------
1828
!
1929
! call assert(a == 5)
2030

21-
if (.not. condition) call error_stop("Assert failed.")
22-
end subroutine
23-
24-
subroutine error_stop(msg)
25-
! Aborts the program with nonzero exit code
26-
!
27-
! The statement "stop msg" will return 0 exit code when compiled using
28-
! gfortran. error_stop() uses the statement "stop 1" which returns an exit code
29-
! 1 and a print statement to print the message.
30-
!
31-
! Example
32-
! -------
33-
!
34-
! call error_stop("Invalid argument")
35-
36-
character(len=*) :: msg ! Message to print on stdout
37-
print *, msg
38-
stop 1
31+
if (.not. condition) call error_stop("Assert failed.", code)
3932
end subroutine
4033

4134
end module

src/tests/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
add_subdirectory(ascii)
22
add_subdirectory(io)
33

4+
add_executable(test_skip test_skip.f90)
5+
target_link_libraries(test_skip fortran_stdlib)
6+
add_test(NAME AlwaysSkip COMMAND $<TARGET_FILE:test_skip>)
7+
set_tests_properties(AlwaysSkip PROPERTIES SKIP_RETURN_CODE 77)
8+
9+
add_executable(test_fail test_fail.f90)
10+
target_link_libraries(test_fail fortran_stdlib)
11+
add_test(NAME AlwaysFail COMMAND $<TARGET_FILE:test_fail>)
12+
set_tests_properties(AlwaysFail PROPERTIES WILL_FAIL true)

src/tests/Makefile.manual

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
.PHONY: all clean
1+
.PHONY: all clean test
22

3-
all: ascii/test_ascii io/test_loadtxt
4-
5-
ascii/test_ascii:
3+
all:
64
$(MAKE) -f Makefile.manual --directory=ascii
7-
8-
io/test_loadtxt:
95
$(MAKE) -f Makefile.manual --directory=io
106

7+
test:
8+
$(MAKE) -f Makefile.manual --directory=ascii test
9+
$(MAKE) -f Makefile.manual --directory=io test
10+
1111
clean:
1212
$(MAKE) -f Makefile.manual --directory=ascii clean
1313
$(MAKE) -f Makefile.manual --directory=io clean

0 commit comments

Comments
 (0)