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

move Test into an extension #3

Open
wants to merge 7 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
16 changes: 9 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
julia-version: ['~1.6.0-beta1', '1.5', '1.4', '1.0']
julia-version: ['lts', '1', 'pre', 'nightly']
fail-fast: false
name: Test Julia ${{ matrix.julia-version }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup julia
uses: julia-actions/setup-julia@v1
uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.julia-version }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v4
with:
file: ./lcov.info
flags: unittests
name: codecov-umbrella
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
8 changes: 7 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ version = "0.1.16-DEV"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[weakdeps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[extensions]
SplittablesTestingExt = "Test"

[compat]
Setfield = "0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1.0"
julia = "1"
julia = "1.6"

[extras]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Expand Down
49 changes: 49 additions & 0 deletions ext/SplittablesTestingExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module SplittablesTestingExt
using SplittablesBase

using Test: @test, @testset
using SplittablesBase: amount, halve
using SplittablesBase.Testing: getdata, getlabel, countmap, recursive_vcat


function SplittablesBase.Testing.test_ordered(examples)
@testset "$(getlabel(x))" for x in enumerate(examples)
@debug "Testing `vcat`: $(getlabel(x))"
@testset "vcat" begin
data = getdata(x)
left, right = halve(getdata(x))
@test isequal(
vcat(vec(collect(left)), vec(collect(right))),
vec(collect(getdata(x))),
)
end
SplittablesBase.Testing.test_recursive_halving(x)
end
end


function SplittablesBase.Testing.test_unordered(examples)
@testset "$(getlabel(x))" for x in enumerate(examples)
@testset "concatenation" begin
data = getdata(x)
left, right = halve(getdata(x))
@test isequal(
countmap(collect(data)),
merge(+, countmap(collect(left)), countmap(collect(right))),
)
end
SplittablesBase.Testing.test_recursive_halving(x)
end
end

function SplittablesBase.Testing.test_recursive_halving(x)
@debug "Testing _recursive halving_: $(getlabel(x))"
@testset "recursive halving" begin
if Base.IteratorSize(getdata(x)) isa Union{Base.HasLength,Base.HasShape}
@test isequal(recursive_vcat(getdata(x), length), vec(collect(getdata(x))))
end
@test isequal(recursive_vcat(getdata(x)), vec(collect(getdata(x))))
end
end

end #module
11 changes: 7 additions & 4 deletions src/SplittablesBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ include("implementations.jl")
end # module

module Testing
using Test: @test, @testset
using ..SplittablesBase: amount, halve
include("testing.jl")
end # module
include("testing.jl")
if !isdefined(Base,:get_extension)
include("../ext/SplittablesTestingExt.jl")
end
end



end # module
51 changes: 10 additions & 41 deletions src/testing.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using ..SplittablesBase: halve, amount

# Load docstring from markdown files:
for (name, path) in [:test_ordered => joinpath(@__DIR__, "test_ordered.md")]
try
Expand Down Expand Up @@ -82,33 +84,6 @@ function recursive_vcat(data, _len, recursions, limit, err)
)
end

function test_recursive_halving(x)
@debug "Testing _recursive halving_: $(getlabel(x))"
@testset "recursive halving" begin
if Base.IteratorSize(getdata(x)) isa Union{Base.HasLength,Base.HasShape}
@test isequal(recursive_vcat(getdata(x), length), vec(collect(getdata(x))))
end
@test isequal(recursive_vcat(getdata(x)), vec(collect(getdata(x))))
end
end

function test_ordered(examples)
@testset "$(getlabel(x))" for x in enumerate(examples)
@debug "Testing `vcat`: $(getlabel(x))"
@testset "vcat" begin
data = getdata(x)
left, right = halve(getdata(x))
@test isequal(
vcat(vec(collect(left)), vec(collect(right))),
vec(collect(getdata(x))),
)
end
test_recursive_halving(x)
end
end

@deprecate test test_ordered false

function countmap(xs)
counts = Dict{Any,Int}()
for x in xs
Expand All @@ -117,27 +92,21 @@ function countmap(xs)
return counts
end

#the actual implementations are in ext/SplittablesTestingExt.jl
function test_recursive_halving end
function test_ordered end

@deprecate test test_ordered false

"""
SplittablesTesting.test_unordered(examples)

See [`test_ordered`](@ref Main.SplittablesTesting.test_ordered).
"""
function test_unordered(examples)
@testset "$(getlabel(x))" for x in enumerate(examples)
@testset "concatenation" begin
data = getdata(x)
left, right = halve(getdata(x))
@test isequal(
countmap(collect(data)),
merge(+, countmap(collect(left)), countmap(collect(right))),
)
end
test_recursive_halving(x)
end
end
function test_unordered end

const _PUBLIC_API = [
# A list of public APIs to be picked by SplittablesTesting.jl
:test_ordered,
:test_unordered,
]
]
Loading