Skip to content

Commit

Permalink
Merge pull request #17 from BerkeleyLab/mk-github_ci-public
Browse files Browse the repository at this point in the history
Make GitHub_CI detector function public
  • Loading branch information
rouson authored Sep 7, 2024
2 parents aba05c6 + 920cabf commit fb79a7f
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 31 deletions.
15 changes: 15 additions & 0 deletions src/julienne/julienne_github_ci_m.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt
module julienne_github_ci_m
!! Detect whether a program is running in GitHub Continuous Integration (CI)
implicit none

interface

logical module function GitHub_CI()
!! The result is true if the environment variable named "CI" is set to the string "true"
end function

end interface

end module
25 changes: 25 additions & 0 deletions src/julienne/julienne_github_ci_s.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt
submodule(julienne_github_ci_m) julienne_github_ci_s
implicit none

contains

module procedure GitHub_CI

integer name_length
character(len=:), allocatable :: CI

call get_environment_variable("CI", length=name_length)

if (name_length==0) then
GitHub_CI = .false.
else
allocate(character(len=name_length):: CI)
call get_environment_variable("CI", value=CI)
GitHub_CI = merge(.true., .false., CI=="true")
end if

end procedure

end submodule
17 changes: 13 additions & 4 deletions src/julienne/julienne_test_description_m.f90
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ function test_function_i() result(passes)
procedure(test_function_i), pointer, nopass :: test_function_ => null()
contains
procedure run
procedure contains_text
generic :: contains_text => contains_string_t, contains_characters
procedure, private :: contains_string_t, contains_characters
generic :: operator(==) => equals
procedure, private :: equals
procedure, private :: equals
end type

interface test_description_t
Expand Down Expand Up @@ -58,14 +59,22 @@ impure elemental module function run(self) result(test_result)
type(test_result_t) test_result
end function

impure elemental module function contains_text(self, substring) result(match)
!! The result is .true. if the test description includes the value of substring
impure elemental module function contains_string_t(self, substring) result(match)
!! The result is .true. if the test description includes the value of substring
implicit none
class(test_description_t), intent(in) :: self
type(string_t), intent(in) :: substring
logical match
end function

impure elemental module function contains_characters(self, substring) result(match)
!! The result is .true. if the test description includes the value of substring
implicit none
class(test_description_t), intent(in) :: self
character(len=*), intent(in) :: substring
logical match
end function

elemental module function equals(lhs, rhs) result(lhs_eq_rhs)
!! The result is .true. if the components of the lhs & rhs are equal
implicit none
Expand Down
6 changes: 5 additions & 1 deletion src/julienne/julienne_test_description_s.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
test_result = test_result_t(self%description_, self%test_function_())
end procedure

module procedure contains_text
module procedure contains_string_t
match = index(self%description_%string(), substring%string()) /= 0
end procedure

module procedure contains_characters
match = index(self%description_%string(), substring) /= 0
end procedure

module procedure equals
lhs_eq_rhs = (lhs%description_ == rhs%description_) .and. associated(lhs%test_function_, rhs%test_function_)
end procedure
Expand Down
2 changes: 1 addition & 1 deletion src/julienne/julienne_test_s.F90
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
end associate
end block
end associate
#ifndef __flang__
#ifndef NO_MULTI_IMAGE_SUPPORT
end associate
#endif

Expand Down
3 changes: 3 additions & 0 deletions src/julienne_m.f90
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt
module julienne_m
!! Global aggregation of all public entities
use julienne_bin_m, only : bin_t
use julienne_command_line_m, only : command_line_t
use julienne_file_m, only : file_t
use julienne_github_ci_m, only : github_ci
use julienne_formats_m, only : separated_values, csv
use julienne_string_m, only : string_t, operator(.cat.)
use julienne_test_m, only : test_t, test_description_substring
Expand All @@ -18,6 +20,7 @@ module julienne_m
public :: command_line_t
public :: operator(.cat.)
public :: file_t
public :: github_ci
public :: separated_values
public :: string_t
public :: test_t
Expand Down
44 changes: 19 additions & 25 deletions test/main.F90
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt

#if defined(__flang__)
#define NO_MULTI_IMAGE_SUPPORT
#endif

program main
use bin_test_m, only : bin_test_t
use command_line_test_m, only : command_line_test_t
use formats_test_m, only : formats_test_t
use julienne_m, only : command_line_t
use string_test_m, only : string_test_t
use test_result_test_m, only : test_result_test_t
use test_description_test_m, only : test_description_test_t
use vector_test_description_test_m, only : vector_test_description_test_t
!! Julienne unit tests driver

! Internal utilities
use julienne_m ,only : command_line_t, GitHub_CI

! Test modules
use bin_test_m ,only : bin_test_t
use command_line_test_m ,only : command_line_test_t
use formats_test_m ,only : formats_test_t
use string_test_m ,only : string_test_t
use test_result_test_m ,only : test_result_test_t
use test_description_test_m ,only : test_description_test_t
use vector_test_description_test_m ,only : vector_test_description_test_t
implicit none

type(bin_test_t) bin_test
Expand Down Expand Up @@ -41,26 +51,10 @@ program main
call vector_test_description_test%report(passes,tests)
if (.not. GitHub_CI()) call command_line_test%report(passes, tests)

#ifndef __flang__
#ifndef NO_MULTI_IMAGE_SUPPORT
if (this_image()==1) &
#endif
print *, new_line('a'), "_________ In total, ",passes," of ",tests, " tests pass. _________"
if (passes /= tests) error stop
contains

logical function GitHub_CI()
integer name_length
character(len=:), allocatable :: CI

call get_environment_variable("CI", length=name_length)

if (name_length==0) then
GitHub_CI = .false.
else
allocate(character(len=name_length):: CI)
call get_environment_variable("CI", value=CI)
GitHub_CI = merge(.true., .false., CI=="true")
end if
end function

end program

0 comments on commit fb79a7f

Please sign in to comment.