Skip to content

Commit

Permalink
Drop dead code due to Julia VERSION requirements
Browse files Browse the repository at this point in the history
modified:   src/Logger/websocketlogger.jl
modified:   test/error_test.jl
modified:   test/test_websocketlogger.jl
  • Loading branch information
hustf committed Nov 29, 2022
1 parent 37cb1d8 commit 8939845
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 56 deletions.
5 changes: 2 additions & 3 deletions src/Logger/websocketlogger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import Base.CoreLogging: logmsg_code,
_min_enabled_level,
current_logger_for_env,
logging_error
if VERSION >= v"1.1"
import Base.CoreLogging: _invoked_shouldlog
end
import Base.CoreLogging: _invoked_shouldlog


import Base.string_with_env
const Wslog = LogLevel(50)
Expand Down
12 changes: 0 additions & 12 deletions test/error_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ global err = take!(chfromserv)
@test typeof(err) <: WebSocketClosedError
@test err.message == "while read(ws|server) Client side closed socket connection - Performed closing handshake."
global stack_trace = take!(chfromserv)
if VERSION <= v"1.0.2"
# Stack trace on master is zero. Unknown cause.
@test length(stack_trace) == 2
end

close(s)

Expand All @@ -146,10 +142,6 @@ global err = take!(s.out)
@test err.message == "while read(ws|server) Client side closed socket connection - Performed closing handshake."
sleep(1)
global stack_trace = take!(s.out);
if VERSION <= v"1.0.2"
# Stack trace on master is zero. Unknown cause.
@test length(stack_trace) in [5, 6]
end

while isready(s.out)
take!(s.out)
Expand All @@ -173,10 +165,6 @@ for (ke, va) in WebSockets.codeDesc
@test err.message == "ws|server respond to OPCODE_CLOSE $ke: $va"
wait(s.out)
stacktra = take!(s.out)
if VERSION <= v"1.0.2"
# Unknown cause, nighly behaves differently
@test length(stacktra) == 0
end
while isready(s.out)
take!(s.out)
end
Expand Down
76 changes: 35 additions & 41 deletions test/test_websocketlogger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,21 @@ import Base.CoreLogging: Info,
logger = WebSocketLogger(io)
# This covers an issue (#28786) in stdlib/Julia v 0.7, where log_record_id is not defined
# in the expanded macro. Fixed Nov 2018, labelled for backporting to v1.0.0
if VERSION >= v"1.0.0"
with_logger(logger) do
for i in 1:2
@info "test" maxlog=1
end
with_logger(logger) do
for i in 1:2
@info "test" maxlog=1
end
@test String(take!(buf)) ==
"""
[ Info: test
"""
with_logger(logger) do
for i in 1:2
@info "test" maxlog=0
end
end
@test String(take!(buf)) ==
"""
[ Info: test
"""
with_logger(logger) do
for i in 1:2
@info "test" maxlog=0
end
@test String(take!(buf)) == ""
end
@test String(take!(buf)) == ""
@testset "Default metadata formatting" begin
@test Logging.default_metafmt(Debug, Base, :g, :i, expanduser("~/somefile.jl"), 42) ==
(:blue, "Debug:", "@ Base ~/somefile.jl:42")
Expand Down Expand Up @@ -202,7 +200,7 @@ import Base.CoreLogging: Info,
│ exception =
│ DivideError: integer division error
│ Stacktrace:
$(VERSION < v"1.6" ? "" : " ")[1] func1()""")
[1] func1()""")


@testset "Limiting large data structures" begin
Expand All @@ -214,15 +212,15 @@ import Base.CoreLogging: Info,
│ 1.00001 1.00001 1.00001 1.00001 … 1.00001 1.00001 1.00001
│ 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
│ 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
│ ⋮ ⋱ $(VERSION < v"1.1" ? " " : "")
│ ⋮ ⋱
│ 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
│ 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001 1.00001
│ b =
│ 10×10 $(Matrix{Float64}):
│ 2.00002 2.00002 2.00002 2.00002 … 2.00002 2.00002 2.00002
│ 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002
│ 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002
│ ⋮ ⋱ $(VERSION < v"1.1" ? " " : "")
│ ⋮ ⋱
│ 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002
│ 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002 2.00002
└ SUFFIX
Expand Down Expand Up @@ -293,19 +291,16 @@ end
# Loglevel Wslog, own format
# This covers an issue related to #28786 in stdlib/Julia v 0.7, where log_record_id is not defined
# in the expanded macro. Why it is triggered here, but not in the LogLevel Info test is unknown.
if VERSION >= v"1.0.0"
msg = spec_msg("---", level = Wslog)
@test startswith(msg, "[ Wslog ")
@test endswith(msg, ": ---\n")
end
msg = spec_msg("---", level = Wslog)
@test startswith(msg, "[ Wslog ")
@test endswith(msg, ": ---\n")
# Blocking all log levels except Wslog.
spec_shouldlog(logger, level, _module, group, id) = level == Wslog
# Issue 28786
if VERSION >= v"1.0.0"
msg = spec_msg("---", level = Wslog, shouldlog = spec_shouldlog)
@test startswith(msg, "[ Wslog ")
@test endswith(msg, ": ---\n")
end
msg = spec_msg("---", level = Wslog, shouldlog = spec_shouldlog)
@test startswith(msg, "[ Wslog ")
@test endswith(msg, ": ---\n")
#
@test spec_msg("---", shouldlog = spec_shouldlog) == ""
@test spec_msg("---", level = Debug, shouldlog = spec_shouldlog) == ""
@test spec_msg("---", level = Warn, shouldlog = spec_shouldlog) == ""
Expand Down Expand Up @@ -333,19 +328,18 @@ end
@test shouldlog(logger, Info, Main, :group, :asdf) == true

# Check that error handling works with @wslog
if VERSION >= v"1.0.0"
# This covers an issue (#28786) in stdlib/Julia v 0.7, where log_record_id is not defined
# in the expanded macro. Fixed Nov 2018, labelled for backporting to v1.0.0
buf = IOBuffer()
io = IOContext(buf, :displaysize=>(30,80), :color=>true)
logger = WebSocketLogger(io)
with_logger(logger) do
@wslog sqrt(-2)
end
@test length(String(take!(buf))) > 1900
"""
[ Info: test
"""
end
# This covers an issue (#28786) in stdlib/Julia v 0.7, where log_record_id is not defined
# in the expanded macro. Fixed Nov 2018, labelled for backporting to v1.0.0
buf = IOBuffer()
io = IOContext(buf, :displaysize=>(30,80), :color=>true)
logger = WebSocketLogger(io)
with_logger(logger) do
@wslog sqrt(-2)
end
@test length(String(take!(buf))) > 1900
"""
[ Info: test
"""

end
nothing

0 comments on commit 8939845

Please sign in to comment.