Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger-luo committed Sep 20, 2020
1 parent a174bae commit 8ed27bd
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/configurations.jl
Expand Up @@ -114,10 +114,10 @@ Base.@kwdef struct Application <: AbstractConfiguration
path::String="build"
incremental::Bool=false
filter_stdlibs::Bool=true
cpu_target::Bool=PackageCompiler.default_app_cpu_target()
cpu_target::String=PackageCompiler.default_app_cpu_target()
precompile::Precompile=Precompile()

function Application(path::String, incremental::Bool, filter_stdlibs::Bool, cpu_target::Bool, precompile::Precompile)
function Application(path::String, incremental::Bool, filter_stdlibs::Bool, cpu_target::String, precompile::Precompile)
if isabspath(path)
throw(ArgumentError("build path must be project relative"))
end
Expand Down Expand Up @@ -320,6 +320,12 @@ function read_configs(m::Union{Module, String}; kwargs...)
end

default_cmd_name(m::Module) = lowercase(string(nameof(m)))
default_cmd_name(path::String) = lowercase(splitext(basename(path))[1])
default_cmd_name(path::String) = error("missing field \"name\" in (Julia)Comonicon.toml")

function Base.:(==)(x::T, y::T) where {T <: AbstractConfiguration}
return all(fieldnames(T)) do field
getfield(x, field) == getfield(y, field)
end
end

end # Configs
101 changes: 101 additions & 0 deletions test/configurations.jl
@@ -0,0 +1,101 @@
using Test
using Comonicon.PATH
using Comonicon.Configurations
using Comonicon.Configurations: Install, Application, SysImg, Download, Precompile

module XYZ end

@test read_configs(XYZ) == Configurations.Comonicon(
name="xyz",
install = Install(
path = "~/.julia",
completion = true,
quiet = false,
compile = "yes",
optimize = 2,
),
sysimg = nothing,
download = nothing,
application = nothing,
)

@test read_configs(XYZ; name="zzz") == Configurations.Comonicon(
name="zzz",
install = Install(
path = "~/.julia",
completion = true,
quiet = false,
compile = "yes",
optimize = 2,
),
sysimg = nothing,
download = nothing,
application = nothing,
)

@test read_configs(XYZ; path="mypath") == Configurations.Comonicon(
name="xyz",
install = Install(
path = "mypath",
completion = true,
quiet = false,
compile = "yes",
optimize = 2,
),
sysimg = nothing,
download = nothing,
application = nothing,
)

@test_throws ArgumentError read_configs(XYZ; filter_stdlibs=true)
@test_throws ArgumentError Application(;path=pwd())
@test_throws ArgumentError SysImg(;path=pwd())

read_configs(XYZ; user="Roger-luo", repo="Foo") == Configurations.Comonicon(
name="xyz",
install = Install(
path = "~/.julia",
completion = true,
quiet = false,
compile = "yes",
optimize = 2,
),
sysimg = nothing,
download = Download(
user="Roger-luo",
repo="Foo",
),
application = nothing,
)

@test_throws ArgumentError read_configs(XYZ; abc=2)

@test read_configs(PATH.project("test", "Foo", "Comonicon.toml")) == Configurations.Comonicon(
name = "foo",
install = Install(
path = "~/.julia",
completion = true,
quiet = false,
compile = "min",
optimize = 2,
),
sysimg = SysImg(
path = "deps",
incremental = true,
filter_stdlibs = false,
cpu_target = "native",
precompile = Precompile(
execution_file = ["deps/precopmile.jl"],
statements_file = String[],
),
),
download = Download(
host = "github.com",
user = "Roger-luo",
repo = "Foo.jl",
),
application = nothing,
)


@test_throws ErrorException read_configs(PATH.project("test"))
4 changes: 4 additions & 0 deletions test/runtests.jl
Expand Up @@ -4,6 +4,10 @@ using Pkg

Comonicon.disable_cache()

@testset "configurations" begin
include("configurations.jl")
end

@testset "codegen" begin
include("codegen.jl")
end
Expand Down

0 comments on commit 8ed27bd

Please sign in to comment.