Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Revise tests #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ julia = "1.7"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"

[targets]
test = ["Test"]
test = ["Test", "Revise"]
10 changes: 10 additions & 0 deletions test/assets/basic1.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using QuickTypes

abstract type Vehicle end

@qstruct Car{T<:Number, U}(size::T, nwheels::Int=4; manufacturer::U=nothing,
brand::String="off-brand") <: Vehicle

@qstruct_fp Plane(nwheels::Number; brand=:zoomba) do
@assert nwheels < 100
end <: Vehicle
10 changes: 10 additions & 0 deletions test/assets/basic2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using QuickTypes

abstract type Vehicle end

@qstruct Car{T<:Number, U}(size::T, nwheels::Int=18; manufacturer::U=nothing,
brand::String="off-brand") <: Vehicle

@qstruct_fp Plane(nwheels::Number; brand=:airbus) do
@assert nwheels < 100
end <: Vehicle
1 change: 1 addition & 0 deletions test/assets/blank.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# blank
10 changes: 10 additions & 0 deletions test/assets/within-macro1.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using QuickTypes
using MacroTools: @q, @capture

macro mymodel(def)
@capture(def, model_(; params__))
esc(@q begin
$QuickTypes.@qstruct_fp $model(; $(params...))
end)
end
@mymodel modelA(; p0=0f0)
10 changes: 10 additions & 0 deletions test/assets/within-macro2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using QuickTypes
using MacroTools: @q, @capture

macro mymodel(def)
@capture(def, model_(; params__))
esc(@q begin
$QuickTypes.@qstruct_fp $model(; $(params...))
end)
end
@mymodel modelA(; p0=22f0)
75 changes: 75 additions & 0 deletions test/revise.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Revise
using Test

## utils

function cp_content(fname; info="test/revise.jl `cp_content`")
content_path = joinpath(assets_dir, fname)
test_content_path = joinpath(test_src_dir, content_fname)
@info info content_path test_content_path
cp(content_path, test_content_path; force=true)
chmod(test_content_path, 0o664) # make sure the file we copied has 'rw' access
end

function do_revise()
sleep(1)
Revise.revise()
sleep(1)
end

## end utils

## setup

assets_dir = joinpath(@__DIR__, "assets")
test_dir = mktempdir()
content_fname = "content.jl"

# use `rand` to avoid caching issues
# when invoking `include("test/revise.jl")` in the REPL
mod_name = string("QuickTypesReviseTestModule", rand(1:100000))
test_src_dir = mkpath(joinpath(test_dir, mod_name, "src"))
test_mod_path = joinpath(test_src_dir, mod_name * ".jl")

open(joinpath(test_mod_path), "w") do f
write(f, """
module $mod_name
include("$content_fname")
end""")
end
cp_content("blank.jl")

# load that temporary package
mod_sym = Symbol(mod_name)
push!(LOAD_PATH, test_dir)
@eval import $mod_sym
pop!(LOAD_PATH)
TestModule = @eval $mod_sym

## end setup

@testset "should revise basic content" begin
cp_content("basic1.jl")
do_revise()

@test TestModule.Car(10; manufacturer=("Danone", "Hershey")).nwheels == 4
@test TestModule.Plane{Int, Symbol}(2).brand == :zoomba

cp_content("basic2.jl")
do_revise()

@test TestModule.Car(10; manufacturer=("Danone", "Hershey")).nwheels == 18
@test TestModule.Plane{Int, Symbol}(2).brand == :airbus
end

@testset "should revise content within macros" begin
cp_content("within-macro1.jl")
do_revise()

@test TestModule.modelA().p0 == 0f0

cp_content("within-macro2.jl")
do_revise()

@test TestModule.modelA().p0 == 22f0
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,5 @@ QuickTypes.check_destructurable(::NotDestruct) = throw(MyException())
@d dontdestruct(NotDestruct(x)) = x

@test_throws MyException dontdestruct(NotDestruct(x))

include("revise.jl")
Loading