Skip to content

Commit

Permalink
[Oscar.jl] Move testsuite helpers to utils.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
lkastner committed May 9, 2023
1 parent 77b12e1 commit 8ab6e23
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 44 deletions.
44 changes: 0 additions & 44 deletions src/Oscar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,50 +236,6 @@ function build()
end


@doc raw"""
test_module(file::AbstractString; new::Bool = true)
Run the Oscar tests in the file `test/<file>.jl` where `file` may be a path.
The optional parameter `new` takes the values `false` and `true` (default). If
`true`, then the tests are run in a new session, otherwise the currently active
session is used.
For experimental modules, use [`test_experimental_module`](@ref) instead.
"""
function test_module(file::AbstractString; new::Bool=true)
julia_exe = Base.julia_cmd()
rel_test_file = normpath("test", "$file.jl")
test_file = joinpath(oscardir, rel_test_file)

if new
cmd = "using Test; using Oscar; Hecke.assertions(true); include(\"$test_file\");"
@info("spawning ", `$julia_exe -e \"$cmd\"`)
run(`$julia_exe -e $cmd`)
else
@req isdefined(Base.Main, :Test) "You need to do \"using Test\""
@info("Running tests for $rel_test_file in same session")
Base.include(Base.Main, test_file)
end
end

@doc raw"""
test_experimental_module(project::AbstractString; file::AbstractString="runtests", new::Bool = true)
Run the Oscar tests in the file `experimental/<project>/test/<file>.jl`
where `file` may be a path.
The default is to run the entire test suite of the module `project`.
The optional parameter `new` takes the values `false` and `true` (default). If
`true`, then the tests are run in a new session, otherwise the currently active
session is used.
"""
function test_experimental_module(
project::AbstractString; file::AbstractString="runtests", new::Bool=true
)
test_file = "../experimental/$project/test/$file"
test_module(test_file; new)
end

include("exports.jl")

Expand Down
67 changes: 67 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
###############################################################################
###############################################################################
##
## versioninfo
##
###############################################################################
###############################################################################
# When a specific branch is loaded via `]add Package#branch` julia will only
# create a checkout and keep a bare git repo in a separate directory.
# In a bare repo HEAD will not point to the correct commit so we use the git
Expand Down Expand Up @@ -86,6 +93,14 @@ function versioninfo(io::IO=stdout; branch=false, jll=false, julia=false, commit
end
end

###############################################################################
###############################################################################
##
## Documentation helpers
##
###############################################################################
###############################################################################

# use tempdir by default to ensure a clean manifest (and avoid modifying the project)
function doc_init(;path=mktempdir())
global docsproject = path
Expand Down Expand Up @@ -179,3 +194,55 @@ $(VERSION). Running the doctests will produce errors that you do not expect."
@warn versionwarn
end
end

###############################################################################
###############################################################################
##
## Testsuite helpers
##
###############################################################################
###############################################################################
@doc raw"""
test_module(file::AbstractString; new::Bool = true)
Run the Oscar tests in the file `test/<file>.jl` where `file` may be a path.
The optional parameter `new` takes the values `false` and `true` (default). If
`true`, then the tests are run in a new session, otherwise the currently active
session is used.
For experimental modules, use [`test_experimental_module`](@ref) instead.
"""
function test_module(file::AbstractString; new::Bool=true)
julia_exe = Base.julia_cmd()
rel_test_file = normpath("test", "$file.jl")
test_file = joinpath(oscardir, rel_test_file)

if new
cmd = "using Test; using Oscar; Hecke.assertions(true); include(\"$test_file\");"
@info("spawning ", `$julia_exe -e \"$cmd\"`)
run(`$julia_exe -e $cmd`)
else
@req isdefined(Base.Main, :Test) "You need to do \"using Test\""
@info("Running tests for $rel_test_file in same session")
Base.include(Base.Main, test_file)
end
end

@doc raw"""
test_experimental_module(project::AbstractString; file::AbstractString="runtests", new::Bool = true)
Run the Oscar tests in the file `experimental/<project>/test/<file>.jl`
where `file` may be a path.
The default is to run the entire test suite of the module `project`.
The optional parameter `new` takes the values `false` and `true` (default). If
`true`, then the tests are run in a new session, otherwise the currently active
session is used.
"""
function test_experimental_module(
project::AbstractString; file::AbstractString="runtests", new::Bool=true
)
test_file = "../experimental/$project/test/$file"
test_module(test_file; new)
end

0 comments on commit 8ab6e23

Please sign in to comment.