Skip to content

Commit

Permalink
Preliminary support for 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Seelengrab committed Jul 15, 2023
1 parent 1f85fdd commit a52b59b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ jobs:
fail-fast: false
matrix:
version:
- '1.9' # Replace this with the minimum Julia version that your package supports. E.g. if your package requires Julia 1.5 or higher, change this to '1.5'.
- '1.6'
- '1.7'
- '1.8'
- '1.9'
- '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia.
os:
- ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["Sukera <[email protected]>"]
version = "0.9.1"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -17,5 +18,6 @@ AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
ATExt = "AbstractTrees"

[compat]
Compat = "3.35, 4"
RequiredInterfaces = "0.1"
julia = "1.9"
2 changes: 2 additions & 0 deletions src/PropCheck.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module PropCheck

using Compat: Returns

using Base: Signed
using Test
using InteractiveUtils: subtypes
Expand Down
2 changes: 1 addition & 1 deletion src/integrated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ shrink according to `shrink`.
mutable struct IntegratedUnique{T,ElT,S} <: AbstractIntegrated{T}
els::Vector{ElT}
cache::Vector{ElT}
const shrink::S
@constfield shrink::S

function IntegratedUnique(vec::Vector{T}, shrink::S) where {T,S}
treeType = integratorType(T)
Expand Down
16 changes: 16 additions & 0 deletions src/util.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
"""
@constfield foo::Int
A macro providing compatibility for `const` fields in mutable structs.
Gives a `const` `Expr` if supported, otherwise is a noop and just returns the field.
"""
macro constfield(ex::Expr)
ex.head != :(::) || length(ex.args) != 2 || throw(ArgumentError("`@constfield` only supports expressions of the form `field::Type`!"))
ex = esc(ex)
if VERSION < v"1.8"
ex
else
Expr(:const, ex)
end
end

function getSubtypes(T=Any)::Vector{DataType}
T isa Union && return getSubUnions!(DataType[], T)
subs = subtypes(T)
Expand Down
41 changes: 29 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ const numTypes = union(getSubtypes(Integer), getSubtypes(AbstractFloat))
end
@testset "numsToZero" begin
@testset "$T" for T in numTypes
@test numsToZero(T) broken=(T == BigInt || T == BigFloat)
if VERSION >= v"1.7"
@test numsToZero(T) broken=(T == BigInt || T == BigFloat)
else
if T != BigInt && T != BigFloat
@test numsToZero(T)
end
end
end
end
@testset "filter predicates hold for shrunk values" begin
Expand All @@ -147,12 +153,20 @@ const numTypes = union(getSubtypes(Integer), getSubtypes(AbstractFloat))
@testset "throwing properties still shrink" begin
@test check(throwingProperty, itype(UInt8)) == (0x05, ArgumentError("x not smaller than 5"))
end
@testset stringsFromTypeToEmpty()
@testset "stringsFromTypeToEmpty" begin
stringsFromTypeToEmpty()
end
@testset "interleave preserves invariants" begin
@testset interleaveFilterInvariant()
@testset interleaveMapInvariant()
@testset "interleaveFilterInvariant" begin
interleaveFilterInvariant()
end
@testset "interleaveMapInvariant" begin
interleaveMapInvariant()
end
end
@testset "initialVectorLengthIsboundedByRange" begin
initialVectorLengthIsBoundedByRange()
end
@testset initialVectorLengthIsBoundedByRange()
@testset "`Integrated` can be `collect`ed" begin
@test all(x -> x isa Tree{Int}, collect(Iterators.take(itype(Int), 5)))
end
Expand All @@ -163,13 +177,16 @@ const numTypes = union(getSubtypes(Integer), getSubtypes(AbstractFloat))
@test eltype(itr) == Tree{T}
@test eltype(collect(itr)) == Tree{T}
end
@testset "type unstable constructors" begin
grade = map(Base.splat(Pair), PropCheck.interleave(itype(String), isample(0:100)))
# it's type unstable because the empty dispatch returns `Dict{Any,Any}`!
# I'd love to propagate the lowerbound of `1` to make this type stable, but that is hard.
# maybe that needs dependent types?
gradegen = map(Base.splat(Dict), PropCheck.tuple(isample(0:10), grade))
@test eltype(gradegen) == Union{PropCheck.Tree{Dict{Any, Any}}, PropCheck.Tree{Dict{String, Int64}}}
if VERSION >= v"1.9"
# this sadly doesn't infer before then, so we can't really test it :/
@testset "type unstable constructors" begin
grade = map(Base.splat(Pair), PropCheck.interleave(itype(String), isample(0:100)))
# it's type unstable because the empty dispatch returns `Dict{Any,Any}`!
# I'd love to propagate the lowerbound of `1` to make this type stable, but that is hard.
# maybe that needs dependent types?
gradegen = map(Base.splat(Dict), PropCheck.tuple(isample(0:10), grade))
@test eltype(gradegen) == Union{PropCheck.Tree{Dict{Any, Any}}, PropCheck.Tree{Dict{String, Int64}}}
end
end
@testset "$f preserves invariants" for f in (PropCheck.str, PropCheck.vector)
# 3 hex characters is plenty - this is already 3^11 == 177147 possible strings
Expand Down

0 comments on commit a52b59b

Please sign in to comment.