Skip to content

Commit

Permalink
Merge pull request #7 from archermarx/coverage
Browse files Browse the repository at this point in the history
Code coverage
  • Loading branch information
archermarx authored Nov 17, 2023
2 parents f9b5616 + 2abbac5 commit a26b2c4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@ jobs:
steps:
- uses: actions/checkout@v3

- run: sudo apt-get install gfortran
- run: make
- run: ./runtests
- run: gcov -pb runtests-fort_test.gcno
- name: Install dependencies
run: sudo apt-get install gfortran

- uses: codecov/codecov-action@v3
- name: Build
run: make

- name: Run tests
run: ./runtests

- name: Generate coverage reports
run: gcov -pb *-fort_test.*

- name: Upload coverage reports to CodeCov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
*.gcno
!makefile
!Doxyfile
!LICENSE
!LICENSE
*.gcov
20 changes: 13 additions & 7 deletions src/fort_test.f90
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module fort_test
private

public:: TestSet, Result, new_testset, run_all, run_and_exit, &
assert, assert_eq, assert_neq, assert_gt, assert_geq, assert_lt, assert_leq, assert_approx
assert, assert_eq, assert_neq, assert_gt, assert_geq, assert_lt, assert_leq, assert_approx, &
style_text, get_color_code, logical_to_int

type Result
character(len = :), allocatable:: assertion
Expand Down Expand Up @@ -235,15 +236,20 @@ integer(i32) function run_all(testsets) result(num_failed)

end function

pure integer(i32) function logical_to_int(log) result(int)
logical, intent(in):: log
if (log) then
int = 1
else
int = 0
endif
end function

subroutine run_and_exit(testsets)
type(TestSet), dimension(:), intent(in):: testsets
integer(i32):: num_failed
num_failed = run_all(testsets)
if (num_failed > 0) then
call exit(1)
else
call exit(0)
endif
call exit(logical_to_int(num_failed /= 0))
end subroutine

!============================================================
Expand Down Expand Up @@ -1101,4 +1107,4 @@ function style_text(str, fg_color, bg_color, style) result(styled)

end function

end module fort_test
end module
31 changes: 29 additions & 2 deletions src/tests.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ program runtests

logical_tests = new_testset( &
(/ &
assert(logical_to_int(.true.) == 1), &
assert(logical_to_int(.false.) == 0), &
assert(.true.) , &
assert_eq((2 + 2 == 4), (4 + 4 == 8)), &
assert_neq((2 + 2 == 4), (4 + 3 == 8)) &
Expand Down Expand Up @@ -77,7 +79,7 @@ program runtests

assert_gt(20.0_real32, 10.0_real32), &
assert_gt(20.0_real64, 10.0_real64), &
!assert_gt(20.0_real128, 10.0_real128), &
assert_gt(20.0_real128, 10.0_real128), &

assert_geq(20.0_real32, 10.0_real32), &
assert_geq(20.0_real32, 20.0_real32), &
Expand All @@ -99,7 +101,14 @@ program runtests

assert_approx(1.0_real32, 1.0_real32 + 10 * epsilon(1.0_real32)), &
assert_approx(1.0_real64, 1.0_real64 + 10 * epsilon(1.0_real64)), &
assert_approx(1.0_real128, 1.0_real128 + 10 * epsilon(1.0_real128)) &
assert_approx(1.0_real128, 1.0_real128 + 10 * epsilon(1.0_real128)), &

assert_approx(1.0_real32, 1.0_real32 + 10 * epsilon(1.0_real32), &
atol = 0.0_real32, rtol = sqrt(epsilon(1.0_real32))), &
assert_approx(1.0_real64, 1.0_real64 + 10 * epsilon(1.0_real64), &
atol = 0.0_real64, rtol = sqrt(epsilon(1.0_real64))), &
assert_approx(1.0_real128, 1.0_real128 + 10 * epsilon(1.0_real128), &
atol = 0.0_real128, rtol = sqrt(epsilon(1.0_real128))) &
/), &
name = "Real tests" &
)
Expand Down Expand Up @@ -171,6 +180,24 @@ program runtests
call exit(1)
endif

! text styling
print*, style_text("test", bg_color = "black", style = "hidden")
print*, style_text("test", bg_color = "white", style = "underline")
print*, style_text("test", bg_color = "green", style = "strike")
print*, style_text("test", bg_color = "light yellow", style = "italic")
print*, style_text("test", bg_color = "gray", style = "dim")
print*, style_text("test", bg_color = "light green", style = "blink")
print*, style_text("test", bg_color = "light pink", style = "fast blink")
print*, style_text("test", bg_color = "yellow", style = "invert")
print*, style_text("test", bg_color = "blue", style = "circle")
print*, style_text("test", bg_color = "aqua", style = "frame")
print*, style_text("test", bg_color = "purple", style = "overline")
print*, style_text("test", bg_color = "white", style = "overline")
print*, style_text("test", bg_color = "pink", style = "bold")
print*, style_text("test", bg_color = "peach", style = "bold")
print*, style_text("test", bg_color = "light blue", style = "bold")
print*, get_color_code("blue", "none")

write(*, *) NEW_LINE('a')//"Running actual tests..."
call run_and_exit(tests)
end program

0 comments on commit a26b2c4

Please sign in to comment.