From 55435eb19d6753fde12136025920f3d9b78eb884 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Thu, 1 Mar 2018 16:05:39 -0800 Subject: [PATCH] Deprecate contains to a more general isfound function While `contains` was generally limited to strings and regular expressions (after the move from `ismatch` to `contains`), `isfound` works more generally, as its fallback method is defined in terms of `findfirst`. --- DISTRIBUTING.md | 2 +- NEWS.md | 2 + base/array.jl | 22 ++++ base/client.jl | 10 +- base/deprecated.jl | 6 +- base/exports.jl | 2 +- base/libc.jl | 2 +- base/loading.jl | 18 +-- base/methodshow.jl | 2 +- base/mpfr.jl | 2 +- base/path.jl | 10 +- base/regex.jl | 6 +- base/strings/search.jl | 27 +---- base/uuid.jl | 2 +- base/version.jl | 6 +- contrib/add_license_to_files.jl | 2 +- contrib/fixup_precompile.jl | 6 +- doc/src/base/arrays.md | 1 + doc/src/base/strings.md | 1 - doc/src/manual/strings.md | 26 ++-- stdlib/DelimitedFiles/src/DelimitedFiles.jl | 2 +- stdlib/Distributed/test/distributed_exec.jl | 4 +- .../InteractiveUtils/src/InteractiveUtils.jl | 6 +- stdlib/InteractiveUtils/test/runtests.jl | 22 ++-- stdlib/LibGit2/test/libgit2.jl | 16 +-- stdlib/Libdl/test/runtests.jl | 6 +- stdlib/LinearAlgebra/src/blas.jl | 2 +- stdlib/LinearAlgebra/src/uniformscaling.jl | 2 +- stdlib/LinearAlgebra/test/triangular.jl | 16 +-- stdlib/Markdown/src/Common/block.jl | 10 +- stdlib/Markdown/src/Common/inline.jl | 2 +- stdlib/Markdown/src/render/plain.jl | 2 +- stdlib/Markdown/src/render/rst.jl | 2 +- .../src/render/terminal/formatting.jl | 2 +- stdlib/Markdown/test/runtests.jl | 22 ++-- stdlib/Pkg/src/read.jl | 6 +- stdlib/Pkg/src/reqs.jl | 6 +- stdlib/Pkg/test/pkg.jl | 46 +++---- stdlib/Pkg3/bin/utils.jl | 2 +- stdlib/Pkg3/src/Operations.jl | 2 +- stdlib/Pkg3/src/Pkg2/reqs.jl | 6 +- stdlib/Pkg3/src/PlatformEngines.jl | 2 +- stdlib/Pkg3/src/REPLMode.jl | 6 +- stdlib/Pkg3/src/Types.jl | 4 +- stdlib/Pkg3/test/pkg.jl | 2 +- stdlib/REPL/src/REPLCompletions.jl | 4 +- stdlib/REPL/src/docview.jl | 2 +- stdlib/REPL/src/latex_symbols.jl | 2 +- stdlib/REPL/test/repl.jl | 57 +++++---- stdlib/REPL/test/replcompletions.jl | 2 +- stdlib/Serialization/test/runtests.jl | 4 +- stdlib/SparseArrays/test/sparsevector.jl | 6 +- stdlib/SuiteSparse/test/cholmod.jl | 4 +- stdlib/Test/src/Test.jl | 4 +- stdlib/Test/src/logging.jl | 14 +-- stdlib/Test/test/runtests.jl | 103 ++++++++-------- test/backtrace.jl | 2 +- test/char.jl | 2 +- test/cmdlineargs.jl | 32 ++--- test/codegen.jl | 52 ++++---- test/compile.jl | 6 +- test/compiler/compiler.jl | 2 +- test/core.jl | 6 +- test/deprecation_exec.jl | 114 +++++++++--------- test/dict.jl | 8 +- test/docs.jl | 6 +- test/env.jl | 4 +- test/errorshow.jl | 76 ++++++------ test/goto.jl | 2 +- test/llvmcall.jl | 2 +- test/llvmcall2.jl | 2 +- test/logging.jl | 6 +- test/math.jl | 2 +- test/misc.jl | 20 +-- test/mpfr.jl | 2 +- test/offsetarray.jl | 4 +- test/osutils.jl | 4 +- test/reduce.jl | 8 +- test/reflection.jl | 12 +- test/regex.jl | 2 +- test/show.jl | 71 +++++------ test/spawn.jl | 4 +- test/stacktraces.jl | 4 +- test/staged.jl | 8 +- test/strings/search.jl | 8 +- test/strings/types.jl | 4 +- test/threads.jl | 4 +- test/worlds.jl | 2 +- 88 files changed, 516 insertions(+), 520 deletions(-) diff --git a/DISTRIBUTING.md b/DISTRIBUTING.md index 74dc01c0bf6448..2b0c1a83f57cbd 100644 --- a/DISTRIBUTING.md +++ b/DISTRIBUTING.md @@ -364,7 +364,7 @@ for result in eachrow(results) b = result[:backport] if (isna(a) && !isna(b)) || (isna(b) && !isna(a)) color = :yellow - elseif a != b && contains(b, "pass") + elseif a != b && isfound("pass", b) color = :green elseif a != b color = :red diff --git a/NEWS.md b/NEWS.md index 190a456e62bb3b..c87f16568d9bb3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1067,6 +1067,8 @@ Deprecated or removed * The `remove_destination` keyword argument to `cp`, `mv`, and the unexported `cptree` has been renamed to `force` ([#25979]). + * `contains` has been deprecated in favor of a more general `isfound` function ([#26283]). + * The methods of `range` based on positional arguments have been deprecated in favor of keyword arguments ([#25896]). diff --git a/base/array.jl b/base/array.jl index 16c23f862ecfb4..f3203a0379720e 100644 --- a/base/array.jl +++ b/base/array.jl @@ -1684,6 +1684,28 @@ end findfirst(testf::Function, A::Union{AbstractArray, AbstractString}) = findnext(testf, A, first(keys(A))) +""" + isfound(needle, haystack) + +Determine whether `needle` is found within `haystack`. This function is effectively +equivalent to `findfirst(needle, haystack) !== nothing`. + +See also [`findfirst`](@ref) and [`any`](@ref). + +# Examples +```jldoctest +julia> isfound('x', "hexonxonx") +true + +julia> isfound("hi", "hi mom") +true + +julia> isfound(equalto(3), 5:10) +false +``` +""" +isfound(needle, haystack) = findfirst(needle, haystack) !== nothing + """ findprev(A, i) diff --git a/base/client.jl b/base/client.jl index ca76fed2ed24bf..2631486cf9b251 100644 --- a/base/client.jl +++ b/base/client.jl @@ -244,11 +244,11 @@ incomplete_tag(ex) = :none function incomplete_tag(ex::Expr) Meta.isexpr(ex, :incomplete) || return :none msg = ex.args[1] - contains(msg, "string") && return :string - contains(msg, "comment") && return :comment - contains(msg, "requires end") && return :block - contains(msg, "\"`\"") && return :cmd - contains(msg, "character") && return :char + isfound("string", msg) && return :string + isfound("comment", msg) && return :comment + isfound("requires end", msg) && return :block + isfound("\"`\"", msg) && return :cmd + isfound("character", msg) && return :char return :other end diff --git a/base/deprecated.jl b/base/deprecated.jl index 9f90cf11e18583..b0db5a9bb231d9 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1229,7 +1229,7 @@ end @deprecate rsearchindex(s::AbstractString, c::Char) findlast(equalto(c), s) @deprecate rsearchindex(s::AbstractString, c::Char, i::Integer) findprev(equalto(c), s, i) -@deprecate ismatch(r::Regex, s::AbstractString) contains(s, r) +@deprecate ismatch(r::Regex, s::AbstractString) isfound(r, s) @deprecate findin(a, b) findall(occursin(b), a) @@ -1454,6 +1454,10 @@ function slicedim(A::AbstractVector, d::Integer, i::Number) end end +# PR #26283 +@deprecate contains(haystack, needle) isfound(needle, haystack) +@deprecate contains(s::AbstractString, r::Regex, offset::Integer) isfound(r, s, offset=offset) + # Issue #25786 @deprecate_binding DevNull devnull # TODO: When these are removed, also remove the uppercase variants in libuv.jl and stream.jl diff --git a/base/exports.jl b/base/exports.jl index b7d3241a7eeba1..c96c28c3b275da 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -447,7 +447,6 @@ export zeros, # search, find, match and related functions - contains, eachmatch, endswith, equalto, @@ -460,6 +459,7 @@ export findmax!, findnext, findprev, + isfound, occursin, match, searchsorted, diff --git a/base/libc.jl b/base/libc.jl index b269e931416f99..41f329c262b184 100644 --- a/base/libc.jl +++ b/base/libc.jl @@ -203,7 +203,7 @@ function strptime(fmt::AbstractString, timestr::AbstractString) @static if Sys.isapple() # if we didn't explicitly parse the weekday or year day, use mktime # to fill them in automatically. - if !contains(fmt, r"([^%]|^)%(a|A|j|w|Ow)") + if !isfound(r"([^%]|^)%(a|A|j|w|Ow)", fmt) ccall(:mktime, Int, (Ref{TmStruct},), tm) end end diff --git a/base/loading.jl b/base/loading.jl index 0723313515a324..25ca69a859547c 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -388,7 +388,7 @@ function project_file_name_uuid_path(project_file::String, uuid = dummy_uuid(project_file) path = joinpath("src", "$name.jl") for line in eachline(io) - contains(line, re_section) && break + isfound(re_section, line) && break if (m = match(re_name_to_string, line)) != nothing name = String(m.captures[1]) elseif (m = match(re_uuid_to_string, line)) != nothing @@ -407,7 +407,7 @@ function project_file_manifest_path(project_file::String)::Union{Nothing,String} open(project_file) do io dir = abspath(dirname(project_file)) for line in eachline(io) - contains(line, re_section) && break + isfound(re_section, line) && break if (m = match(re_manifest_to_string, line)) != nothing return normpath(joinpath(dir, m.captures[1])) end @@ -494,9 +494,9 @@ function explicit_project_deps_get(project_file::String, name::String)::Union{Bo state = :top for line in eachline(io) if state == :top - if contains(line, re_section) + if isfound(re_section, line) root_name == name && return root_uuid - state = contains(line, re_section_deps) ? :deps : :other + state = isfound(re_section_deps, line) ? :deps : :other elseif (m = match(re_name_to_string, line)) != nothing root_name = String(m.captures[1]) elseif (m = match(re_uuid_to_string, line)) != nothing @@ -506,7 +506,7 @@ function explicit_project_deps_get(project_file::String, name::String)::Union{Bo if (m = match(re_key_to_string, line)) != nothing m.captures[1] == name && return UUID(m.captures[2]) end - elseif contains(line, re_section) + elseif isfound(re_section, line) state = :deps end end @@ -524,7 +524,7 @@ function explicit_manifest_deps_get(manifest_file::String, where::UUID, name::St uuid = deps = nothing state = :other for line in eachline(io) - if contains(line, re_array_of_tables) + if isfound(re_array_of_tables, line) uuid == where && break uuid = deps = nothing state = :stanza @@ -533,9 +533,9 @@ function explicit_manifest_deps_get(manifest_file::String, where::UUID, name::St uuid = UUID(m.captures[1]) elseif (m = match(re_deps_to_any, line)) != nothing deps = String(m.captures[1]) - elseif contains(line, re_subsection_deps) + elseif isfound(re_subsection_deps, line) state = :deps - elseif contains(line, re_section) + elseif isfound(re_section, line) state = :other end elseif state == :deps && uuid == where @@ -551,7 +551,7 @@ function explicit_manifest_deps_get(manifest_file::String, where::UUID, name::St @warn "Unexpected TOML deps format:\n$deps" return nothing end - contains(deps, repr(name)) || return true + isfound(repr(name), deps) || return true seekstart(io) # rewind IO handle manifest_file_name_uuid(manifest_file, name, io) end diff --git a/base/methodshow.jl b/base/methodshow.jl index 013246e24c54da..4605ae415445c6 100644 --- a/base/methodshow.jl +++ b/base/methodshow.jl @@ -202,7 +202,7 @@ function url(m::Method) (m.file == :null || m.file == :string) && return "" file = string(m.file) line = m.line - line <= 0 || contains(file, r"In\[[0-9]+\]") && return "" + line <= 0 || isfound(r"In\[[0-9]+\]", file) && return "" Sys.iswindows() && (file = replace(file, '\\' => '/')) libgit2_id = PkgId(UUID((0x76f85450_5226_5b5a,0x8eaa_529ad045b433)), "LibGit2") if inbase(M) diff --git a/base/mpfr.jl b/base/mpfr.jl index edb91c90185891..d161df1a750a3c 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -936,7 +936,7 @@ end function _prettify_bigfloat(s::String)::String mantissa, exponent = split(s, 'e') - if !contains(mantissa, '.') + if !isfound('.', mantissa) mantissa = string(mantissa, '.') end mantissa = rstrip(mantissa, '0') diff --git a/base/path.jl b/base/path.jl index 1bb777dd2377dc..a25d1fde697b2f 100644 --- a/base/path.jl +++ b/base/path.jl @@ -78,7 +78,7 @@ end if Sys.iswindows() - isabspath(path::String) = contains(path, path_absolute_re) + isabspath(path::String) = isfound(path_absolute_re, path) else isabspath(path::String) = startswith(path, '/') end @@ -113,7 +113,7 @@ julia> isdirpath("/home/") true ``` """ -isdirpath(path::String) = contains(splitdrive(path)[2], path_directory_re) +isdirpath(path::String) = isfound(path_directory_re, splitdrive(path)[2]) """ splitdir(path::AbstractString) -> (AbstractString, AbstractString) @@ -218,9 +218,9 @@ function joinpath(a::String, b::String) B, b = splitdrive(b) !isempty(B) && A != B && return string(B,b) C = isempty(B) ? A : B - isempty(a) ? string(C,b) : - contains(a[end:end], path_separator_re) ? string(C,a,b) : - string(C,a,pathsep(a,b),b) + isempty(a) ? string(C,b) : + isfound(path_separator_re, a[end:end]) ? string(C,a,b) : + string(C,a,pathsep(a,b),b) end joinpath(a::AbstractString, b::AbstractString) = joinpath(String(a), String(b)) diff --git a/base/regex.jl b/base/regex.jl index 6f75eee72e5f50..f88192621476b8 100644 --- a/base/regex.jl +++ b/base/regex.jl @@ -141,19 +141,19 @@ function getindex(m::RegexMatch, name::Symbol) end getindex(m::RegexMatch, name::AbstractString) = m[Symbol(name)] -function contains(s::AbstractString, r::Regex, offset::Integer=0) +function isfound(r::Regex, s::AbstractString; offset::Integer=0) compile(r) return PCRE.exec(r.regex, String(s), offset, r.match_options, r.match_data) end -function contains(s::SubString, r::Regex, offset::Integer=0) +function isfound(r::Regex, s::SubString; offset::Integer=0) compile(r) return PCRE.exec(r.regex, s, offset, r.match_options, r.match_data) end -(r::Regex)(s) = contains(s, r) +(r::Regex)(s) = isfound(r, s) """ match(r::Regex, s::AbstractString[, idx::Integer[, addopts]]) diff --git a/base/strings/search.jl b/base/strings/search.jl index 72e434d1f96f68..229dd2f677b00f 100644 --- a/base/strings/search.jl +++ b/base/strings/search.jl @@ -425,30 +425,7 @@ julia> findprev("Julia", "JuliaLang", 6) """ findprev(t::AbstractString, s::AbstractString, i::Integer) = _rsearch(s, t, i) -""" - contains(haystack::AbstractString, needle::Union{AbstractString,Regex,Char}) - -Determine whether the second argument is a substring of the first. If `needle` -is a regular expression, checks whether `haystack` contains a match. - -# Examples -```jldoctest -julia> contains("JuliaLang is pretty cool!", "Julia") -true - -julia> contains("JuliaLang is pretty cool!", 'a') -true - -julia> contains("aba", r"a.a") -true - -julia> contains("abba", r"a.a") -false -``` -""" -function contains end - -contains(haystack::AbstractString, needle::Union{AbstractString,Char}) = +isfound(needle::Union{AbstractString,Char}, haystack::AbstractString) = _searchindex(haystack, needle, firstindex(haystack)) != 0 -in(::AbstractString, ::AbstractString) = error("use contains(x,y) for string containment") +in(::AbstractString, ::AbstractString) = error("use isfound(x, y) for string containment") diff --git a/base/uuid.jl b/base/uuid.jl index 533646d59af899..c8f55ad15f480a 100644 --- a/base/uuid.jl +++ b/base/uuid.jl @@ -30,7 +30,7 @@ let groupings = [1:8; 10:13; 15:18; 20:23; 25:36] function UUID(s::AbstractString) s = lowercase(s) - if !contains(s, r"^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$") + if !isfound(r"^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$", s) throw(ArgumentError("Malformed UUID string: $(repr(s))")) end diff --git a/base/version.jl b/base/version.jl index 37ba3c2297c890..39520d9d0de1f3 100644 --- a/base/version.jl +++ b/base/version.jl @@ -21,7 +21,7 @@ struct VersionNumber if ident isa Integer ident >= 0 || throw(ArgumentError("invalid negative pre-release identifier: $ident")) else - if !contains(ident, r"^(?:|[0-9a-z-]*[a-z-][0-9a-z-]*)$"i) || + if !isfound(r"^(?:|[0-9a-z-]*[a-z-][0-9a-z-]*)$"i, ident) || isempty(ident) && !(length(pre)==1 && isempty(bld)) throw(ArgumentError("invalid pre-release identifier: $(repr(ident))")) end @@ -31,7 +31,7 @@ struct VersionNumber if ident isa Integer ident >= 0 || throw(ArgumentError("invalid negative build identifier: $ident")) else - if !contains(ident, r"^(?:|[0-9a-z-]*[a-z-][0-9a-z-]*)$"i) || + if !isfound(r"^(?:|[0-9a-z-]*[a-z-][0-9a-z-]*)$"i, ident) || isempty(ident) && length(bld)!=1 throw(ArgumentError("invalid build identifier: $(repr(ident))")) end @@ -83,7 +83,7 @@ function split_idents(s::AbstractString) idents = split(s, '.') ntuple(length(idents)) do i ident = idents[i] - contains(ident, r"^\d+$") ? parse(UInt64, ident) : String(ident) + isfound(r"^\d+$", ident) ? parse(UInt64, ident) : String(ident) end end diff --git a/contrib/add_license_to_files.jl b/contrib/add_license_to_files.jl index 827680ae95f197..eaa1cdf9530ac8 100644 --- a/contrib/add_license_to_files.jl +++ b/contrib/add_license_to_files.jl @@ -81,7 +81,7 @@ function check_lines!( remove = [] for i in 1:length(lines) line = lines[i] - if contains(line, checktxt) + if isfound(checktxt, line) if strip(line) == strip(prefix * checktxt) || strip(line) == strip(checktxt) push!(remove, i) else diff --git a/contrib/fixup_precompile.jl b/contrib/fixup_precompile.jl index db47ab149f90ef..4a7103bbdc38a8 100644 --- a/contrib/fixup_precompile.jl +++ b/contrib/fixup_precompile.jl @@ -1,5 +1,5 @@ function needs_USE_GPL_LIBS(s::String) - contains(s, "CHOLMOD") && return true + isfound("CHOLMOD", s) && return true return false end @@ -24,7 +24,7 @@ function fixup_precompile(new_precompile_file; merge=false) for line in eachline(file) line = strip(line) # filter out closures, which might have different generated names in different environments - contains(line, r"#[0-9]") && continue + isfound(r"#[0-9]", line) && continue # Other stuff than precompile statements might have been written to STDERR startswith(line, "precompile(Tuple{") || continue # Ok, add the line @@ -65,4 +65,4 @@ elseif length(ARGS) == 2 fixup_precompile(joinpath(pwd(), ARGS[2]); merge = true) else error("invalid arguments") -end \ No newline at end of file +end diff --git a/doc/src/base/arrays.md b/doc/src/base/arrays.md index 11b3c6dbb7b2d0..035f8781b1dbab 100644 --- a/doc/src/base/arrays.md +++ b/doc/src/base/arrays.md @@ -129,6 +129,7 @@ Base.findnext(::Any, ::Integer) Base.findnext(::Function, ::Any, ::Integer) Base.findprev(::Any, ::Integer) Base.findprev(::Function, ::Any, ::Integer) +Base.isfound Base.permutedims Base.permutedims! Base.PermutedDimsArray diff --git a/doc/src/base/strings.md b/doc/src/base/strings.md index d71e7ef5b237fd..62b028ce2c123c 100644 --- a/doc/src/base/strings.md +++ b/doc/src/base/strings.md @@ -35,7 +35,6 @@ Base.findfirst(::AbstractString, ::AbstractString) Base.findnext(::AbstractString, ::AbstractString, ::Integer) Base.findlast(::AbstractString, ::AbstractString) Base.findprev(::AbstractString, ::AbstractString, ::Integer) -Base.contains Base.reverse(::Union{String,SubString{String}}) Base.replace(s::AbstractString, ::Pair) Base.split diff --git a/doc/src/manual/strings.md b/doc/src/manual/strings.md index 50020168e3ccde..f4bcc90dfee884 100644 --- a/doc/src/manual/strings.md +++ b/doc/src/manual/strings.md @@ -534,23 +534,23 @@ julia> findnext(equalto('o'), "xylophone", 5) julia> findnext(equalto('o'), "xylophone", 8) ``` -You can use the [`contains`](@ref) function to check if a substring is contained in a string: +You can use the [`isfound`](@ref) function to check if a substring is found within a string: ```jldoctest -julia> contains("Hello, world.", "world") +julia> isfound("world", "Hello, world.") true -julia> contains("Xylophon", "o") +julia> isfound("o", "Xylophon") true -julia> contains("Xylophon", "a") +julia> isfound("a", "Xylophon") false -julia> contains("Xylophon", 'o') +julia> isfound('o', "Xylophon") true ``` -The last example shows that [`contains`](@ref) can also look for a character literal. +The last example shows that [`isfound`](@ref) can also look for a character literal. Two other handy string functions are [`repeat`](@ref) and [`join`](@ref): @@ -605,20 +605,20 @@ julia> typeof(ans) Regex ``` -To check if a regex matches a string, use [`contains`](@ref): +To check if a regex matches a string, use [`isfound`](@ref): ```jldoctest -julia> contains("not a comment", r"^\s*(?:#|$)") +julia> isfound(r"^\s*(?:#|$)", "not a comment") false -julia> contains("# a comment", r"^\s*(?:#|$)") +julia> isfound(r"^\s*(?:#|$)", "# a comment") true ``` -As one can see here, [`contains`](@ref) simply returns true or false, indicating whether the -given regex matches the string or not. Commonly, however, one wants to know not just whether a -string matched, but also *how* it matched. To capture this information about a match, use the -[`match`](@ref) function instead: +As one can see here, [`isfound`](@ref) simply returns true or false, indicating whether a +match for the given regex was found in the string. Commonly, however, one wants to know not +just whether a string matched, but also *how* it matched. To capture this information about +a match, use the [`match`](@ref) function instead: ```jldoctest julia> match(r"^\s*(?:#|$)", "not a comment") diff --git a/stdlib/DelimitedFiles/src/DelimitedFiles.jl b/stdlib/DelimitedFiles/src/DelimitedFiles.jl index 904ab945669b56..6f58b67d5e48f2 100644 --- a/stdlib/DelimitedFiles/src/DelimitedFiles.jl +++ b/stdlib/DelimitedFiles/src/DelimitedFiles.jl @@ -732,7 +732,7 @@ end # todo: keyword argument for # of digits to print writedlm_cell(io::IO, elt::AbstractFloat, dlm, quotes) = print(io, elt) function writedlm_cell(io::IO, elt::AbstractString, dlm::T, quotes::Bool) where T - if quotes && !isempty(elt) && (('"' in elt) || ('\n' in elt) || ((T <: Char) ? (dlm in elt) : contains(elt, dlm))) + if quotes && !isempty(elt) && (('"' in elt) || ('\n' in elt) || ((T <: Char) ? (dlm in elt) : isfound(dlm, elt))) print(io, '"', replace(elt, r"\"" => "\"\""), '"') else print(io, elt) diff --git a/stdlib/Distributed/test/distributed_exec.jl b/stdlib/Distributed/test/distributed_exec.jl index 190e26d36698bc..e855b634b20df6 100644 --- a/stdlib/Distributed/test/distributed_exec.jl +++ b/stdlib/Distributed/test/distributed_exec.jl @@ -1301,7 +1301,7 @@ let thrown = false thrown = true local b = IOBuffer() showerror(b, e) - @test contains(String(take!(b)), "sqrt will only return") + @test isfound("sqrt will only return", String(take!(b))) end @test thrown end @@ -1375,7 +1375,7 @@ try error("unexpected") catch ex @test isa(ex.captured.ex.exceptions[1].ex, ErrorException) - @test contains(ex.captured.ex.exceptions[1].ex.msg, "BoundsError") + @test isfound("BoundsError", ex.captured.ex.exceptions[1].ex.msg) @test ex.captured.ex.exceptions[2].ex == UndefVarError(:DontExistOn1) end diff --git a/stdlib/InteractiveUtils/src/InteractiveUtils.jl b/stdlib/InteractiveUtils/src/InteractiveUtils.jl index 0c397ba534c8fc..b095c344d9a493 100644 --- a/stdlib/InteractiveUtils/src/InteractiveUtils.jl +++ b/stdlib/InteractiveUtils/src/InteractiveUtils.jl @@ -36,7 +36,7 @@ function varinfo(m::Module=Main, pattern::Regex=r"") (value===Base || value===Main || value===Core ? "" : format_bytes(summarysize(value))), summary(value)] end - for v in sort!(names(m)) if isdefined(m, v) && contains(string(v), pattern) ] + for v in sort!(names(m)) if isdefined(m, v) && isfound(pattern, string(v)) ] pushfirst!(rows, Any["name", "size", "summary"]) @@ -106,13 +106,13 @@ function versioninfo(io::IO=stdout; verbose::Bool=false, packages::Bool=false) println(io, "Environment:") for (k,v) in ENV - if contains(String(k), r"JULIA") + if isfound(r"JULIA", String(k)) println(io, " $(k) = $(v)") end end if verbose for (k,v) in ENV - if contains(String(k), r"PATH|FLAG|^TERM$|HOME") + if isfound(r"PATH|FLAG|^TERM$|HOME", String(k)) println(io, " $(k) = $(v)") end end diff --git a/stdlib/InteractiveUtils/test/runtests.jl b/stdlib/InteractiveUtils/test/runtests.jl index 514ffa91eb64f5..53dcad6141be2b 100644 --- a/stdlib/InteractiveUtils/test/runtests.jl +++ b/stdlib/InteractiveUtils/test/runtests.jl @@ -31,7 +31,7 @@ function warntype_hastag(f, types, tag) iob = IOBuffer() code_warntype(iob, f, types) str = String(take!(iob)) - return contains(str, tag) + return isfound(tag, str) end pos_stable(x) = x > 0 ? x : zero(x) @@ -60,7 +60,7 @@ tag = "ANY" iob = IOBuffer() show(iob, Meta.lower(Main, :(x -> x^2))) str = String(take!(iob)) -@test !contains(str, tag) +@test !isfound(tag, str) # Make sure non used variables are not emphasized has_unused() = (a = rand(5)) @@ -71,7 +71,7 @@ has_unused() = (a = rand(5)) iob = IOBuffer() code_warntype(IOContext(iob, :color => true), x -> (x > 1 ? "foo" : nothing), Tuple{Int64}) str = String(take!(iob)) -@test contains(str, Base.text_colors[Base.warn_color()]) +@test isfound(Base.text_colors[Base.warn_color()], str) # Make sure getproperty and setproperty! works with @code_... macros struct T1234321 @@ -150,7 +150,7 @@ end |:---- | ----:|:------- | """ let v = repr(varinfo(_test_varinfo_)) - @test contains(v, "| x | 8 bytes | Float64 |") + @test isfound("| x | 8 bytes | Float64 |", v) end # Issue 14173 @@ -180,9 +180,9 @@ end versioninfo(buf, verbose=true) ver = read(buf, String) @test startswith(ver, "Julia Version $VERSION") - @test contains(ver, "Environment:") - @test contains(ver, "Package Status:") - @test contains(ver, "no packages installed") + @test isfound("Environment:", ver) + @test isfound("Package Status:", ver) + @test isfound("no packages installed", ver) @test isempty(readdir(dir)) end end @@ -296,7 +296,7 @@ end # module ReflectionTest ix86 = r"i[356]86" -if Sys.ARCH === :x86_64 || contains(string(Sys.ARCH), ix86) +if Sys.ARCH === :x86_64 || isfound(ix86, string(Sys.ARCH)) function linear_foo() x = 4 y = 5 @@ -309,18 +309,18 @@ if Sys.ARCH === :x86_64 || contains(string(Sys.ARCH), ix86) code_native(buf,linear_foo,(), syntax = :att) output=String(take!(buf)) - @test contains(output,rgx) + @test isfound(rgx, output) #test that the code output is intel syntax by checking it has no occurrences of '%' code_native(buf,linear_foo,(), syntax = :intel) output=String(take!(buf)) - @test !contains(output,rgx) + @test !isfound(rgx, output) code_native(buf,linear_foo,()) output=String(take!(buf)) - @test contains(output,rgx) + @test isfound(rgx, output) end using InteractiveUtils: editor diff --git a/stdlib/LibGit2/test/libgit2.jl b/stdlib/LibGit2/test/libgit2.jl index f12cb8cc4d027e..95fe5cc7ddca0a 100644 --- a/stdlib/LibGit2/test/libgit2.jl +++ b/stdlib/LibGit2/test/libgit2.jl @@ -812,10 +812,10 @@ mktempdir() do dir # test showing the commit showstr = split(sprint(show, cmt), "\n") # the time of the commit will vary so just test the first two parts - @test contains(showstr[1], "Git Commit:") - @test contains(showstr[2], "Commit Author: Name: TEST, Email: TEST@TEST.COM, Time:") - @test contains(showstr[3], "Committer: Name: TEST, Email: TEST@TEST.COM, Time:") - @test contains(showstr[4], "SHA:") + @test isfound("Git Commit:", showstr[1]) + @test isfound("Commit Author: Name: TEST, Email: TEST@TEST.COM, Time:", showstr[2]) + @test isfound("Committer: Name: TEST, Email: TEST@TEST.COM, Time:", showstr[3]) + @test isfound("SHA:", showstr[4]) @test showstr[5] == "Message:" @test showstr[6] == commit_msg1 @test LibGit2.revcount(repo, string(commit_oid1), string(commit_oid3)) == (-1,0) @@ -996,7 +996,7 @@ mktempdir() do dir # test showing a GitBlob blob_show_strs = split(sprint(show, blob), "\n") @test blob_show_strs[1] == "GitBlob:" - @test contains(blob_show_strs[2], "Blob id:") + @test isfound("Blob id:", blob_show_strs[2]) @test blob_show_strs[3] == "Contents are binary." blob2 = LibGit2.GitBlob(repo, LibGit2.GitHash(blob)) @@ -1085,9 +1085,9 @@ mktempdir() do dir @test diff_strs[3] == "Number of files: 2" @test diff_strs[4] == "Old file:" @test diff_strs[5] == "DiffFile:" - @test contains(diff_strs[6], "Oid:") - @test contains(diff_strs[7], "Path:") - @test contains(diff_strs[8], "Size:") + @test isfound("Oid:", diff_strs[6]) + @test isfound("Path:", diff_strs[7]) + @test isfound("Size:", diff_strs[8]) @test isempty(diff_strs[9]) @test diff_strs[10] == "New file:" diff --git a/stdlib/Libdl/test/runtests.jl b/stdlib/Libdl/test/runtests.jl index 8a7a7482449619..3c2a26bdd8d972 100644 --- a/stdlib/Libdl/test/runtests.jl +++ b/stdlib/Libdl/test/runtests.jl @@ -16,7 +16,7 @@ if !Sys.iswindows() || Sys.windows_version() >= Sys.WINDOWS_VISTA_VER end end @test length(filter(dlls) do dl - return contains(basename(dl), Regex("^libjulia(?:.*)\\.$(Libdl.dlext)(?:\\..+)?\$")) + return isfound(Regex("^libjulia(?:.*)\\.$(Libdl.dlext)(?:\\..+)?\$"), basename(dl)) end) == 1 # look for something libjulia-like (but only one) # library handle pointer must not be NULL @@ -165,9 +165,9 @@ end # opening a versioned library that does not exist does not result in adding extension twice err = @test_throws ErrorException Libdl.dlopen("./foo.$(Libdl.dlext).0") -@test !contains(err.value.msg, "foo.$(Libdl.dlext).0.$(Libdl.dlext)") +@test !isfound("foo.$(Libdl.dlext).0.$(Libdl.dlext)", err.value.msg) err = @test_throws ErrorException Libdl.dlopen("./foo.$(Libdl.dlext).0.22.1") -@test !contains(err.value.msg, "foo.$(Libdl.dlext).0.22.1.$(Libdl.dlext)") +@test !isfound("foo.$(Libdl.dlext).0.22.1.$(Libdl.dlext)", err.value.msg) # test dlsym let dl = C_NULL diff --git a/stdlib/LinearAlgebra/src/blas.jl b/stdlib/LinearAlgebra/src/blas.jl index 5733fa8ad528b3..9414ae00b7cbfc 100644 --- a/stdlib/LinearAlgebra/src/blas.jl +++ b/stdlib/LinearAlgebra/src/blas.jl @@ -125,7 +125,7 @@ function check() blas = vendor() if blas == :openblas || blas == :openblas64 openblas_config = openblas_get_config() - openblas64 = contains(openblas_config, r".*USE64BITINT.*") + openblas64 = isfound(r".*USE64BITINT.*", openblas_config) if Base.USE_BLAS64 != openblas64 if !openblas64 @error """ diff --git a/stdlib/LinearAlgebra/src/uniformscaling.jl b/stdlib/LinearAlgebra/src/uniformscaling.jl index a153882f1ed709..aab6c0deb689a5 100644 --- a/stdlib/LinearAlgebra/src/uniformscaling.jl +++ b/stdlib/LinearAlgebra/src/uniformscaling.jl @@ -54,7 +54,7 @@ getindex(J::UniformScaling, i::Integer,j::Integer) = ifelse(i==j,J.λ,zero(J.λ) function show(io::IO, J::UniformScaling) s = "$(J.λ)" - if contains(s, r"\w+\s*[\+\-]\s*\w+") + if isfound(r"\w+\s*[\+\-]\s*\w+", s) s = "($s)" end print(io, "$(typeof(J))\n$s*I") diff --git a/stdlib/LinearAlgebra/test/triangular.jl b/stdlib/LinearAlgebra/test/triangular.jl index 284938e1fcd9d3..5fb26e6ae65e1b 100644 --- a/stdlib/LinearAlgebra/test/triangular.jl +++ b/stdlib/LinearAlgebra/test/triangular.jl @@ -539,14 +539,14 @@ end end @testset "special printing of Lower/UpperTriangular" begin - @test contains(sprint(show, MIME"text/plain"(), LowerTriangular(2ones(Int64,3,3))), - r"3×3 (LinearAlgebra\.)?LowerTriangular{Int64,Array{Int64,2}}:\n 2 ⋅ ⋅\n 2 2 ⋅\n 2 2 2") - @test contains(sprint(show, MIME"text/plain"(), UnitLowerTriangular(2ones(Int64,3,3))), - r"3×3 (LinearAlgebra\.)?UnitLowerTriangular{Int64,Array{Int64,2}}:\n 1 ⋅ ⋅\n 2 1 ⋅\n 2 2 1") - @test contains(sprint(show, MIME"text/plain"(), UpperTriangular(2ones(Int64,3,3))), - r"3×3 (LinearAlgebra\.)?UpperTriangular{Int64,Array{Int64,2}}:\n 2 2 2\n ⋅ 2 2\n ⋅ ⋅ 2") - @test contains(sprint(show, MIME"text/plain"(), UnitUpperTriangular(2ones(Int64,3,3))), - r"3×3 (LinearAlgebra\.)?UnitUpperTriangular{Int64,Array{Int64,2}}:\n 1 2 2\n ⋅ 1 2\n ⋅ ⋅ 1") + @test isfound(r"3×3 (LinearAlgebra\.)?LowerTriangular{Int64,Array{Int64,2}}:\n 2 ⋅ ⋅\n 2 2 ⋅\n 2 2 2", + sprint(show, MIME"text/plain"(), LowerTriangular(2ones(Int64,3,3)))) + @test isfound(r"3×3 (LinearAlgebra\.)?UnitLowerTriangular{Int64,Array{Int64,2}}:\n 1 ⋅ ⋅\n 2 1 ⋅\n 2 2 1", + sprint(show, MIME"text/plain"(), UnitLowerTriangular(2ones(Int64,3,3)))) + @test isfound(r"3×3 (LinearAlgebra\.)?UpperTriangular{Int64,Array{Int64,2}}:\n 2 2 2\n ⋅ 2 2\n ⋅ ⋅ 2", + sprint(show, MIME"text/plain"(), UpperTriangular(2ones(Int64,3,3)))) + @test isfound(r"3×3 (LinearAlgebra\.)?UnitUpperTriangular{Int64,Array{Int64,2}}:\n 1 2 2\n ⋅ 1 2\n ⋅ ⋅ 1", + sprint(show, MIME"text/plain"(), UnitUpperTriangular(2ones(Int64,3,3)))) end end # module TestTriangular diff --git a/stdlib/Markdown/src/Common/block.jl b/stdlib/Markdown/src/Common/block.jl index fd6c9de93d1ac0..ad63d7cea33822 100644 --- a/stdlib/Markdown/src/Common/block.jl +++ b/stdlib/Markdown/src/Common/block.jl @@ -211,11 +211,11 @@ function admonition(stream::IO, block::MD) let untitled = r"^([a-z]+)$", # !!! titled = r"^([a-z]+) \"(.*)\"$", # !!! "" line = strip(readline(stream)) - if contains(line, untitled) + if isfound(untitled, line) m = match(untitled, line) # When no title is provided we use CATEGORY_NAME, capitalising it. m.captures[1], ucfirst(m.captures[1]) - elseif contains(line, titled) + elseif isfound(titled, line) m = match(titled, line) # To have a blank TITLE provide an explicit empty string as TITLE. m.captures[1], m.captures[2] @@ -270,12 +270,12 @@ function list(stream::IO, block::MD) indent = isempty(bullet) ? (return false) : length(bullet) # Calculate the starting number and regex to use for bullet matching. initial, regex = - if contains(bullet, BULLETS) + if isfound(BULLETS, bullet) # An unordered list. Use `-1` to flag the list as unordered. -1, BULLETS - elseif contains(bullet, r"^ {0,3}\d+(\.|\))( |$)") + elseif isfound(r"^ {0,3}\d+(\.|\))( |$)", bullet) # An ordered list. Either with `1. ` or `1) ` style numbering. - r = contains(bullet, ".") ? r"^ {0,3}(\d+)\.( |$)" : r"^ {0,3}(\d+)\)( |$)" + r = isfound(".", bullet) ? r"^ {0,3}(\d+)\.( |$)" : r"^ {0,3}(\d+)\)( |$)" Base.parse(Int, match(r, bullet).captures[1]), r else # Failed to match any bullets. This branch shouldn't actually be needed diff --git a/stdlib/Markdown/src/Common/inline.jl b/stdlib/Markdown/src/Common/inline.jl index 63a5fb887c7fa4..b2399e255ba787 100644 --- a/stdlib/Markdown/src/Common/inline.jl +++ b/stdlib/Markdown/src/Common/inline.jl @@ -152,7 +152,7 @@ function _is_mailto(s::AbstractString) length(s) < 6 && return false # slicing strings is a bit risky, but this equality check is safe lowercase(s[1:6]) == "mailto:" || return false - return contains(s[6:end], _email_regex) + return isfound(_email_regex, s[6:end]) end # ––––––––––– diff --git a/stdlib/Markdown/src/render/plain.jl b/stdlib/Markdown/src/render/plain.jl index dbee4dcf33fa68..5d2619e292b88e 100644 --- a/stdlib/Markdown/src/render/plain.jl +++ b/stdlib/Markdown/src/render/plain.jl @@ -120,7 +120,7 @@ plaininline(io::IO, md::Bold) = plaininline(io, "**", md.text, "**") plaininline(io::IO, md::Italic) = plaininline(io, "*", md.text, "*") function plaininline(io::IO, md::Code) - if contains(md.code, "`") + if isfound("`", md.code) n = maximum(length(m.match) for m in eachmatch(r"(`+)", md.code)) s = "`"^((iseven(n) ? 1 : 2) + n) print(io, s, Base.startswith(md.code, "`") ? " " : "") diff --git a/stdlib/Markdown/src/render/rst.jl b/stdlib/Markdown/src/render/rst.jl index 737cf316c88516..44f1bc5eae5670 100644 --- a/stdlib/Markdown/src/render/rst.jl +++ b/stdlib/Markdown/src/render/rst.jl @@ -115,7 +115,7 @@ rstinline(io::IO, md::Vector) = !isempty(md) && rstinline(io, md...) # rstinline(io::IO, md::Image) = rstinline(io, ".. image:: ", md.url) function rstinline(io::IO, md::Link) - if contains(md.url, r":(func|obj|ref|exc|class|const|data):`\.*") + if isfound(r":(func|obj|ref|exc|class|const|data):`\.*", md.url) rstinline(io, md.url) else rstinline(io, "`", md.text, " <", md.url, ">`_") diff --git a/stdlib/Markdown/src/render/terminal/formatting.jl b/stdlib/Markdown/src/render/terminal/formatting.jl index 866fd7e6257299..d9e5ff1e2bceb0 100644 --- a/stdlib/Markdown/src/render/terminal/formatting.jl +++ b/stdlib/Markdown/src/render/terminal/formatting.jl @@ -11,7 +11,7 @@ lines(s) = split(s, "\n") # This could really be more efficient function wrapped_lines(io::IO, s::AbstractString; width = 80, i = 0) - if contains(s, r"\n") + if isfound(r"\n", s) return vcat(map(s->wrapped_lines(io, s, width = width, i = i), split(s, "\n"))...) end ws = words(s) diff --git a/stdlib/Markdown/test/runtests.jl b/stdlib/Markdown/test/runtests.jl index 8512b54324f773..b24076e4bacbe8 100644 --- a/stdlib/Markdown/test/runtests.jl +++ b/stdlib/Markdown/test/runtests.jl @@ -144,16 +144,16 @@ let text = @test Markdown.rst(md) == expected end let html = Markdown.html(md) - @test contains(html, ",<a href=\"#footnote-1\" class=\"footnote\">[1]</a>") - @test contains(html, ".<a href=\"#footnote-note\" class=\"footnote\">[note]</a>") - @test contains(html, "<div class=\"footnote\" id=\"footnote-1\"><p class=\"footnote-title\">1</p>") - @test contains(html, "<div class=\"footnote\" id=\"footnote-note\"><p class=\"footnote-title\">note</p>") + @test isfound(",<a href=\"#footnote-1\" class=\"footnote\">[1]</a>", html) + @test isfound(".<a href=\"#footnote-note\" class=\"footnote\">[note]</a>", html) + @test isfound("<div class=\"footnote\" id=\"footnote-1\"><p class=\"footnote-title\">1</p>", html) + @test isfound("<div class=\"footnote\" id=\"footnote-note\"><p class=\"footnote-title\">note</p>", html) end let latex = Markdown.latex(md) - @test contains(latex, ",\\footnotemark[1]") - @test contains(latex, ".\\footnotemark[note]") - @test contains(latex, "\n\\footnotetext[1]{Footnote text for") - @test contains(latex, "\n\\footnotetext[note]{A longer footnote:\n") + @test isfound(",\\footnotemark[1]", latex) + @test isfound(".\\footnotemark[note]", latex) + @test isfound("\n\\footnotetext[1]{Footnote text for", latex) + @test isfound("\n\\footnotetext[note]{A longer footnote:\n", latex) end end @@ -239,9 +239,9 @@ let doc = Markdown.parse( 3. b """ ) - @test contains(sprint(term, doc), "1. ") - @test contains(sprint(term, doc), "2. ") - @test !contains(sprint(term, doc), "3. ") + @test isfound("1. ", sprint(term, doc)) + @test isfound("2. ", sprint(term, doc)) + @test !isfound("3. ", sprint(term, doc)) end # HTML output diff --git a/stdlib/Pkg/src/read.jl b/stdlib/Pkg/src/read.jl index f1698b1553a09c..1d5e9bc4362041 100644 --- a/stdlib/Pkg/src/read.jl +++ b/stdlib/Pkg/src/read.jl @@ -20,7 +20,7 @@ function available(names=readdir("METADATA")) versdir = joinpath("METADATA", pkg, "versions") isdir(versdir) || continue for ver in readdir(versdir) - contains(ver, Base.VERSION_REGEX) || continue + isfound(Base.VERSION_REGEX, ver) || continue isfile(versdir, ver, "sha1") || continue haskey(pkgs,pkg) || (pkgs[pkg] = Dict{VersionNumber,Available}()) pkgs[pkg][VersionNumber(ver)] = Available( @@ -41,7 +41,7 @@ function latest(names=readdir("METADATA")) isdir(versdir) || continue pkgversions = VersionNumber[] for ver in readdir(versdir) - contains(ver, Base.VERSION_REGEX) || continue + isfound(Base.VERSION_REGEX, ver) || continue isfile(versdir, ver, "sha1") || continue push!(pkgversions, VersionNumber(ver)) end @@ -116,7 +116,7 @@ function ispinned(prepo::LibGit2.GitRepo) LibGit2.isattached(prepo) || return false br = LibGit2.branch(prepo) # note: regex is based on the naming scheme used in Entry.pin() - return contains(br, r"^pinned\.[0-9a-f]{8}\.tmp$") + return isfound(r"^pinned\.[0-9a-f]{8}\.tmp$", br) end function installed_version(pkg::AbstractString, prepo::LibGit2.GitRepo, avail::Dict=available(pkg)) diff --git a/stdlib/Pkg/src/reqs.jl b/stdlib/Pkg/src/reqs.jl index 300ed8d90aeb80..6c5d63d17687e2 100644 --- a/stdlib/Pkg/src/reqs.jl +++ b/stdlib/Pkg/src/reqs.jl @@ -27,7 +27,7 @@ struct Requirement <: Line end isempty(fields) && throw(PkgError("invalid requires entry: $content")) package = popfirst!(fields) - all(field->contains(field, Base.VERSION_REGEX), fields) || + all(field->isfound(Base.VERSION_REGEX, field), fields) || throw(PkgError("invalid requires entry for $package: $content")) versions = map(VersionNumber, fields) issorted(versions) || throw(PkgError("invalid requires entry for $package: $content")) @@ -59,7 +59,7 @@ function read(readable::Vector{<:AbstractString}) lines = Line[] for line in readable line = chomp(line) - push!(lines, contains(line, r"^\s*(?:#|$)") ? Comment(line) : Requirement(line)) + push!(lines, isfound(r"^\s*(?:#|$)", line) ? Comment(line) : Requirement(line)) end return lines end @@ -67,7 +67,7 @@ end function read(readable::Union{IO,Base.AbstractCmd}) lines = Line[] for line in eachline(readable) - push!(lines, contains(line, r"^\s*(?:#|$)") ? Comment(line) : Requirement(line)) + push!(lines, isfound(r"^\s*(?:#|$)", line) ? Comment(line) : Requirement(line)) end return lines end diff --git a/stdlib/Pkg/test/pkg.jl b/stdlib/Pkg/test/pkg.jl index c033d0fae4d6ff..06cf2b7f38851f 100644 --- a/stdlib/Pkg/test/pkg.jl +++ b/stdlib/Pkg/test/pkg.jl @@ -87,7 +87,7 @@ temp_pkg_dir() do end end @test isa(ex,Pkg.PkgError) - @test contains(ex.msg, "Cannot clone Example from notarealprotocol://github.com/JuliaLang/Example.jl.git") + @test isfound("Cannot clone Example from notarealprotocol://github.com/JuliaLang/Example.jl.git", ex.msg) end end @@ -415,16 +415,16 @@ temp_pkg_dir() do # Pkg.build works without the src directory now # but it's probably fine to require it. msg = read(`$(Base.julia_cmd()) --startup-file=no -e 'redirect_stderr(stdout); using Logging; global_logger(SimpleLogger(stdout)); import Pkg; Pkg.build("BuildFail")'`, String) - @test contains(msg, "Building BuildFail") - @test !contains(msg, "Build failed for BuildFail") + @test isfound("Building BuildFail", msg) + @test !isfound("Build failed for BuildFail", msg) open(depsbuild, "w") do fd println(fd, "error(\"Throw build error\")") end msg = read(`$(Base.julia_cmd()) --startup-file=no -e 'redirect_stderr(stdout); using Logging; global_logger(SimpleLogger(stdout)); import Pkg; Pkg.build("BuildFail")'`, String) - @test contains(msg, "Building BuildFail") - @test contains(msg, "Build failed for BuildFail") - @test contains(msg, "Pkg.build(\"BuildFail\")") - @test contains(msg, "Throw build error") + @test isfound("Building BuildFail", msg) + @test isfound("Build failed for BuildFail", msg) + @test isfound("Pkg.build(\"BuildFail\")", msg) + @test isfound("Throw build error", msg) end # issue #15948 @@ -432,8 +432,8 @@ temp_pkg_dir() do Pkg.rm(package) # Remove package if installed @test Pkg.installed(package) === nothing # Registered with METADATA but not installed msg = read(ignorestatus(`$(Base.julia_cmd()) --startup-file=no -e "redirect_stderr(stdout); using Logging; global_logger(SimpleLogger(stdout)); import Pkg; Pkg.build(\"$package\")"`), String) - @test contains(msg, "$package is not an installed package") - @test !contains(msg, "signal (15)") + @test isfound("$package is not an installed package", msg) + @test !isfound("signal (15)", msg) end # issue #20695 @@ -506,7 +506,7 @@ temp_pkg_dir() do Pkg.add("Iterators") Pkg.update("Iterators") end - @test all(!contains(l.message,"updated but were already imported") for l in logs) + @test all(!isfound("updated but were already imported", l.message) for l in logs) # Do it again, because the above Iterators test will update things prematurely LibGit2.with(LibGit2.GitRepo, metadata_dir) do repo @@ -522,9 +522,9 @@ temp_pkg_dir() do logs,_ = Test.collect_test_logs() do Pkg.update("ColorTypes") end - @test any(contains(l, (:info,r"Upgrading ColorTypes: v0\.2\.2 => v\d+\.\d+\.\d+")) for l in logs) - @test any(contains(l, (:info,r"Upgrading Compat: v0\.7\.18 => v\d+\.\d+\.\d+")) for l in logs) - @test !any(contains(l, (:info,r"Upgrading Colors")) for l in logs) + @test any(isfound((:info, r"Upgrading ColorTypes: v0\.2\.2 => v\d+\.\d+\.\d+"), l) for l in logs) + @test any(isfound((:info, r"Upgrading Compat: v0\.7\.18 => v\d+\.\d+\.\d+"), l) for l in logs) + @test !any(isfound((:info, r"Upgrading Colors"), l) for l in logs) @test Pkg.installed("Colors") == v"0.6.4" @@ -547,7 +547,7 @@ temp_pkg_dir() do Pkg.add(package) msg = read(ignorestatus(`$(Base.julia_cmd()) --startup-file=no -e "redirect_stderr(stdout); using Logging; global_logger(SimpleLogger(stdout)); using Example; import Pkg; Pkg.update(\"$package\")"`), String) - @test contains(msg, Regex("- $package.*Restart Julia to use the updated versions","s")) + @test isfound(Regex("- $package.*Restart Julia to use the updated versions","s"), msg) end # Verify that the --startup-file flag is respected by Pkg.build / Pkg.test @@ -572,24 +572,24 @@ temp_pkg_dir() do withenv((Sys.iswindows() ? "USERPROFILE" : "HOME") => home) do code = "redirect_stderr(stdout); using Logging; global_logger(SimpleLogger(stdout)); import Pkg; Pkg.build(\"$package\")" msg = read(`$(Base.julia_cmd()) --startup-file=no -e $code`, String) - @test contains(msg, "JULIA_RC_LOADED defined false") - @test contains(msg, "Main.JULIA_RC_LOADED defined false") + @test isfound("JULIA_RC_LOADED defined false", msg) + @test isfound("Main.JULIA_RC_LOADED defined false", msg) msg = read(`$(Base.julia_cmd()) --startup-file=yes -e $code`, String) - @test contains(msg, "JULIA_RC_LOADED defined false") - @test contains(msg, "Main.JULIA_RC_LOADED defined true") + @test isfound("JULIA_RC_LOADED defined false", msg) + @test isfound("Main.JULIA_RC_LOADED defined true", msg) code = "redirect_stderr(stdout); using Logging; global_logger(SimpleLogger(stdout)); import Pkg; Pkg.test(\"$package\")" msg = read(`$(Base.julia_cmd()) --startup-file=no -e $code`, String) - @test contains(msg, "JULIA_RC_LOADED defined false") - @test contains(msg, "Main.JULIA_RC_LOADED defined false") + @test isfound("JULIA_RC_LOADED defined false", msg) + @test isfound("Main.JULIA_RC_LOADED defined false", msg) # Note: Since both the startup-file and "runtests.jl" are run in the Main # module any global variables created in the startup file can be referenced. msg = read(`$(Base.julia_cmd()) --startup-file=yes -e $code`, String) - @test contains(msg, "JULIA_RC_LOADED defined true") - @test contains(msg, "Main.JULIA_RC_LOADED defined true") + @test isfound("JULIA_RC_LOADED defined true", msg) + @test isfound("Main.JULIA_RC_LOADED defined true", msg) end end @@ -660,7 +660,7 @@ end let io = IOBuffer() Base.showerror(io, Pkg.Entry.PkgTestError("ppp"), backtrace()) - @test !contains(String(take!(io)), "backtrace()") + @test !isfound("backtrace()", String(take!(io))) end @testset "Relative path operations" begin diff --git a/stdlib/Pkg3/bin/utils.jl b/stdlib/Pkg3/bin/utils.jl index 4a84f6af96a13e..8d9d14295eab35 100644 --- a/stdlib/Pkg3/bin/utils.jl +++ b/stdlib/Pkg3/bin/utils.jl @@ -114,5 +114,5 @@ function write_toml(f::Function, names::String...) end end -toml_key(str::String) = contains(str, r"[^\w-]") ? repr(str) : str +toml_key(str::String) = isfound(r"[^\w-]", str) ? repr(str) : str toml_key(strs::String...) = join(map(toml_key, [strs...]), '.') diff --git a/stdlib/Pkg3/src/Operations.jl b/stdlib/Pkg3/src/Operations.jl index c1e71492ecb15d..3bebbd81b2fb0d 100644 --- a/stdlib/Pkg3/src/Operations.jl +++ b/stdlib/Pkg3/src/Operations.jl @@ -494,7 +494,7 @@ function find_stdlib_deps(ctx::Context, path::String) endswith(file, ".jl") || continue filecontent = read(joinpath(root, file), String) for ((uuid, stdlib), r) in zip(ctx.stdlibs, regexps) - if contains(filecontent, r) + if isfound(r, filecontent) stdlib_deps[uuid] = stdlib end end diff --git a/stdlib/Pkg3/src/Pkg2/reqs.jl b/stdlib/Pkg3/src/Pkg2/reqs.jl index 2af7083a8c84b1..1b65073f6dfaf3 100644 --- a/stdlib/Pkg3/src/Pkg2/reqs.jl +++ b/stdlib/Pkg3/src/Pkg2/reqs.jl @@ -25,7 +25,7 @@ struct Requirement <: Line end isempty(fields) && throw(PkgError("invalid requires entry: $content")) package = popfirst!(fields) - all(field->contains(field, Base.VERSION_REGEX), fields) || + all(field->isfound(Base.VERSION_REGEX, field), fields) || throw(PkgError("invalid requires entry for $package: $content")) versions = VersionNumber.(fields) issorted(versions) || throw(PkgError("invalid requires entry for $package: $content")) @@ -36,11 +36,11 @@ end function read(readable::Union{IO,Base.AbstractCmd}) lines = Line[] for line in eachline(readable) - push!(lines, contains(line, r"^\s*(?:#|$)") ? Comment(line) : Requirement(line)) + push!(lines, isfound(r"^\s*(?:#|$)", line) ? Comment(line) : Requirement(line)) end return lines end read(file::AbstractString) = isfile(file) ? open(read,file) : Line[] -end # module \ No newline at end of file +end # module diff --git a/stdlib/Pkg3/src/PlatformEngines.jl b/stdlib/Pkg3/src/PlatformEngines.jl index 5a936f86d090fb..66a03d1878cb4d 100644 --- a/stdlib/Pkg3/src/PlatformEngines.jl +++ b/stdlib/Pkg3/src/PlatformEngines.jl @@ -363,7 +363,7 @@ function parse_7z_list(output::AbstractString) # Find index of " Name". (can't use `findfirst(generator)` until this is # closed: https://github.com/JuliaLang/julia/issues/16884 - header_row = find(contains(l, " Name") && contains(l, " Attr") for l in lines)[1] + header_row = find(isfound(" Name", l) && isfound(" Attr", l) for l in lines)[1] name_idx = search(lines[header_row], "Name")[1] attr_idx = search(lines[header_row], "Attr")[1] - 1 diff --git a/stdlib/Pkg3/src/REPLMode.jl b/stdlib/Pkg3/src/REPLMode.jl index a7a21bc8c346e3..a97d1113f3c8c2 100644 --- a/stdlib/Pkg3/src/REPLMode.jl +++ b/stdlib/Pkg3/src/REPLMode.jl @@ -131,11 +131,11 @@ let uuid = raw"(?i)[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}( end function parse_package(word::AbstractString)::PackageSpec - if contains(word, uuid_re) + if isfound(uuid_re, word) return PackageSpec(UUID(word)) - elseif contains(word, name_re) + elseif isfound(name_re, word) return PackageSpec(String(match(name_re, word).captures[1])) - elseif contains(word, name_uuid_re) + elseif isfound(name_uuid_re, word) m = match(name_uuid_re, word) return PackageSpec(String(m.captures[1]), UUID(m.captures[2])) else diff --git a/stdlib/Pkg3/src/Types.jl b/stdlib/Pkg3/src/Types.jl index 867569932a6bad..f796c32dd378d5 100644 --- a/stdlib/Pkg3/src/Types.jl +++ b/stdlib/Pkg3/src/Types.jl @@ -762,11 +762,11 @@ function find_registered!( open(joinpath(registry, "Registry.toml")) do io # skip forward until [packages] section for line in eachline(io) - contains(line, r"^ \s* \[ \s* packages \s* \] \s* $"x) && break + isfound(r"^ \s* \[ \s* packages \s* \] \s* $"x, line) && break end # find lines with uuid or name we're looking for for line in eachline(io) - contains(line,regex) || continue + isfound(regex, line) || continue m = match(line_re, line) m == nothing && error("misformatted registry.toml package entry: $line") diff --git a/stdlib/Pkg3/test/pkg.jl b/stdlib/Pkg3/test/pkg.jl index b3be6fbdb69699..d6e72975cf804f 100644 --- a/stdlib/Pkg3/test/pkg.jl +++ b/stdlib/Pkg3/test/pkg.jl @@ -147,7 +147,7 @@ temp_pkg_dir() do project_path try Pkg3.add([PackageSpec(TEST_PKG.name, VersionSpec(v"55"))]) catch e - @test contains(sprint(showerror, e), TEST_PKG.name) + @test isfound(TEST_PKG.name, sprint(showerror, e)) end end diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index b2247f30d69694..0f9aec21e52e9d 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -126,7 +126,7 @@ function complete_keyword(s::Union{String,SubString{String}}) end function complete_path(path::AbstractString, pos; use_envpath=false) - if Base.Sys.isunix() && contains(path, r"^~(?:/|$)") + if Base.Sys.isunix() && isfound(r"^~(?:/|$)", path) # if the path is just "~", don't consider the expanded username as a prefix if path == "~" dir, prefix = homedir(), "" @@ -419,7 +419,7 @@ function afterusing(string::String, startpos::Int) r = findfirst(r"\s(gnisu|tropmi)\b", rstr) isempty(r) && return false fr = reverseind(str, last(r)) - return contains(str[fr:end], r"^\b(using|import)\s*((\w+[.])*\w+\s*,\s*)*$") + return isfound(r"^\b(using|import)\s*((\w+[.])*\w+\s*,\s*)*$", str[fr:end]) end function bslash_completions(string, pos) diff --git a/stdlib/REPL/src/docview.jl b/stdlib/REPL/src/docview.jl index 22edebcd79592f..59ad9daa524306 100644 --- a/stdlib/REPL/src/docview.jl +++ b/stdlib/REPL/src/docview.jl @@ -479,7 +479,7 @@ const builtins = ["abstract type", "baremodule", "begin", "break", moduleusings(mod) = ccall(:jl_module_usings, Any, (Any,), mod) -filtervalid(names) = filter(x->!contains(x, r"#"), map(string, names)) +filtervalid(names) = filter(x->!isfound(r"#", x), map(string, names)) accessible(mod::Module) = [filter!(s -> !Base.isdeprecated(mod, s), names(mod, all = true, imported = true)); diff --git a/stdlib/REPL/src/latex_symbols.jl b/stdlib/REPL/src/latex_symbols.jl index 339b30496d81ba..96f44381ae7095 100644 --- a/stdlib/REPL/src/latex_symbols.jl +++ b/stdlib/REPL/src/latex_symbols.jl @@ -25,7 +25,7 @@ for c in child_nodes(root(xdoc)) id = attribute(ce, "id") U = string(map(s -> Char(parse(Int, s, base = 16)), split(id[2:end], "-"))...) - if contains(L, r"^\\[A-Za-z]+$") && !isa(U,String) + if isfound(r"^\\[A-Za-z]+$", L) && !isa(U,String) if L in Ls println("# duplicated symbol $L ($id)") else diff --git a/stdlib/REPL/test/repl.jl b/stdlib/REPL/test/repl.jl index 01383edde18054..ee876d362de159 100644 --- a/stdlib/REPL/test/repl.jl +++ b/stdlib/REPL/test/repl.jl @@ -119,8 +119,8 @@ fake_repl() do stdin_write, stdout_read, repl # readuntil(stdout_read, "shell> ") # write(stdin_write, "echo hello >/dev/null\n") # let s = readuntil(stdout_read, "\n", keep=true) - # @test contains(s, "shell> ") # make sure we echoed the prompt - # @test contains(s, "echo hello >/dev/null") # make sure we echoed the input + # @test isfound("shell> ", s) # make sure we echoed the prompt + # @test isfound("echo hello >/dev/null", s) # make sure we echoed the input # end # @test readuntil(stdout_read, "\n", keep=true) == "\e[0m\n" #end @@ -131,8 +131,8 @@ fake_repl() do stdin_write, stdout_read, repl readuntil(stdout_read, "shell> ") write(stdin_write, "'\n") # invalid input s = readuntil(stdout_read, "\n") - @test contains(s, "shell> ") # check for the echo of the prompt - @test contains(s, "'") # check for the echo of the input + @test isfound("shell> ", s) # check for the echo of the prompt + @test isfound("'", s) # check for the echo of the input s = readuntil(stdout_read, "\n\n") @test startswith(s, "\e[0mERROR: unterminated single quote\nStacktrace:\n [1] ") || startswith(s, "\e[0m\e[1m\e[91mERROR: \e[39m\e[22m\e[91munterminated single quote\e[39m\nStacktrace:\n [1] ") @@ -146,8 +146,8 @@ fake_repl() do stdin_write, stdout_read, repl # readuntil(stdout_read, "shell> ") # write(stdin_write, "echo \$123 >$tmp\n") # let s = readuntil(stdout_read, "\n") - # @test contains(s, "shell> ") # make sure we echoed the prompt - # @test contains(s, "echo \$123 >$tmp") # make sure we echoed the input + # @test isfound("shell> ", s) # make sure we echoed the prompt + # @test isfound("echo \$123 >$tmp", s) # make sure we echoed the input # end # @test readuntil(stdout_read, "\n", keep=true) == "\e[0m\n" # @test read(tmp, String) == "123\n" @@ -173,11 +173,11 @@ fake_repl() do stdin_write, stdout_read, repl # if shell width is precisely the text width, # we may print some extra characters to fix the cursor state s = readuntil(stdout_read, "\n", keep=true) - @test contains(s, "shell> ") + @test isfound("shell> ", s) s = readuntil(stdout_read, "\n", keep=true) @test s == "\r\r\n" else - @test contains(s, "shell> ") + @test isfound("shell> ", s) end s = readuntil(stdout_read, "\n", keep=true) @test s == "\e[0m\n" # the child has exited @@ -193,7 +193,7 @@ fake_repl() do stdin_write, stdout_read, repl let write(stdin_write, "\0\n") s = readuntil(stdout_read, "\n\n") - @test !contains(s, "invalid character") + @test !isfound("invalid character", s) end # Test that accepting a REPL result immediately shows up, not @@ -699,7 +699,7 @@ function test19864() REPL.print_response(buf, Error19864(), [], false, false, nothing) return String(take!(buf)) end -@test contains(test19864(), "correct19864") +@test isfound("correct19864", test19864()) # Test containers in error messages are limited #18726 let io = IOBuffer() @@ -837,28 +837,27 @@ for keys = [altkeys, merge(altkeys...)], # Check that the correct prompt was displayed output = readuntil(stdout_read, "1 * 1;", keep=true) - @test !contains(LineEdit.prompt_string(altprompt), output) - @test !contains("julia> ", output) + @test !isfound(output, LineEdit.prompt_string(altprompt)) + @test !isfound(output, "julia> ") # Check the history file history = read(histfile, String) - @test contains(history, - r""" - ^\#\ time:\ .*\n - \#\ mode:\ julia\n - \t1\ \+\ 1;\n - \#\ time:\ .*\n - \#\ mode:\ julia\n - \tmulti=2;\n - \tline=2;\n - \#\ time:\ .*\n - \#\ mode:\ julia\n - \tmulti=3;\n - \tline=1;\n - \#\ time:\ .*\n - \#\ mode:\ julia\n - \t1\ \*\ 1;\n$ - """xm) + @test isfound(r""" + ^\#\ time:\ .*\n + \#\ mode:\ julia\n + \t1\ \+\ 1;\n + \#\ time:\ .*\n + \#\ mode:\ julia\n + \tmulti=2;\n + \tline=2;\n + \#\ time:\ .*\n + \#\ mode:\ julia\n + \tmulti=3;\n + \tline=1;\n + \#\ time:\ .*\n + \#\ mode:\ julia\n + \t1\ \*\ 1;\n$ + """xm, history) end finally rm(histfile, force=true) diff --git a/stdlib/REPL/test/replcompletions.jl b/stdlib/REPL/test/replcompletions.jl index d780ea2d47624a..a2b80e814eca8a 100644 --- a/stdlib/REPL/test/replcompletions.jl +++ b/stdlib/REPL/test/replcompletions.jl @@ -440,7 +440,7 @@ let s = "CompletionFoo.kwtest( " c, r, res = test_complete(s) @test !res @test length(c) == 1 - @test contains(c[1], "x, y, w...") + @test isfound("x, y, w...", c[1]) end # Test of inference based getfield completion diff --git a/stdlib/Serialization/test/runtests.jl b/stdlib/Serialization/test/runtests.jl index 0a3e66dadf0dbc..591079b87ac0cd 100644 --- a/stdlib/Serialization/test/runtests.jl +++ b/stdlib/Serialization/test/runtests.jl @@ -442,8 +442,8 @@ using .Shell, .Instance1 io = IOBuffer() serialize(io, foo) str = String(take!(io)) -@test !contains(str, "Instance1") -@test contains(str, "Shell") +@test !isfound("Instance1", str) +@test isfound("Shell", str) end # module Test13452 diff --git a/stdlib/SparseArrays/test/sparsevector.jl b/stdlib/SparseArrays/test/sparsevector.jl index 268263191cb78e..79eff93e09a380 100644 --- a/stdlib/SparseArrays/test/sparsevector.jl +++ b/stdlib/SparseArrays/test/sparsevector.jl @@ -41,9 +41,9 @@ end end end @testset "show" begin - @test contains(string(spv_x1), "1.25") - @test contains(string(spv_x1), "-0.75") - @test contains(string(spv_x1), "3.5") + @test isfound("1.25", string(spv_x1)) + @test isfound("-0.75", string(spv_x1)) + @test isfound("3.5", string(spv_x1)) end ### Comparison helper to ensure exact equality with internal structure diff --git a/stdlib/SuiteSparse/test/cholmod.jl b/stdlib/SuiteSparse/test/cholmod.jl index 08afc74660832c..01c962af78b9bd 100644 --- a/stdlib/SuiteSparse/test/cholmod.jl +++ b/stdlib/SuiteSparse/test/cholmod.jl @@ -631,8 +631,8 @@ GC.gc() @testset "Issue 11747 - Wrong show method defined for FactorComponent" begin v = cholfact(sparse(Float64[ 10 1 1 1; 1 10 0 0; 1 0 10 0; 1 0 0 10])).L for s in (sprint(show, MIME("text/plain"), v), sprint(show, v)) - @test contains(s, "method: simplicial") - @test !contains(s, "#undef") + @test isfound("method: simplicial", s) + @test !isfound("#undef", s) end end diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index bdffcc68808a35..55549bf8e74003 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -533,8 +533,8 @@ end # Test for warning messages (deprecated) -contains_warn(output, s::AbstractString) = contains(output, s) -contains_warn(output, s::Regex) = contains(output, s) +contains_warn(output, s::AbstractString) = isfound(s, output) +contains_warn(output, s::Regex) = isfound(s, output) contains_warn(output, s::Function) = s(output) contains_warn(output, S::Union{AbstractArray,Tuple}) = all(s -> contains_warn(output, s), S) diff --git a/stdlib/Test/src/logging.jl b/stdlib/Test/src/logging.jl index b02bdadcd481c4..6d5270104d23f6 100644 --- a/stdlib/Test/src/logging.jl +++ b/stdlib/Test/src/logging.jl @@ -3,7 +3,7 @@ using Logging import Logging: Info, shouldlog, handle_message, min_enabled_level, catch_exceptions -import Base: contains +import Base: isfound #------------------------------------------------------------------------------- # Log records @@ -113,7 +113,7 @@ corresponding to the arguments to passed to `AbstractLogger` via the Elements which are present will be matched pairwise with the log record fields using `==` by default, with the special cases that `Symbol`s may be used for the standard log levels, and `Regex`s in the pattern will match string or -Symbol fields using `contains`. +Symbol fields using `isfound`. # Examples @@ -181,9 +181,9 @@ function match_logs(f, patterns...; match_mode::Symbol=:all, kwargs...) logs,value = collect_test_logs(f; kwargs...) if match_mode == :all didmatch = length(logs) == length(patterns) && - all(contains(l,p) for (p,l) in zip(patterns, logs)) + all(isfound(p, l) for (p,l) in zip(patterns, logs)) elseif match_mode == :any - didmatch = all(any(contains(l,p) for l in logs) for p in patterns) + didmatch = all(any(isfound(p, l) for l in logs) for p in patterns) end didmatch,logs,value end @@ -202,12 +202,12 @@ function parse_level(level::Symbol) end logfield_contains(a, b) = a == b -logfield_contains(a, r::Regex) = contains(a, r) -logfield_contains(a::Symbol, r::Regex) = contains(String(a), r) +logfield_contains(a, r::Regex) = isfound(r, a) +logfield_contains(a::Symbol, r::Regex) = isfound(r, String(a)) logfield_contains(a::LogLevel, b::Symbol) = a == parse_level(b) logfield_contains(a, b::Ignored) = true -function contains(r::LogRecord, pattern::Tuple) +function isfound(pattern::Tuple, r::LogRecord) stdfields = (r.level, r.message, r._module, r.group, r.id, r.file, r.line) all(logfield_contains(f, p) for (f, p) in zip(stdfields[1:length(pattern)], pattern)) end diff --git a/stdlib/Test/test/runtests.jl b/stdlib/Test/test/runtests.jl index e661a6bcb7736a..9be227a0166468 100644 --- a/stdlib/Test/test/runtests.jl +++ b/stdlib/Test/test/runtests.jl @@ -119,87 +119,87 @@ let fails = @testset NoThrowTestSet begin end let str = sprint(show, fails[1]) - @test contains(str, "Expression: error()") - @test contains(str, "Thrown: ErrorException") + @test isfound("Expression: error()", str) + @test isfound("Thrown: ErrorException", str) end let str = sprint(show, fails[2]) - @test contains(str, "Expression: 1 + 1") - @test contains(str, "No exception thrown") + @test isfound("Expression: 1 + 1", str) + @test isfound("No exception thrown", str) end let str = sprint(show, fails[3]) - @test contains(str, "Expression: 1 + 1 == 2 + 2") - @test contains(str, "Evaluated: 2 == 4") + @test isfound("Expression: 1 + 1 == 2 + 2", str) + @test isfound("Evaluated: 2 == 4", str) end let str = sprint(show, fails[4]) - @test contains(str, "Expression: 1 / 1 ≈ 2 / 1") - @test contains(str, "Evaluated: 1.0 ≈ 2.0") + @test isfound("Expression: 1 / 1 ≈ 2 / 1", str) + @test isfound("Evaluated: 1.0 ≈ 2.0", str) end let str = sprint(show, fails[5]) - @test contains(str, "Expression: 1 + 0 == 2 + 0 == 3 + 0") - @test contains(str, "Evaluated: 1 == 2 == 3") + @test isfound("Expression: 1 + 0 == 2 + 0 == 3 + 0", str) + @test isfound("Evaluated: 1 == 2 == 3", str) end let str = sprint(show, fails[6]) - @test contains(str, "Expression: 1 - 2 == 2 - 1") - @test contains(str, "Evaluated: -1 == 1") + @test isfound("Expression: 1 - 2 == 2 - 1", str) + @test isfound("Evaluated: -1 == 1", str) end let str = sprint(show, fails[7]) - @test contains(str, "Expression: (==)(1:2...)") - @test !contains(str, "Evaluated") + @test isfound("Expression: (==)(1:2...)", str) + @test !isfound("Evaluated", str) end let str = sprint(show, fails[8]) - @test contains(str, "Expression: isequal(0 / 0, 1 / 0)") - @test contains(str, "Evaluated: isequal(NaN, Inf)") + @test isfound("Expression: isequal(0 / 0, 1 / 0)", str) + @test isfound("Evaluated: isequal(NaN, Inf)", str) end let str = sprint(show, fails[9]) - @test contains(str, "Expression: isequal(1:2...)") - @test contains(str, "Evaluated: isequal(1, 2)") + @test isfound("Expression: isequal(1:2...)", str) + @test isfound("Evaluated: isequal(1, 2)", str) end let str = sprint(show, fails[10]) - @test contains(str, "Expression: isapprox(0 / 1, -1 / 0)") - @test contains(str, "Evaluated: isapprox(0.0, -Inf)") + @test isfound("Expression: isapprox(0 / 1, -1 / 0)", str) + @test isfound("Evaluated: isapprox(0.0, -Inf)", str) end let str = sprint(show, fails[11]) - @test contains(str, "Expression: isapprox(1 / 2, 2 / 1, atol=1 / 1)") - @test contains(str, "Evaluated: isapprox(0.5, 2.0; atol=1.0)") + @test isfound("Expression: isapprox(1 / 2, 2 / 1, atol=1 / 1)", str) + @test isfound("Evaluated: isapprox(0.5, 2.0; atol=1.0)", str) end let str = sprint(show, fails[12]) - @test contains(str, "Expression: isapprox(1 - 2, 2 - 1; atol=1 - 1)") - @test contains(str, "Evaluated: isapprox(-1, 1; atol=0)") + @test isfound("Expression: isapprox(1 - 2, 2 - 1; atol=1 - 1)", str) + @test isfound("Evaluated: isapprox(-1, 1; atol=0)", str) end let str = sprint(show, fails[13]) - @test contains(str, "Expression: isapprox(1, 2; k...)") - @test contains(str, "Evaluated: isapprox(1, 2; atol=0, nans=true)") + @test isfound("Expression: isapprox(1, 2; k...)", str) + @test isfound("Evaluated: isapprox(1, 2; atol=0, nans=true)", str) end let str = sprint(show, fails[14]) - @test contains(str, "Unexpected Pass") - @test contains(str, "Expression: true") + @test isfound("Unexpected Pass", str) + @test isfound("Expression: true", str) end let str = sprint(show, fails[15]) - @test contains(str, "Expression: ==(1, 1:2...)") - @test contains(str, "MethodError: no method matching ==(::$Int, ::$Int, ::$Int)") + @test isfound("Expression: ==(1, 1:2...)", str) + @test isfound("MethodError: no method matching ==(::$Int, ::$Int, ::$Int)", str) end end @testset "printing of a TestSetException" begin tse_str = sprint(show, Test.TestSetException(1, 2, 3, 4, Vector{Union{Test.Error, Test.Fail}}())) - @test contains(tse_str, "1 passed") - @test contains(tse_str, "2 failed") - @test contains(tse_str, "3 errored") - @test contains(tse_str, "4 broken") + @test isfound("1 passed", tse_str) + @test isfound("2 failed", tse_str) + @test isfound("3 errored", tse_str) + @test isfound("4 broken", tse_str) end @test Test.finish(Test.FallbackTestSet()) !== nothing @@ -513,7 +513,7 @@ Base.getindex(a::SillyArray, i) = rand() > 0.5 ? 0 : false @testset "@inferred works with A[i] expressions" begin @test @inferred((1:3)[2]) == 2 test_result = @test_throws ErrorException @inferred(SillyArray()[2]) - @test contains(test_result.value.msg, "Bool") + @test isfound("Bool", test_result.value.msg) end # Issue #14928 # Make sure abstract error type works. @@ -550,30 +550,30 @@ end local msg = read(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no --color=no $f`), stderr=devnull), String) # NOTE: This test depends on the code generated by @testset getting compiled, # to get good backtraces. If it fails, check the implementation of `testset_beginend`. - @test !contains(msg, "do_test(") - @test !contains(msg, "include(") - @test contains(msg, "at " * f * ":3") - @test contains(msg, "at " * f * ":4") + @test !isfound("do_test(", msg) + @test !isfound("include(", msg) + @test isfound("at " * f * ":3", msg) + @test isfound("at " * f * ":4", msg) rm(f; force=true) end let io = IOBuffer() exc = Test.TestSetException(1,2,3,4,Vector{Union{Test.Error, Test.Fail}}()) Base.showerror(io, exc, backtrace()) - @test !contains(String(take!(io)), "backtrace()") + @test !isfound("backtrace()", String(take!(io))) end @testset "#19750" begin io = IOBuffer() exc = Test.TestSetException(1,2,3,4,Vector{Union{Test.Error, Test.Fail}}()) Base.showerror(io, exc, backtrace()) - @test !contains(String(take!(io)), "backtrace()") + @test !isfound("backtrace()", String(take!(io))) exc = Test.FallbackTestSetException("msg") Base.showerror(io, exc, backtrace()) str = String(take!(io)) - @test contains(str, "msg") - @test !contains(str, "backtrace()") + @test isfound("msg", str) + @test !isfound("backtrace()", str) end let msg = read(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no --color=no -e ' @@ -595,15 +595,14 @@ let msg = read(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no --co @test foo(fill(1., 4)) == 15 end end'`), stderr=devnull), String) - @test contains(msg, - """ + @test isfound(""" Test Summary: | Pass Fail Total Foo Tests | 2 2 4 Animals | 1 1 2 Felines | 1 1 Canines | 1 1 Arrays | 1 1 2 - """) + """, msg) end # 20489 @@ -646,9 +645,9 @@ end """) local msg = read(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no --color=no $f`), stderr=devnull), String) - @test contains(msg, "at " * f * ":" * "3") - @test contains(msg, "at " * f * ":" * "4") - @test contains(msg, "at " * f * ":" * "5") + @test isfound("at " * f * ":" * "3", msg) + @test isfound("at " * f * ":" * "4", msg) + @test isfound("at " * f * ":" * "5", msg) rm(f; force=true) end @@ -663,14 +662,14 @@ end x, y = 0.9, 0.1 @test x ≈ y atol=0.01 """) - @test contains(msg, "Evaluated: 0.9 ≈ 0.1 (atol=0.01)") + @test isfound("Evaluated: 0.9 ≈ 0.1 (atol=0.01)", msg) msg = f(""" using Test x, y = 0.9, 0.1 @test x ≈ y nans=true atol=0.01 """) - @test contains(msg, "Evaluated: 0.9 ≈ 0.1 (nans=true, atol=0.01)") + @test isfound("Evaluated: 0.9 ≈ 0.1 (nans=true, atol=0.01)", msg) end @testset "@test_logs" begin @@ -810,7 +809,7 @@ end """) run(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no --color=no $f`), stderr=err)) msg = read(err, String) - @test contains(msg, "Expected `desc` to be an AbstractTestSet, it is a String") + @test isfound("Expected `desc` to be an AbstractTestSet, it is a String", msg) rm(f; force=true) end diff --git a/test/backtrace.jl b/test/backtrace.jl index 4477dd1e98be20..a500d7d1977605 100644 --- a/test/backtrace.jl +++ b/test/backtrace.jl @@ -161,5 +161,5 @@ end let st = stacktrace(bt23971) @test StackTraces.is_top_level_frame(st[1]) @test string(st[1].file) == @__FILE__ - @test !contains(string(st[2].file), "missing") + @test !isfound("missing", string(st[2].file)) end diff --git a/test/char.jl b/test/char.jl index d1e1288ef11cf4..6287d57d580b99 100644 --- a/test/char.jl +++ b/test/char.jl @@ -232,7 +232,7 @@ end end @test sprint(show, c) == rep if Base.isoverlong(c) - @test contains(sprint(show, "text/plain", c), rep*": [overlong]") + @test isfound(rep*": [overlong]", sprint(show, "text/plain", c)) end end diff --git a/test/cmdlineargs.jl b/test/cmdlineargs.jl index a40767b2855e1f..97be90f5273a5f 100644 --- a/test/cmdlineargs.jl +++ b/test/cmdlineargs.jl @@ -222,26 +222,26 @@ let exename = `$(Base.julia_cmd()) --sysimage-native-code=yes --startup-file=no` let code = writereadpipeline("code_llvm(stdout, +, (Int64, Int64), false, true)", `$exename -g0`) @test code[2] code = code[1] - @test contains(code, "llvm.module.flags") - @test !contains(code, "llvm.dbg.cu") - @test !contains(code, "int.jl") - @test !contains(code, "Int64") + @test isfound("llvm.module.flags", code) + @test !isfound("llvm.dbg.cu", code) + @test !isfound("int.jl", code) + @test !isfound("Int64", code) end let code = writereadpipeline("code_llvm(stdout, +, (Int64, Int64), false, true)", `$exename -g1`) @test code[2] code = code[1] - @test contains(code, "llvm.module.flags") - @test contains(code, "llvm.dbg.cu") - @test contains(code, "int.jl") - @test !contains(code, "Int64") + @test isfound("llvm.module.flags", code) + @test isfound("llvm.dbg.cu", code) + @test isfound("int.jl", code) + @test !isfound("Int64", code) end let code = writereadpipeline("code_llvm(stdout, +, (Int64, Int64), false, true)", `$exename -g2`) @test code[2] code = code[1] - @test contains(code, "llvm.module.flags") - @test contains(code, "llvm.dbg.cu") - @test contains(code, "int.jl") - @test contains(code, "\"Int64\"") + @test isfound("llvm.module.flags", code) + @test isfound("llvm.dbg.cu", code) + @test isfound("int.jl", code) + @test isfound("\"Int64\"", code) end # --check-bounds @@ -445,9 +445,9 @@ let exename = joinpath(Sys.BINDIR, Base.julia_exename()), p = run(pipeline(`$exename --sysimage=$nonexist_image`, stderr=err), wait=false) close(err.in) let s = read(err, String) - @test contains(s, "ERROR: could not load library \"$nonexist_image\"\n") - @test !contains(s, "Segmentation fault") - @test !contains(s, "EXCEPTION_ACCESS_VIOLATION") + @test isfound("ERROR: could not load library \"$nonexist_image\"\n", s) + @test !isfound("Segmentation fault", s) + @test !isfound("EXCEPTION_ACCESS_VIOLATION", s) end @test !success(p) @test !Base.process_signaled(p) @@ -503,7 +503,7 @@ for precomp in ("yes", "no") -E 'include("____nonexistent_file")'`) @test !success @test out == "" - @test contains(bt, "include_relative(::Module, ::String) at $(joinpath(".", "loading.jl"))") + @test isfound("include_relative(::Module, ::String) at $(joinpath(".", "loading.jl"))", bt) lno = match(r"at \.[\/\\]loading\.jl:(\d+)", bt) @test length(lno.captures) == 1 @test parse(Int, lno.captures[1]) > 0 diff --git a/test/codegen.jl b/test/codegen.jl index 475d2e1abe973a..2c960a410988e9 100644 --- a/test/codegen.jl +++ b/test/codegen.jl @@ -21,7 +21,7 @@ get_llvm_noopt(@nospecialize(f), @nospecialize(t), strip_ir_metadata=true, dump_ if opt_level > 0 # Make sure getptls call is removed at IR level with optimization on - @test !contains(get_llvm(identity, Tuple{String}), " call ") + @test !isfound(" call ", get_llvm(identity, Tuple{String})) end jl_string_ptr(s::String) = ccall(:jl_string_ptr, Ptr{UInt8}, (Any,), s) @@ -36,7 +36,7 @@ function test_loads_no_call(ir, load_types) end continue end - @test !contains(line, " call ") + @test !isfound(" call ", line) load_split = split(line, " load ", limit=2) if !coverage && length(load_split) >= 2 @test load_idx <= length(load_types) @@ -89,7 +89,7 @@ end if opt_level > 0 # Make sure `jl_string_ptr` is inlined - @test !contains(get_llvm(jl_string_ptr, Tuple{String}), " call ") + @test !isfound(" call ", get_llvm(jl_string_ptr, Tuple{String})) s = "aaa" @test jl_string_ptr(s) == pointer_from_objref(s) + sizeof(Int) # String @@ -172,23 +172,23 @@ breakpoint_ptrstruct(a::RealStruct) = ccall(:jl_breakpoint, Cvoid, (Ref{PtrStruct},), a) if opt_level > 0 - @test !contains(get_llvm(pointer_not_safepoint, Tuple{}), "%gcframe") + @test !isfound("%gcframe", get_llvm(pointer_not_safepoint, Tuple{})) compare_large_struct_ir = get_llvm(compare_large_struct, Tuple{typeof(create_ref_struct())}) - @test contains(compare_large_struct_ir, "call i32 @memcmp") - @test !contains(compare_large_struct_ir, "%gcframe") + @test isfound("call i32 @memcmp", compare_large_struct_ir) + @test !isfound("%gcframe", compare_large_struct_ir) - @test contains(get_llvm(MutableStruct, Tuple{}), "jl_gc_pool_alloc") + @test isfound(Tuple{}, get_llvm(MutableStruct), "jl_gc_pool_alloc") breakpoint_mutable_ir = get_llvm(breakpoint_mutable, Tuple{MutableStruct}) - @test !contains(breakpoint_mutable_ir, "%gcframe") - @test !contains(breakpoint_mutable_ir, "jl_gc_pool_alloc") + @test !isfound("%gcframe", breakpoint_mutable_ir) + @test !isfound("jl_gc_pool_alloc", breakpoint_mutable_ir) breakpoint_badref_ir = get_llvm(breakpoint_badref, Tuple{MutableStruct}) - @test !contains(breakpoint_badref_ir, "%gcframe") - @test !contains(breakpoint_badref_ir, "jl_gc_pool_alloc") + @test !isfound("%gcframe", breakpoint_badref_ir) + @test !isfound("jl_gc_pool_alloc", breakpoint_badref_ir) breakpoint_ptrstruct_ir = get_llvm(breakpoint_ptrstruct, Tuple{RealStruct}) - @test !contains(breakpoint_ptrstruct_ir, "%gcframe") - @test !contains(breakpoint_ptrstruct_ir, "jl_gc_pool_alloc") + @test !isfound("%gcframe", breakpoint_ptrstruct_ir) + @test !isfound("jl_gc_pool_alloc", breakpoint_ptrstruct_ir) end function two_breakpoint(a::Float64) @@ -206,19 +206,19 @@ end if opt_level > 0 breakpoint_f64_ir = get_llvm((a)->ccall(:jl_breakpoint, Cvoid, (Ref{Float64},), a), Tuple{Float64}) - @test !contains(breakpoint_f64_ir, "jl_gc_pool_alloc") + @test !isfound("jl_gc_pool_alloc", breakpoint_f64_ir) breakpoint_any_ir = get_llvm((a)->ccall(:jl_breakpoint, Cvoid, (Ref{Any},), a), Tuple{Float64}) - @test contains(breakpoint_any_ir, "jl_gc_pool_alloc") + @test isfound("jl_gc_pool_alloc", breakpoint_any_ir) two_breakpoint_ir = get_llvm(two_breakpoint, Tuple{Float64}) - @test !contains(two_breakpoint_ir, "jl_gc_pool_alloc") - @test contains(two_breakpoint_ir, "llvm.lifetime.end") + @test !isfound("jl_gc_pool_alloc", two_breakpoint_ir) + @test isfound("llvm.lifetime.end", two_breakpoint_ir) @test load_dummy_ref(1234) === 1234 load_dummy_ref_ir = get_llvm(load_dummy_ref, Tuple{Int}) - @test !contains(load_dummy_ref_ir, "jl_gc_pool_alloc") + @test !isfound("jl_gc_pool_alloc", load_dummy_ref_ir) # Hopefully this is reliable enough. LLVM should be able to optimize this to a direct return. - @test contains(load_dummy_ref_ir, "ret $Iptr %0") + @test isfound("ret $Iptr %0", load_dummy_ref_ir) end # Issue 22770 @@ -308,11 +308,11 @@ g24108(x::B24108) = f24108(x.x.x) @test g22421_2(Ref(7), Ref(8), false) === 24 if opt_level > 0 - @test !contains(get_llvm(g22421_1, Tuple{Base.RefValue{Int},Base.RefValue{Int},Bool}), - "%gcframe") - @test !contains(get_llvm(g22421_2, Tuple{Base.RefValue{Int},Base.RefValue{Int},Bool}), - "%gcframe") - @test !contains(get_llvm(g24108, Tuple{B24108}), "%gcframe") + @test !isfound("%gcframe", + get_llvm(g22421_1, Tuple{Base.RefValue{Int},Base.RefValue{Int},Bool})) + @test !isfound("%gcframe", + get_llvm(g22421_2, Tuple{Base.RefValue{Int},Base.RefValue{Int},Bool})) + @test !isfound("%gcframe", get_llvm(g24108, Tuple{B24108})) end # Issue 24632 @@ -323,8 +323,8 @@ end # A bit coarse-grained perhaps, but ok for now. What we want to check is that the load from # the semi-boxed union on the if-branch of the `isa` is not annotated !nonnull -@test contains(get_llvm_noopt(foo24632, (Bool,), false), "!dereferenceable_or_null") -@test !contains(get_llvm_noopt(foo24632, (Bool,), false), "!nonnull") +@test isfound("!dereferenceable_or_null", get_llvm_noopt(foo24632, (Bool,), false)) +@test !isfound("!nonnull", get_llvm_noopt(foo24632, (Bool,), false)) str_22330 = """ Base.convert(::Type{Array{T,n}}, a::Array) where {T<:Number,n} = diff --git a/test/compile.jl b/test/compile.jl index da4b8853bce54a..a65f3c95e19b7b 100644 --- a/test/compile.jl +++ b/test/compile.jl @@ -273,7 +273,7 @@ try error("__precompile__ disabled test failed") catch exc isa(exc, ErrorException) || rethrow(exc) - contains(exc.msg, "__precompile__(false)") && rethrow(exc) + isfound("__precompile__(false)", exc.msg) && rethrow(exc) end # Issue #12720 @@ -340,7 +340,7 @@ try error("\"LoadError: break me\" test failed") catch exc isa(exc, ErrorException) || rethrow(exc) - contains(exc.msg, "ERROR: LoadError: break me") && rethrow(exc) + isfound("ERROR: LoadError: break me", exc.msg) && rethrow(exc) end # Test transitive dependency for #21266 @@ -458,7 +458,7 @@ let dir = mktempdir() let fname = tempname() try @test readchomp(pipeline(`$exename -E $(testcode)`, stderr=fname)) == "nothing" - @test contains(read(fname, String), Regex("Replacing module `$Test_module`")) + @test isfound(Regex("Replacing module `$Test_module`"), read(fname, String)) finally rm(fname, force=true) end diff --git a/test/compiler/compiler.jl b/test/compiler/compiler.jl index d6c107b3f669b1..fa1c7e3b4663c5 100644 --- a/test/compiler/compiler.jl +++ b/test/compiler/compiler.jl @@ -890,7 +890,7 @@ end f22290() = return 3 for i in 1:3 ir = sprint(io -> code_llvm(io, f22290, Tuple{})) - @test contains(ir, "julia_f22290") + @test isfound("julia_f22290", ir) end # constant inference of isdefined diff --git a/test/core.jl b/test/core.jl index f68234ca609fdd..f220b48c02c10e 100644 --- a/test/core.jl +++ b/test/core.jl @@ -1205,9 +1205,9 @@ let @test_throws InexactError unsafe_wrap(Array, pointer(a), -3) # Misaligned pointer res = @test_throws ArgumentError unsafe_wrap(Array, pointer(a) + 1, length(a)) - @test contains(res.value.msg, "is not properly aligned to $(sizeof(Int)) bytes") + @test isfound("is not properly aligned to $(sizeof(Int)) bytes", res.value.msg) res = @test_throws ArgumentError unsafe_wrap(Array, pointer(a) + 1, (1, 1)) - @test contains(res.value.msg, "is not properly aligned to $(sizeof(Int)) bytes") + @test isfound("is not properly aligned to $(sizeof(Int)) bytes", res.value.msg) end struct FooBar2515 @@ -4760,7 +4760,7 @@ ptr18236 = cfunction(identity, VecElement{Float64}, Tuple{VecElement{Float64}}) @eval @noinline f18236(ptr) = ccall(ptr, VecElement{Float64}, (VecElement{Float64},), $v18236) @test f18236(ptr18236) === v18236 -@test !contains(sprint(code_llvm, f18236, Tuple{Ptr{Cvoid}}), "double undef") +@test !isfound("double undef", sprint(code_llvm, f18236, Tuple{Ptr{Cvoid}})) # VecElement of struct, not necessarily useful but does have special # ABI so should be handled correctly # This struct should be small enough to be passed by value in C ABI diff --git a/test/deprecation_exec.jl b/test/deprecation_exec.jl index 86ae275dcb0ec4..94c70d5a5a5dca 100644 --- a/test/deprecation_exec.jl +++ b/test/deprecation_exec.jl @@ -247,109 +247,109 @@ with_logger(NullLogger()) do @testset "Deprecated logging" begin # Test info -@test contains(sprint(info, "test"), "INFO:") -@test contains(sprint(info, "test"), "INFO: test") -@test contains(sprint(info, "test ", 1, 2, 3), "INFO: test 123") -@test contains(sprint(io->info(io,"test", prefix="MYINFO: ")), "MYINFO: test") +@test isfound("INFO:", sprint(info, "test")) +@test isfound("INFO: test", sprint(info, "test")) +@test isfound("INFO: test 123", sprint(info, "test ", 1, 2, 3)) +@test isfound("MYINFO: test", sprint(io->info(io,"test", prefix="MYINFO: "))) # Test warn -@test contains(sprint(Base.warn_once, "test"), "WARNING: test") +@test isfound("WARNING: test", sprint(Base.warn_once, "test")) @test isempty(sprint(Base.warn_once, "test")) -@test contains(sprint(warn), "WARNING:") -@test contains(sprint(warn, "test"), "WARNING: test") -@test contains(sprint(warn, "test ", 1, 2, 3), "WARNING: test 123") -@test contains(sprint(io->warn(io, "test", prefix="MYWARNING: ")), "MYWARNING: test") -@test contains(sprint(io->warn(io, "testonce", once=true)), "WARNING: testonce") +@test isfound("WARNING:", sprint(warn)) +@test isfound("WARNING: test", sprint(warn, "test")) +@test isfound("WARNING: test 123", sprint(warn, "test ", 1, 2, 3)) +@test isfound("MYWARNING: test", sprint(io->warn(io, "test", prefix="MYWARNING: "))) +@test isfound("WARNING: testonce", sprint(io->warn(io, "testonce", once=true))) @test isempty(sprint(io->warn(io, "testonce", once=true))) @test !isempty(sprint(io->warn(io, "testonce", once=true, key=hash("testonce",hash("testanother"))))) let bt = backtrace() ws = split(chomp(sprint(io->warn(io, "test", bt = bt))), '\n') bs = split(chomp(sprint(Base.show_backtrace, bt)), '\n') - @test contains(ws[1],"WARNING: test") + @test isfound("WARNING: test", ws[1]) for (l,b) in zip(ws[2:end],bs[2:end]) - @test contains(l, b) + @test isfound(b, l) end end # PR #16213 -@test all(contains.(sprint(LogTest.bar), ["INFO: barinfo", "WARNING: barwarn", "ERROR: \"barerror\""])) -@test all(contains.(sprint(LogTest.pooh), ["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["INFO: barinfo", "WARNING: barwarn", "ERROR: \"barerror\""], sprint(LogTest.bar))) +@test all(isfound.(["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) logging(devnull, LogTest, :bar; kind=:info) -@test all(contains.(sprint(LogTest.bar), ["WARNING: barwarn", "ERROR: \"barerror\""])) -@test all(contains.(sprint(LogTest.pooh), ["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["WARNING: barwarn", "ERROR: \"barerror\""], sprint(LogTest.bar))) +@test all(isfound.(["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) logging(devnull, LogTest; kind=:info) -@test all(contains.(sprint(LogTest.bar), ["WARNING: barwarn", "ERROR: \"barerror\""])) -@test all(contains.(sprint(LogTest.pooh), ["WARNING: poohwarn", "ERROR: \"pooherror\""])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["WARNING: barwarn", "ERROR: \"barerror\""], sprint(LogTest.bar))) +@test all(isfound.(["WARNING: poohwarn", "ERROR: \"pooherror\""], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) logging(devnull; kind=:info) -@test all(contains.(sprint(LogTest.bar), ["WARNING: barwarn", "ERROR: \"barerror\""])) -@test all(contains.(sprint(LogTest.pooh), ["WARNING: poohwarn", "ERROR: \"pooherror\""])) -@test all(contains.(sprint(foo), ["WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["WARNING: barwarn", "ERROR: \"barerror\""], sprint(LogTest.bar))) +@test all(isfound.(["WARNING: poohwarn", "ERROR: \"pooherror\""], sprint(LogTest.pooh))) +@test all(isfound.(["WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) logging(kind=:info) -@test all(contains.(sprint(LogTest.bar), ["INFO: barinfo", "WARNING: barwarn", "ERROR: \"barerror\""])) -@test all(contains.(sprint(LogTest.pooh), ["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["INFO: barinfo", "WARNING: barwarn", "ERROR: \"barerror\""], sprint(LogTest.bar))) +@test all(isfound.(["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) logging(devnull, LogTest, :bar; kind=:warn) -@test all(contains.(sprint(LogTest.bar), ["INFO: barinfo", "ERROR: \"barerror\""])) -@test all(contains.(sprint(LogTest.pooh), ["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["INFO: barinfo", "ERROR: \"barerror\""], sprint(LogTest.bar))) +@test all(isfound.(["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) logging(devnull, LogTest; kind=:warn) -@test all(contains.(sprint(LogTest.bar), ["INFO: barinfo", "ERROR: \"barerror\""])) -@test all(contains.(sprint(LogTest.pooh), ["INFO: poohinfo", "ERROR: \"pooherror\""])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["INFO: barinfo", "ERROR: \"barerror\""], sprint(LogTest.bar))) +@test all(isfound.(["INFO: poohinfo", "ERROR: \"pooherror\""], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) logging(devnull; kind=:warn) -@test all(contains.(sprint(LogTest.bar), ["INFO: barinfo", "ERROR: \"barerror\""])) -@test all(contains.(sprint(LogTest.pooh), ["INFO: poohinfo", "ERROR: \"pooherror\""])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "ERROR: \"fooerror\""])) +@test all(isfound.(["INFO: barinfo", "ERROR: \"barerror\""], sprint(LogTest.bar))) +@test all(isfound.(["INFO: poohinfo", "ERROR: \"pooherror\""], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "ERROR: \"fooerror\""], sprint(foo))) logging(kind=:warn) -@test all(contains.(sprint(LogTest.bar), ["INFO: barinfo", "WARNING: barwarn", "ERROR: \"barerror\""])) -@test all(contains.(sprint(LogTest.pooh), ["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["INFO: barinfo", "WARNING: barwarn", "ERROR: \"barerror\""], sprint(LogTest.bar))) +@test all(isfound.(["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) logging(devnull, LogTest, :bar; kind=:error) -@test all(contains.(sprint(LogTest.bar), ["INFO: barinfo", "WARNING: barwarn"])) -@test all(contains.(sprint(LogTest.pooh), ["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["INFO: barinfo", "WARNING: barwarn"], sprint(LogTest.bar))) +@test all(isfound.(["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) logging(devnull, LogTest; kind=:error) -@test all(contains.(sprint(LogTest.bar), ["INFO: barinfo", "WARNING: barwarn"])) -@test all(contains.(sprint(LogTest.pooh), ["INFO: poohinfo", "WARNING: poohwarn"])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["INFO: barinfo", "WARNING: barwarn"], sprint(LogTest.bar))) +@test all(isfound.(["INFO: poohinfo", "WARNING: poohwarn"], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) logging(devnull; kind=:error) -@test all(contains.(sprint(LogTest.bar), ["INFO: barinfo", "WARNING: barwarn"])) -@test all(contains.(sprint(LogTest.pooh), ["INFO: poohinfo", "WARNING: poohwarn"])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn"])) +@test all(isfound.(["INFO: barinfo", "WARNING: barwarn"], sprint(LogTest.bar))) +@test all(isfound.(["INFO: poohinfo", "WARNING: poohwarn"], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn"], sprint(foo))) logging(kind=:error) -@test all(contains.(sprint(LogTest.bar), ["INFO: barinfo", "WARNING: barwarn", "ERROR: \"barerror\""])) -@test all(contains.(sprint(LogTest.pooh), ["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["INFO: barinfo", "WARNING: barwarn", "ERROR: \"barerror\""], sprint(LogTest.bar))) +@test all(isfound.(["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) logging(devnull, LogTest, :bar) @test sprint(LogTest.bar) == "" -@test all(contains.(sprint(LogTest.pooh), ["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) logging(devnull, LogTest) @test sprint(LogTest.bar) == "" @test sprint(LogTest.pooh) == "" -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) logging(devnull) @test sprint(LogTest.bar) == "" @@ -357,9 +357,9 @@ logging(devnull) @test sprint(foo) == "" logging() -@test all(contains.(sprint(LogTest.bar), ["INFO: barinfo", "WARNING: barwarn", "ERROR: \"barerror\""])) -@test all(contains.(sprint(LogTest.pooh), ["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""])) -@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""])) +@test all(isfound.(["INFO: barinfo", "WARNING: barwarn", "ERROR: \"barerror\""], sprint(LogTest.bar))) +@test all(isfound.(["INFO: poohinfo", "WARNING: poohwarn", "ERROR: \"pooherror\""], sprint(LogTest.pooh))) +@test all(isfound.(["INFO: fooinfo", "WARNING: foowarn", "ERROR: \"fooerror\""], sprint(foo))) end # @testset diff --git a/test/dict.jl b/test/dict.jl index 0c1f33ec4645bd..2963ba4cb972b3 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -355,9 +355,9 @@ end # Check explicitly for the expected strings, since the CPU bitness effects # dictionary ordering. result = String(take!(buf)) - @test contains(result, "Dict") - @test contains(result, "(1=>2)=>(3=>45)") - @test contains(result, "(3=>10)=>(10=>11)") + @test isfound("Dict", result) + @test isfound("(1=>2)=>(3=>45)", result) + @test isfound("(3=>10)=>(10=>11)", result) end mutable struct Alpha end @@ -368,7 +368,7 @@ Base.show(io::IO, ::Alpha) = print(io,"α") Base.show(io, MIME("text/plain"), Dict(Alpha()=>1)) local str = String(take!(sbuff)) - @test !contains(str, "…") + @test !isfound("…", str) @test endswith(str, "α => 1") end diff --git a/test/docs.jl b/test/docs.jl index 48d4668a023d2d..11ab575ab03d40 100644 --- a/test/docs.jl +++ b/test/docs.jl @@ -669,10 +669,10 @@ end @test (@repl :@r_str) !== nothing # Simple tests for apropos: -@test contains(sprint(apropos, "pearson"), "cor") -@test contains(sprint(apropos, r"ind(exes|ices)"), "eachindex") +@test isfound("cor", sprint(apropos, "pearson")) +@test isfound("eachindex", sprint(apropos, r"ind(exes|ices)")) using Profile -@test contains(sprint(apropos, "print"), "Profile.print") +@test isfound("Profile.print", sprint(apropos, "print")) # Issue #13068. diff --git a/test/env.jl b/test/env.jl index b3e19250a3ab1b..433b15b255de86 100644 --- a/test/env.jl +++ b/test/env.jl @@ -50,8 +50,8 @@ end io = IOBuffer() show(io, ENV) s = String(take!(io)) - @test contains(s, "$k1=$k1") - @test contains(s, "$k2=$k2") + @test isfound("$k1=$k1", s) + @test isfound("$k2=$k2", s) @test pop!(ENV, k1) == k1 @test !haskey(ENV, k1) diff --git a/test/errorshow.jl b/test/errorshow.jl index 1841715856e0ad..cea33dd2110815 100644 --- a/test/errorshow.jl +++ b/test/errorshow.jl @@ -30,8 +30,8 @@ Base.show_method_candidates(buf, Base.MethodError(method_c1,(1, 1, 1))) # matches the implicit constructor -> convert method Base.show_method_candidates(buf, Base.MethodError(Tuple{}, (1, 1, 1))) let mc = String(take!(buf)) - @test contains(mc, "\nClosest candidates are:\n Tuple{}") - @test !contains(mc, cfile) + @test isfound("\nClosest candidates are:\n Tuple{}", mc) + @test !isfound(cfile, mc) end c2line = @__LINE__ @@ -107,12 +107,12 @@ m_error = try TestKWError.method_c6_in_module(1, x=1) catch e; e; end showerror(buf, m_error) error_out3 = String(take!(buf)) -@test contains(error_out, "method_c6(; x)$cfile$(c6line + 1) got unsupported keyword argument \"y\"") -@test contains(error_out, "method_c6(!Matched::Any; y)$cfile$(c6line + 2)") -@test contains(error_out1, "method_c6(::Any; y)$cfile$(c6line + 2) got unsupported keyword argument \"x\"") -@test contains(error_out2, "method_c6_in_module(; x)$cfile$(c6mline + 2) got unsupported keyword argument \"y\"") -@test contains(error_out2, "method_c6_in_module(!Matched::Any; y)$cfile$(c6mline + 3)") -@test contains(error_out3, "method_c6_in_module(::Any; y)$cfile$(c6mline + 3) got unsupported keyword argument \"x\"") +@test isfound("method_c6(; x)$cfile$(c6line + 1) got unsupported keyword argument \"y\"", error_out) +@test isfound("method_c6(!Matched::Any; y)$cfile$(c6line + 2)", error_out) +@test isfound("method_c6(::Any; y)$cfile$(c6line + 2) got unsupported keyword argument \"x\"", error_out1) +@test isfound("method_c6_in_module(; x)$cfile$(c6mline + 2) got unsupported keyword argument \"y\"", error_out2) +@test isfound("method_c6_in_module(!Matched::Any; y)$cfile$(c6mline + 3)", error_out2) +@test isfound("method_c6_in_module(::Any; y)$cfile$(c6mline + 3) got unsupported keyword argument \"x\"", error_out3) c7line = @__LINE__() + 1 method_c7(a, b; kargs...) = a @@ -127,7 +127,7 @@ let no_kwsorter_match, e no_kwsorter_match() = 0 no_kwsorter_match(a;y=1) = y e = try no_kwsorter_match(y=1) catch ex; ex; end - @test contains(sprint(showerror, e), r"no method matching.+\(; y=1\)") + @test isfound(r"no method matching.+\(; y=1\)", sprint(showerror, e)) end ac15639line = @__LINE__ @@ -195,8 +195,8 @@ let f11007(::MethodType11007) = nothing err_str = @except_str(invoke(f11007, Tuple{InvokeType11007}, InstanceType11007()), MethodError) - @test !contains(err_str, "::$(curmod_prefix)InstanceType11007") - @test contains(err_str, "::$(curmod_prefix)InvokeType11007") + @test !isfound("::$(curmod_prefix)InstanceType11007", err_str) + @test isfound("::$(curmod_prefix)InvokeType11007", err_str) end module __tmp_replutil @@ -206,37 +206,37 @@ import ..@except_str global + +() = nothing err_str = @except_str 1 + 2 MethodError -@test contains(err_str, "import Base.+") +@test isfound("import Base.+", err_str) err_str = @except_str Float64[](1) MethodError -@test !contains(err_str, "import Base.Array") +@test !isfound("import Base.Array", err_str) Array() = 1 err_str = @except_str Array(1) MethodError -@test contains(err_str, "import Base.Array") +@test isfound("import Base.Array", err_str) end let g11007(::AbstractVector) = nothing err_str = @except_str g11007([[1] [1]]) MethodError - @test contains(err_str, "row vector") - @test contains(err_str, "column vector") + @test isfound("row vector", err_str) + @test isfound("column vector", err_str) end struct TypeWithIntParam{T <: Integer} end let undefvar err_str = @except_strbt sqrt(-1) DomainError - @test contains(err_str, "Try sqrt(Complex(x)).") + @test isfound("Try sqrt(Complex(x)).", err_str) err_str = @except_strbt 2^(1-2) DomainError - @test contains(err_str, "Cannot raise an integer x to a negative power -1") + @test isfound("Cannot raise an integer x to a negative power -1", err_str) err_str = @except_strbt (-1)^0.25 DomainError - @test contains(err_str, "Exponentiation yielding a complex result requires a complex argument") + @test isfound("Exponentiation yielding a complex result requires a complex argument", err_str) A = zeros(10, 10) A[2,1] = 1 A[1,2] = -1 err_str = @except_strbt eigmax(A) DomainError - @test contains(err_str, "DomainError with [0.0 -1.0 …") + @test isfound("DomainError with [0.0 -1.0 …", err_str) err_str = @except_str (1, 2, 3)[4] BoundsError @test err_str == "BoundsError: attempt to access (1, 2, 3)\n at index [4]" @@ -297,29 +297,29 @@ let err_str, j = reinterpret(EightBitTypeT{Int32}, 0x54) err_str = @except_str Bool() MethodError - @test contains(err_str, "MethodError: no method matching Bool()") + @test isfound("MethodError: no method matching Bool()", err_str) err_str = @except_str :a() MethodError - @test contains(err_str, "MethodError: objects of type Symbol are not callable") + @test isfound("MethodError: objects of type Symbol are not callable", err_str) err_str = @except_str EightBitType() MethodError - @test contains(err_str, "MethodError: no method matching $(curmod_prefix)EightBitType()") + @test isfound("MethodError: no method matching $(curmod_prefix)EightBitType()", err_str) err_str = @except_str i() MethodError - @test contains(err_str, "MethodError: objects of type $(curmod_prefix)EightBitType are not callable") + @test isfound("MethodError: objects of type $(curmod_prefix)EightBitType are not callable", err_str) err_str = @except_str EightBitTypeT() MethodError - @test contains(err_str, "MethodError: no method matching $(curmod_prefix)EightBitTypeT()") + @test isfound("MethodError: no method matching $(curmod_prefix)EightBitTypeT()", err_str) err_str = @except_str EightBitTypeT{Int32}() MethodError - @test contains(err_str, "MethodError: no method matching $(curmod_prefix)EightBitTypeT{Int32}()") + @test isfound("MethodError: no method matching $(curmod_prefix)EightBitTypeT{Int32}()", err_str) err_str = @except_str j() MethodError - @test contains(err_str, "MethodError: objects of type $(curmod_prefix)EightBitTypeT{Int32} are not callable") + @test isfound("MethodError: objects of type $(curmod_prefix)EightBitTypeT{Int32} are not callable", err_str) err_str = @except_str FunctionLike()() MethodError - @test contains(err_str, "MethodError: no method matching (::$(curmod_prefix)FunctionLike)()") + @test isfound("MethodError: no method matching (::$(curmod_prefix)FunctionLike)()", err_str) err_str = @except_str [1,2](1) MethodError - @test contains(err_str, "MethodError: objects of type Array{$Int,1} are not callable\nUse square brackets [] for indexing an Array.") + @test isfound("MethodError: objects of type Array{$Int,1} are not callable\nUse square brackets [] for indexing an Array.", err_str) # Issue 14940 err_str = @except_str randn(1)() MethodError - @test contains(err_str, "MethodError: objects of type Array{Float64,1} are not callable") + @test isfound("MethodError: objects of type Array{Float64,1} are not callable", err_str) end @test repr("text/plain", FunctionLike()) == "(::$(curmod_prefix)FunctionLike) (generic function with 0 methods)" -@test contains(repr("text/plain", getfield(Base, Symbol("@doc"))), r"^@doc \(macro with \d+ method[s]?\)$") +@test isfound(r"^@doc \(macro with \d+ method[s]?\)$", repr("text/plain", getfield(Base, Symbol("@doc")))) method_defs_lineno = @__LINE__() + 1 Base.Symbol() = throw(ErrorException("1")) @@ -382,7 +382,7 @@ let err, buf = IOBuffer() try Array() catch err end Base.show_method_candidates(buf,err) @test isa(err, MethodError) - @test contains(String(take!(buf)), "Closest candidates are:") + @test isfound("Closest candidates are:", String(take!(buf))) end # @macroexpand tests @@ -449,7 +449,7 @@ foo_9965(x::Int) = 2x @test typeof(ex) == MethodError io = IOBuffer() Base.show_method_candidates(io, ex, pairs((w = true,))) - @test contains(String(take!(io)), "got unsupported keyword argument \"w\"") + @test isfound("got unsupported keyword argument \"w\"", String(take!(io))) end # Issue #20556 @@ -471,7 +471,7 @@ let "MethodError: no method matching $(EnclosingModule.AbstractTypeNoConstructors)()") # Test that the 'default' sysimg.jl method is not displayed. - @test !contains(sprint(showerror, method_error), "where T at sysimg.jl") + @test !isfound("where T at sysimg.jl", sprint(showerror, method_error)) # Test that tab-completion will not show the 'default' sysimg.jl method. for method_string in REPL.REPLCompletions.complete_methods(:(EnclosingModule.AbstractTypeNoConstructors())) @@ -491,14 +491,14 @@ end end::MethodError str = sprint(Base.showerror, ex1) @test startswith(str, "MethodError: no method matching f21006(::Tuple{})") - @test !contains(str, "The applicable method may be too new") + @test !isfound("The applicable method may be too new", str) # If newer applicable methods are available, world age should be mentioned. f21006(x) = x @test f21006(()) === () str = sprint(Base.showerror, ex1) @test startswith(str, "MethodError: no method matching f21006(::Tuple{})") - @test contains(str, "The applicable method may be too new: running in world age $(ex1.world)") + @test isfound("The applicable method may be too new: running in world age $(ex1.world)", str) # This method error should be thrown in a world new enough for `f21006(())`. # Also makes sure it's printed correctly. @@ -509,7 +509,7 @@ end end::MethodError str = sprint(Base.showerror, ex2) @test startswith(str, "MethodError: no method matching f21006(::Tuple{}, ::Tuple{})") - @test !contains(str, "The applicable method may be too new") + @test !isfound("The applicable method may be too new", str) # If the method is available in the exception world or if the exception world is invalid, # don't warn about world age @@ -517,7 +517,7 @@ end MethodError(ex1.f, ex1.args, typemax(UInt))) str = sprint(Base.showerror, ex3) @test startswith(str, "MethodError: no method matching f21006(::Tuple{})") - @test !contains(str, "The applicable method may be too new") + @test !isfound("The applicable method may be too new", str) end end diff --git a/test/goto.jl b/test/goto.jl index 4e8063ffb09902..e4b9fa48e4837d 100644 --- a/test/goto.jl +++ b/test/goto.jl @@ -75,7 +75,7 @@ let e = Meta.lower(@__MODULE__, quote end end) @test (e::Expr).head === :error - @test contains(e.args[1], r"label \"#\d+#a\" referenced but not defined") + @test isfound(r"label \"#\d+#a\" referenced but not defined", e.args[1]) end function goto_test5_3() diff --git a/test/llvmcall.jl b/test/llvmcall.jl index ddc67eb7ac84e5..0bfc997eb121fe 100644 --- a/test/llvmcall.jl +++ b/test/llvmcall.jl @@ -87,7 +87,7 @@ function declared_floor(x::Float64) end @test declared_floor(4.2) ≈ 4. ir = sprint(code_llvm, declared_floor, Tuple{Float64}) -@test contains(ir, "call double @llvm.floor.f64") # should be inlined +@test isfound("call double @llvm.floor.f64", ir) # should be inlined function doubly_declared_floor(x::Float64) llvmcall( diff --git a/test/llvmcall2.jl b/test/llvmcall2.jl index 63f6785f029fba..99cd93a1b3de1e 100644 --- a/test/llvmcall2.jl +++ b/test/llvmcall2.jl @@ -7,7 +7,7 @@ function declared_floor(x::Float64) end @test declared_floor(4.2) == 4.0 ir = sprint(code_llvm, declared_floor, Tuple{Float64}) -@test contains(ir, "call double @llvm.floor.f64") # should be inlined +@test isfound("call double @llvm.floor.f64", ir) # should be inlined function doubly_declared_floor(x::Float64) a = ccall("llvm.floor.f64", llvmcall, Float64, (Float64,), x) diff --git a/test/logging.jl b/test/logging.jl index 88ebb8f0c226f5..800b51da334b38 100644 --- a/test/logging.jl +++ b/test/logging.jl @@ -59,7 +59,7 @@ end @test record.file == Base.source_path() @test record.line == kwargs[:real_line] @test record.id isa Symbol - @test contains(String(record.id), r"^.*logging_[[:xdigit:]]{8}$") + @test isfound(r"^.*logging_[[:xdigit:]]{8}$", String(record.id)) # User-defined metadata @test kwargs[:bar_val] === bar_val @@ -69,13 +69,13 @@ end # Keyword values accessible from message block record2 = logs[2] - @test contains(record2, (Info,"test2")) + @test isfound((Info, "test2"), record2) kwargs = record2.kwargs @test kwargs[:value_in_msg_block] === 1000.0 # Splatting of keywords record3 = logs[3] - @test contains(record3, (Info,"test3")) + @test isfound((Info, "test3"), record3) kwargs = record3.kwargs @test sort(collect(keys(kwargs))) == [:a, :b] @test kwargs[:a] === 1 diff --git a/test/math.jl b/test/math.jl index 94a97b13e11d74..139f1ab7a1b0e0 100644 --- a/test/math.jl +++ b/test/math.jl @@ -43,7 +43,7 @@ end @test Float16(3.0) < pi @test pi < Float16(4.0) - @test contains(sprint(show,π),"3.14159") + @test isfound("3.14159", sprint(show, π)) @test widen(pi) === pi end diff --git a/test/misc.jl b/test/misc.jl index 6cdd03a463b5ef..2a66a449a48f26 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -14,7 +14,7 @@ let error("unexpected") catch ex @test isa(ex, AssertionError) - @test contains(ex.msg, "1 == 2") + @test isfound("1 == 2", ex.msg) end end # test @assert message @@ -44,8 +44,8 @@ let error("unexpected") catch ex @test isa(ex, AssertionError) - @test !contains(ex.msg, "1 == 2") - @test contains(ex.msg, "random_object") + @test !isfound("1 == 2", ex.msg) + @test isfound("random_object", ex.msg) end end # if the second argument is an expression, c @@ -82,7 +82,7 @@ let exename = Base.julia_cmd() script = "$redir_err; module A; f() = 1; end; A.f() = 1" warning_str = read(`$exename --warn-overwrite=yes --startup-file=no -e $script`, String) - @test contains(warning_str, "f()") + @test isfound("f()", warning_str) end # lock / unlock @@ -371,16 +371,16 @@ end let optstring = repr("text/plain", Base.JLOptions()) @test startswith(optstring, "JLOptions(\n") - @test !contains(optstring, "Ptr") + @test !isfound("Ptr", optstring) @test endswith(optstring, "\n)") - @test contains(optstring, " = \"") + @test isfound(" = \"", optstring) end let optstring = repr(Base.JLOptions()) @test startswith(optstring, "JLOptions(") @test endswith(optstring, ")") - @test !contains(optstring, "\n") - @test !contains(optstring, "Ptr") - @test contains(optstring, " = \"") + @test !isfound("\n", optstring) + @test !isfound("Ptr", optstring) + @test isfound(" = \"", optstring) end # Base.securezero! functions (#17579) @@ -579,7 +579,7 @@ end include("testenv.jl") -let flags = Cmd(filter(a->!contains(a, "depwarn"), collect(test_exeflags))) +let flags = Cmd(filter(a->!isfound("depwarn", a), collect(test_exeflags))) local cmd = `$test_exename $flags deprecation_exec.jl` if !success(pipeline(cmd; stdout=stdout, stderr=stderr)) diff --git a/test/mpfr.jl b/test/mpfr.jl index f1396333923494..c1621d95e8fcba 100644 --- a/test/mpfr.jl +++ b/test/mpfr.jl @@ -903,7 +903,7 @@ end @test x == parse(BigFloat, sx) @test ≈(x, parse(BigFloat, scx), rtol=1e-4) for s in (sx, scx) - @test contains(s, 'e') == contains_e + @test isfound('e', s) == contains_e @test startswith(s, starts) @test endswith(s, ends) end diff --git a/test/offsetarray.jl b/test/offsetarray.jl index 42e05f1d4c252f..d43b2c0fbc831d 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -164,8 +164,8 @@ str = String(take!(io)) show(io, parent(v)) @test str == String(take!(io)) smry = summary(v) -@test contains(smry, "OffsetArray{Float64,1") -@test contains(smry, "with indices -1:1") +@test isfound("OffsetArray{Float64,1", smry) +@test isfound("with indices -1:1", smry) function cmp_showf(printfunc, io, A) ioc = IOContext(io, :limit => true, :compact => true) printfunc(ioc, A) diff --git a/test/osutils.jl b/test/osutils.jl index ebbd7c9084c3dd..a984fca775b53d 100644 --- a/test/osutils.jl +++ b/test/osutils.jl @@ -40,8 +40,8 @@ if Sys.iswindows() @testset "path variables use correct path delimiters on windows" begin for path in (Base.SYSCONFDIR, Base.DATAROOTDIR, Base.DOCDIR, Base.LIBDIR, Base.PRIVATE_LIBDIR, Base.INCLUDEDIR) - @test !contains(path, "/") - @test !contains(path, "\\\\") + @test !isfound("/", path) + @test !isfound("\\\\", path) end end end diff --git a/test/reduce.jl b/test/reduce.jl index ed5734dc879b2a..e3ec4b55175920 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -323,10 +323,10 @@ struct SomeFunctor end @test in(1, 1:3) == true @test in(2, 1:3) == true -# contains +# isfound -@test contains("quick fox", "fox") == true -@test contains("quick fox", "lazy dog") == false +@test isfound("fox", "quick fox") == true +@test isfound("lazy dog", "quick fox") == false # count @@ -375,7 +375,7 @@ A = reshape(map(UInt8, 1:100), (10,10)) @test sum([-0.0, -0.0]) === -0.0 @test prod([-0.0, -0.0]) === 0.0 -#contains +# containment let A = Vector(1:10) @test A ∋ 5 @test A ∌ 11 diff --git a/test/reflection.jl b/test/reflection.jl index dbb544b2e8ac15..c22c11720cd6b4 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -331,20 +331,20 @@ function test_typed_ast_printing(Base.@nospecialize(f), Base.@nospecialize(types for str in (sprint(code_warntype, f, types), repr("text/plain", src)) for var in must_used_vars - @test contains(str, string(var)) + @test isfound(string(var), str) end - @test !contains(str, "Any") - @test !contains(str, "ANY") + @test !isfound("Any", str) + @test !isfound("ANY", str) # Check that we are not printing the bare slot numbers for i in 1:length(src.slotnames) name = src.slotnames[i] if name in dupnames - if name in must_used_vars && contains(str, Regex("_$i\\b")) + if name in must_used_vars && isfound(Regex("_$i\\b"), str) must_used_checked[name] = true global used_dup_var_tested15714 = true end else - @test !contains(str, Regex("_$i\\b")) + @test !isfound(Regex("_$i\\b"), str) if name in must_used_vars global used_unique_var_tested15714 = true end @@ -363,7 +363,7 @@ function test_typed_ast_printing(Base.@nospecialize(f), Base.@nospecialize(types # Use the variable names that we know should be present in the optimized AST for i in 2:length(src.slotnames) name = src.slotnames[i] - if name in must_used_vars && contains(str, Regex("_$i\\b")) + if name in must_used_vars && isfound(Regex("_$i\\b"), str) must_used_checked[name] = true end end diff --git a/test/regex.jl b/test/regex.jl index 7db1e282907b2b..754fd6af4c7020 100644 --- a/test/regex.jl +++ b/test/regex.jl @@ -31,7 +31,7 @@ show(buf, r"") @test read(buf, String) == "r\"\"" # see #10994, #11447: PCRE2 allows NUL chars in the pattern -@test contains("a\0b", Regex("^a\0b\$")) +@test isfound(Regex("^a\0b\$"), "a\0b") # regex match / search string must be a String @test_throws ArgumentError match(r"test", GenericString("this is a test")) diff --git a/test/show.jl b/test/show.jl index 0ffda8661e1e72..e81fa7e0b3a97d 100644 --- a/test/show.jl +++ b/test/show.jl @@ -432,7 +432,7 @@ let a = Expr(:quote,Expr(:$,:x8d003)) end # issue #9865 -@test contains(replstr(Set(1:100)), r"^Set\(\[.+….+\]\)$") +@test isfound(r"^Set\(\[.+….+\]\)$", replstr(Set(1:100))) # issue #11413 @test string(:(*{1, 2})) == "*{1, 2}" @@ -538,7 +538,7 @@ let filename = tempname() @test ret == [2] # stdin is unavailable on the workers. Run test on master. - @test contains(read(filename, String), "WARNING: hello") + @test isfound("WARNING: hello", read(filename, String)) ret = eval(Main, quote remotecall_fetch(1, $filename) do fname open(fname) do f @@ -549,7 +549,7 @@ let filename = tempname() end end) - @test contains(ret, "WARNING: hello") + @test isfound("WARNING: hello", ret) rm(filename) end @@ -580,28 +580,28 @@ end @test !Base.inbase(Core) let repr = sprint(show, "text/plain", methods(Base.inbase)) - @test contains(repr, "inbase(m::Module)") + @test isfound("inbase(m::Module)", repr) end let repr = sprint(show, "text/html", methods(Base.inbase)) - @test contains(repr, "inbase(m::<b>Module</b>)") + @test isfound("inbase(m::<b>Module</b>)", repr) end f5971(x, y...; z=1, w...) = nothing let repr = sprint(show, "text/plain", methods(f5971)) - @test contains(repr, "f5971(x, y...; z, w...)") + @test isfound("f5971(x, y...; z, w...)", repr) end let repr = sprint(show, "text/html", methods(f5971)) - @test contains(repr, "f5971(x, y...; <i>z, w...</i>)") + @test isfound("f5971(x, y...; <i>z, w...</i>)", repr) end f16580(x, y...; z=1, w=y+x, q...) = nothing let repr = sprint(show, "text/html", methods(f16580)) - @test contains(repr, "f16580(x, y...; <i>z, w, q...</i>)") + @test isfound("f16580(x, y...; <i>z, w, q...</i>)", repr) end if isempty(Base.GIT_VERSION_INFO.commit) - @test contains(Base.url(which(sin, (Float64,))), "https://github.com/JuliaLang/julia/tree/v$VERSION/base/special/trig.jl#L") + @test isfound("https://github.com/JuliaLang/julia/tree/v$VERSION/base/special/trig.jl#L", Base.url(which(sin, (Float64,)))) else - @test contains(Base.url(which(sin, (Float64,))), "https://github.com/JuliaLang/julia/tree/$(Base.GIT_VERSION_INFO.commit)/base/special/trig.jl#L") + @test isfound("https://github.com/JuliaLang/julia/tree/$(Base.GIT_VERSION_INFO.commit)/base/special/trig.jl#L", Base.url(which(sin, (Float64,)))) end # print_matrix should be able to handle small and large objects easily, test by @@ -611,7 +611,7 @@ end @test replstr(Matrix(1.0I, 10, 10)) == "10×10 Array{Float64,2}:\n 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0\n 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0\n 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0\n 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0\n 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0\n 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0\n 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0" # an array too long vertically to fit on screen, and too long horizontally: @test replstr(Vector(1.:100.)) == "100-element Array{Float64,1}:\n 1.0\n 2.0\n 3.0\n 4.0\n 5.0\n 6.0\n 7.0\n 8.0\n 9.0\n 10.0\n ⋮ \n 92.0\n 93.0\n 94.0\n 95.0\n 96.0\n 97.0\n 98.0\n 99.0\n 100.0" -@test contains(replstr(Vector(1.:100.)'), r"1×100 (LinearAlgebra\.)?Adjoint{Float64,Array{Float64,1}}:\n 1.0 2.0 3.0 4.0 5.0 6.0 7.0 … 95.0 96.0 97.0 98.0 99.0 100.0") +@test isfound(r"1×100 (LinearAlgebra\.)?Adjoint{Float64,Array{Float64,1}}:\n 1.0 2.0 3.0 4.0 5.0 6.0 7.0 … 95.0 96.0 97.0 98.0 99.0 100.0", replstr(Vector(1.:100.)')) # too big in both directions to fit on screen: @test replstr((1.:100.)*(1:100)') == "100×100 Array{Float64,2}:\n 1.0 2.0 3.0 4.0 5.0 6.0 … 97.0 98.0 99.0 100.0\n 2.0 4.0 6.0 8.0 10.0 12.0 194.0 196.0 198.0 200.0\n 3.0 6.0 9.0 12.0 15.0 18.0 291.0 294.0 297.0 300.0\n 4.0 8.0 12.0 16.0 20.0 24.0 388.0 392.0 396.0 400.0\n 5.0 10.0 15.0 20.0 25.0 30.0 485.0 490.0 495.0 500.0\n 6.0 12.0 18.0 24.0 30.0 36.0 … 582.0 588.0 594.0 600.0\n 7.0 14.0 21.0 28.0 35.0 42.0 679.0 686.0 693.0 700.0\n 8.0 16.0 24.0 32.0 40.0 48.0 776.0 784.0 792.0 800.0\n 9.0 18.0 27.0 36.0 45.0 54.0 873.0 882.0 891.0 900.0\n 10.0 20.0 30.0 40.0 50.0 60.0 970.0 980.0 990.0 1000.0\n ⋮ ⋮ ⋱ \n 92.0 184.0 276.0 368.0 460.0 552.0 8924.0 9016.0 9108.0 9200.0\n 93.0 186.0 279.0 372.0 465.0 558.0 9021.0 9114.0 9207.0 9300.0\n 94.0 188.0 282.0 376.0 470.0 564.0 9118.0 9212.0 9306.0 9400.0\n 95.0 190.0 285.0 380.0 475.0 570.0 9215.0 9310.0 9405.0 9500.0\n 96.0 192.0 288.0 384.0 480.0 576.0 … 9312.0 9408.0 9504.0 9600.0\n 97.0 194.0 291.0 388.0 485.0 582.0 9409.0 9506.0 9603.0 9700.0\n 98.0 196.0 294.0 392.0 490.0 588.0 9506.0 9604.0 9702.0 9800.0\n 99.0 198.0 297.0 396.0 495.0 594.0 9603.0 9702.0 9801.0 9900.0\n 100.0 200.0 300.0 400.0 500.0 600.0 9700.0 9800.0 9900.0 10000.0" @@ -659,20 +659,13 @@ end # test structured zero matrix printing for select structured types let A = reshape(1:16, 4, 4) - @test contains(replstr(Diagonal(A)), - r"4×4 (LinearAlgebra\.)?Diagonal{Int(32|64),Array{Int(32|64),1}}:\n 1 ⋅ ⋅ ⋅\n ⋅ 6 ⋅ ⋅\n ⋅ ⋅ 11 ⋅\n ⋅ ⋅ ⋅ 16") - @test contains(replstr(Bidiagonal(A, :U)), - r"4×4 (LinearAlgebra\.)?Bidiagonal{Int(32|64),Array{Int(32|64),1}}:\n 1 5 ⋅ ⋅\n ⋅ 6 10 ⋅\n ⋅ ⋅ 11 15\n ⋅ ⋅ ⋅ 16") - @test contains(replstr(Bidiagonal(A, :L)), - r"4×4 (LinearAlgebra\.)?Bidiagonal{Int(32|64),Array{Int(32|64),1}}:\n 1 ⋅ ⋅ ⋅\n 2 6 ⋅ ⋅\n ⋅ 7 11 ⋅\n ⋅ ⋅ 12 16") - @test contains(replstr(SymTridiagonal(A + A')), - r"4×4 (LinearAlgebra\.)?SymTridiagonal{Int(32|64),Array{Int(32|64),1}}:\n 2 7 ⋅ ⋅\n 7 12 17 ⋅\n ⋅ 17 22 27\n ⋅ ⋅ 27 32") - @test contains(replstr(Tridiagonal(diag(A, -1), diag(A), diag(A, +1))), - r"4×4 (LinearAlgebra\.)?Tridiagonal{Int(32|64),Array{Int(32|64),1}}:\n 1 5 ⋅ ⋅\n 2 6 10 ⋅\n ⋅ 7 11 15\n ⋅ ⋅ 12 16") - @test contains(replstr(UpperTriangular(copy(A))), - r"4×4 (LinearAlgebra\.)?UpperTriangular{Int(32|64),Array{Int(32|64),2}}:\n 1 5 9 13\n ⋅ 6 10 14\n ⋅ ⋅ 11 15\n ⋅ ⋅ ⋅ 16") - @test contains(replstr(LowerTriangular(copy(A))), - r"4×4 (LinearAlgebra\.)?LowerTriangular{Int(32|64),Array{Int(32|64),2}}:\n 1 ⋅ ⋅ ⋅\n 2 6 ⋅ ⋅\n 3 7 11 ⋅\n 4 8 12 16") + @test isfound(r"4×4 (LinearAlgebra\.)?Diagonal{Int(32|64),Array{Int(32|64),1}}:\n 1 ⋅ ⋅ ⋅\n ⋅ 6 ⋅ ⋅\n ⋅ ⋅ 11 ⋅\n ⋅ ⋅ ⋅ 16", replstr(Diagonal(A))) + @test isfound(r"4×4 (LinearAlgebra\.)?Bidiagonal{Int(32|64),Array{Int(32|64),1}}:\n 1 5 ⋅ ⋅\n ⋅ 6 10 ⋅\n ⋅ ⋅ 11 15\n ⋅ ⋅ ⋅ 16", replstr(Bidiagonal(A, :U))) + @test isfound(r"4×4 (LinearAlgebra\.)?Bidiagonal{Int(32|64),Array{Int(32|64),1}}:\n 1 ⋅ ⋅ ⋅\n 2 6 ⋅ ⋅\n ⋅ 7 11 ⋅\n ⋅ ⋅ 12 16", replstr(Bidiagonal(A, :L))) + @test isfound(r"4×4 (LinearAlgebra\.)?SymTridiagonal{Int(32|64),Array{Int(32|64),1}}:\n 2 7 ⋅ ⋅\n 7 12 17 ⋅\n ⋅ 17 22 27\n ⋅ ⋅ 27 32", replstr(SymTridiagonal(A + A'))) + @test isfound(r"4×4 (LinearAlgebra\.)?Tridiagonal{Int(32|64),Array{Int(32|64),1}}:\n 1 5 ⋅ ⋅\n 2 6 10 ⋅\n ⋅ 7 11 15\n ⋅ ⋅ 12 16", replstr(Tridiagonal(diag(A, -1), diag(A), diag(A, +1)))) + @test isfound(r"4×4 (LinearAlgebra\.)?UpperTriangular{Int(32|64),Array{Int(32|64),2}}:\n 1 5 9 13\n ⋅ 6 10 14\n ⋅ ⋅ 11 15\n ⋅ ⋅ ⋅ 16", replstr(UpperTriangular(copy(A)))) + @test isfound(r"4×4 (LinearAlgebra\.)?LowerTriangular{Int(32|64),Array{Int(32|64),2}}:\n 1 ⋅ ⋅ ⋅\n 2 6 ⋅ ⋅\n 3 7 11 ⋅\n 4 8 12 16", replstr(LowerTriangular(copy(A)))) end # Vararg methods in method tables @@ -744,8 +737,8 @@ end @test string(Tuple{Array}) == "Tuple{Array}" # PR #16651 -@test !contains(repr(fill(1.,10,10)), "\u2026") -@test contains(sprint((io, x) -> show(IOContext(io, :limit => true), x), fill(1.,30,30)), "\u2026") +@test !isfound("\u2026", repr(fill(1.,10,10))) +@test isfound("\u2026", sprint((io, x) -> show(IOContext(io, :limit => true), x), fill(1.,30,30))) # showcompact() also sets :multiline=>false (#16817) let io = IOBuffer(), @@ -788,12 +781,12 @@ let repr = sprint(dump, Int64) end let repr = sprint(dump, Any) @test length(repr) == 4 - @test contains(repr, r"^Any\n") + @test isfound(r"^Any\n", repr) @test endswith(repr, '\n') end let repr = sprint(dump, Integer) - @test contains(repr, "Integer <: Real") - @test !contains(repr, "Any") + @test isfound("Integer <: Real", repr) + @test !isfound("Any", repr) end let repr = sprint(dump, Union{Integer, Float32}) @test repr == "Union{Integer, Float32}\n" || repr == "Union{Float32, Integer}\n" @@ -892,7 +885,7 @@ let m = which(T20332{Int}(), (Int,)), mi = ccall(:jl_specializations_get_linfo, Ref{Core.MethodInstance}, (Any, Any, Any, UInt), m, Tuple{T20332{T}, Int} where T, Core.svec(), typemax(UInt)) # test that this doesn't throw an error - @test contains(repr(mi), "MethodInstance for") + @test isfound("MethodInstance for", repr(mi)) end @test sprint(show, Main) == "Main" @@ -946,7 +939,7 @@ end let io = IOBuffer() show(io, MIME"text/html"(), f_with_params.body.name.mt) - @test contains(String(take!(io)), "f_with_params") + @test isfound("f_with_params", String(take!(io))) end @testset "printing of Val's" begin @@ -1082,7 +1075,7 @@ end io = IOBuffer() show(io, "text/html", m) s = String(take!(io)) - @test contains(s, " in Base.Math ") + @test isfound(" in Base.Math ", s) end module TestShowType @@ -1142,11 +1135,11 @@ end display(td, d) result = String(take!(td.io)) - @test contains(result, summary(d)) + @test isfound(summary(d), result) # Is every pair in the string? for el in d - @test contains(result, string(el)) + @test isfound(string(el), result) end end @@ -1154,14 +1147,14 @@ end K20111(x) = y -> x buf = IOBuffer() show(buf, methods(K20111(1))) - @test contains(String(take!(buf)), " 1 method for generic function") + @test isfound(" 1 method for generic function", String(take!(buf))) end @generated f22798(x::Integer, y) = :x @testset "#22798" begin buf = IOBuffer() show(buf, methods(f22798)) - @test contains(String(take!(buf)), "f22798(x::Integer, y)") + @test isfound("f22798(x::Integer, y)", String(take!(buf))) end @testset "Intrinsic printing" begin @@ -1169,8 +1162,8 @@ end let io = IOBuffer() show(io, MIME"text/plain"(), Core.Intrinsics.arraylen) str = String(take!(io)) - @test contains(str, "arraylen") - @test contains(str, "(intrinsic function") + @test isfound("arraylen", str) + @test isfound("(intrinsic function", str) end end diff --git a/test/spawn.jl b/test/spawn.jl index a468df6741de59..c7abfbe61e29f7 100644 --- a/test/spawn.jl +++ b/test/spawn.jl @@ -48,8 +48,8 @@ end @test length(run(pipeline(`$echocmd hello`, sortcmd), wait=false).processes) == 2 out = read(`$echocmd hello` & `$echocmd world`, String) -@test contains(out,"world") -@test contains(out,"hello") +@test isfound("world", out) +@test isfound("hello", out) @test read(pipeline(`$echocmd hello` & `$echocmd world`, sortcmd), String) == "hello\nworld\n" @test (run(`$printfcmd " \033[34m[stdio passthrough ok]\033[0m\n"`); true) diff --git a/test/stacktraces.jl b/test/stacktraces.jl index 59e9268c892dd3..ed4f5294956349 100644 --- a/test/stacktraces.jl +++ b/test/stacktraces.jl @@ -141,7 +141,7 @@ end # Test that `removes_frames!` can correctly remove frames from within the module trace = StackTracesTestMod.unfiltered_stacktrace() -@test contains(string(trace), "unfiltered_stacktrace") +@test isfound("unfiltered_stacktrace", string(trace)) trace = StackTracesTestMod.filtered_stacktrace() -@test !contains(string(trace), "filtered_stacktrace") +@test !isfound("filtered_stacktrace", string(trace)) diff --git a/test/staged.jl b/test/staged.jl index 8d1cb76be7253e..b677ab65d762d2 100644 --- a/test/staged.jl +++ b/test/staged.jl @@ -274,10 +274,10 @@ end let a = Any[] @test f23168(a, 3) == (6, Int) @test a == [1, 6, 3] - @test contains(string(code_lowered(f23168, (Vector{Any},Int))), "x + x") - @test contains(string(Base.uncompressed_ast(first(methods(f23168)))), "2 * x") - @test contains(string(code_lowered(f23168, (Vector{Any},Int), generated=false)), "2 * x") - @test contains(string(code_typed(f23168, (Vector{Any},Int))), "(Base.add_int)(x, x)") + @test isfound("x + x", string(code_lowered(f23168, (Vector{Any},Int)))) + @test isfound("2 * x", string(Base.uncompressed_ast(first(methods(f23168))))) + @test isfound("2 * x", string(code_lowered(f23168, (Vector{Any},Int), generated=false))) + @test isfound("(Base.add_int)(x, x)", string(code_typed(f23168, (Vector{Any},Int)))) end # issue #18747 diff --git a/test/strings/search.jl b/test/strings/search.jl index b494d72c83ee4d..8af8509340e2a1 100644 --- a/test/strings/search.jl +++ b/test/strings/search.jl @@ -313,9 +313,9 @@ end @test findfirst(r"az", "foo,bar,baz") == 10:11 @test findnext(r"az", "foo,bar,baz", 12) == 0:-1 -# contains with a String and Char needle -@test contains("foo", "o") -@test contains("foo", 'o') +# isfound with a String and Char needle +@test isfound("o", "foo") +@test isfound('o', "foo") @test_throws ErrorException "ab" ∈ "abc" @@ -327,4 +327,4 @@ end @test @inferred findall(equalto('a'), "éa") == [3] @test @inferred findall(equalto('€'), "€€") == [1, 4] -@test @inferred isempty(findall(equalto('é'), "")) \ No newline at end of file +@test @inferred isempty(findall(equalto('é'), "")) diff --git a/test/strings/types.jl b/test/strings/types.jl index 1b12b7cf634c83..26ba7222d0a18a 100644 --- a/test/strings/types.jl +++ b/test/strings/types.jl @@ -154,8 +154,8 @@ end @test parse(Float32, SubString("10",1,1)) === 1.0f0 # issue #5870 -@test !contains(SubString("",1,0), Regex("aa")) -@test contains(SubString("",1,0), Regex("")) +@test !isfound(Regex("aa"), SubString("",1,0)) +@test isfound(Regex(""), SubString("",1,0)) # isvalid, length, prevind, nextind for SubString{String} let s = "lorem ipsum", sdict = Dict( diff --git a/test/threads.jl b/test/threads.jl index a05415b4dfe9ce..d60af1974cf633 100644 --- a/test/threads.jl +++ b/test/threads.jl @@ -475,8 +475,8 @@ test_nested_loops() append=false)) out = readchomp(joinpath(dir, "out.txt")) err = readchomp(joinpath(dir, "err.txt")) - @test contains(out, "libat_store") || contains(out, "atomic_store") - @test !contains(err, "__atomic_store") + @test isfound("libat_store", out) || isfound("atomic_store", out) + @test !isfound("__atomic_store", err) end end diff --git a/test/worlds.jl b/test/worlds.jl index db1d03755e2d90..0bc9e72cd8a314 100644 --- a/test/worlds.jl +++ b/test/worlds.jl @@ -152,7 +152,7 @@ let ex = t265.exception The applicable method may be too new: running in world age $wc265, while current world is $wc.""" @test startswith(str, cmps) cmps = "\n h265() at $loc_h265 (method too new to be called from this world context.)" - @test contains(str, cmps) + @test isfound(cmps, str) end # test for generated function correctness