Skip to content

Commit 2e4c3d4

Browse files
committed
make ReTest compatible with Julia 1.0+
1 parent b0dfc71 commit 2e4c3d4

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

src/ReTest.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ matched by `pattern`) and its subject matches `pattern`.
137137
138138
If the passed `pattern` is a string, then it is wrapped in a `Regex` prefixed with
139139
`".*"`, and must match literally the subjects.
140-
This means for example that `"a|b"` will match a subject like `"a|b"` but not like `"a"`.
140+
This means for example that `"a|b"` will match a subject like `"a|b"` but not like `"a"`
141+
(only in Julia versions >= 1.3; in older versions, the regex is simply created as
142+
`Regex(".*" * pattern)`).
141143
The `".*"` prefix is intended to allow matching subjects of nested testsets,
142144
e.g. in the example above, `r".*b"` partially matches the subject `"/a"` and
143145
matches the subject `"/a/b"` (so the corresponding nested testset is run),
@@ -150,7 +152,11 @@ module in which it was written (e.g. `m`, when specified).
150152
function runtests(m::Module, pattern::Union{AbstractString,Regex} = r""; wrap::Bool=false)
151153
regex = pattern isa Regex ?
152154
pattern :
153-
r".*" * pattern
155+
if VERSION >= v"1.3"
156+
r".*" * pattern
157+
else
158+
Regex(".*" * pattern)
159+
end
154160

155161
partial = partialize(regex)
156162
matches(desc, final) = Testset.partialoccursin((partial, regex)[1+final],

src/regex.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ function partialoccursin(r::Regex, s::AbstractString; offset::Integer=0)
55
e == -2 || e >= 0
66
end
77

8+
if isdefined(Base.PCRE, :get_local_match_context)
9+
get_local_match_context() = Base.PCRE.get_local_match_context()
10+
else
11+
get_local_match_context() = Base.PCRE.MATCH_CONTEXT[]
12+
end
13+
814
# from base/pcre.jl
915
# we only changed the return value, to allow detecting partial matches
1016
function exec(re, subject, offset, options, match_data)
@@ -13,7 +19,7 @@ function exec(re, subject, offset, options, match_data)
1319
end
1420
rc = ccall((:pcre2_match_8, Base.PCRE.PCRE_LIB), Cint,
1521
(Ptr{Cvoid}, Ptr{UInt8}, Csize_t, Csize_t, UInt32, Ptr{Cvoid}, Ptr{Cvoid}),
16-
re, subject, ncodeunits(subject), offset, options, match_data, Base.PCRE.get_local_match_context())
22+
re, subject, ncodeunits(subject), offset, options, match_data, get_local_match_context())
1723
# rc == -1 means no match, -2 means partial match.
1824
rc < -2 && error("PCRE.exec error: $(err_message(rc))")
1925
return rc

src/testset.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ include("regex.jl")
55
using Test: DefaultTestSet, Error, Test, _check_testset, finish, get_testset,
66
get_testset_depth, parse_testset_args, pop_testset, push_testset, record
77

8-
using Random: Random, default_rng
8+
import Random
99

1010
const REGEX = Ref{Symbol}()
1111
const FINAL = Ref{Symbol}(:__FINAL__) # must have a value at compile time for ReTestTest
@@ -15,6 +15,10 @@ function __init__()
1515
FINAL[] = gensym()
1616
end
1717

18+
default_rng() = isdefined(Random, :default_rng) ?
19+
Random.default_rng() :
20+
Random.GLOBAL_RNG
21+
1822
function get_testset_string(remove_last=false)
1923
testsets = get(task_local_storage(), :__BASETESTNEXT__, Test.AbstractTestSet[])
2024
join('/' * ts.description for ts in (remove_last ? testsets[1:end-1] : testsets))

test/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ end
151151

152152
import .P # test ReTest's wrapping of non-regex patterns
153153
P.check("b", ["a", "b", "b|c"]) # an implicit prefix r".*" is added
154-
P.check("b|c", ["a", "b|c"]) # "b" is not matched
154+
155+
if VERSION >= v"1.3"
156+
P.check("b|c", ["a", "b|c"]) # "b" is not matched
157+
end
155158

156159
runtests()
157160
runtests(r"^/f1") # just test that a regex can be passed

0 commit comments

Comments
 (0)