Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check captured logging messages #109

Merged
merged 1 commit into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "EzXML"
version = "0.9.1"
authors = ["Kenta Sato <bicycle1885@gmail.com>"]
uuid = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
authors = ["Kenta Sato <bicycle1885@gmail.com>"]
version = "0.9.1"

[deps]
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
Expand All @@ -10,6 +10,7 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"

[targets]
test = ["Test"]
test = ["Test", "Logging"]
2 changes: 1 addition & 1 deletion src/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function throw_xml_error()
if isempty(XML_GLOBAL_ERROR_STACK)
error("unknown error of libxml2")
elseif length(XML_GLOBAL_ERROR_STACK) > 1
@warn("caught $(length(XML_GLOBAL_ERROR_STACK)) errors; show the first one")
@warn("caught $(length(XML_GLOBAL_ERROR_STACK)) errors; showing the first one")
end
# DEBUG
# for err in XML_GLOBAL_ERROR_STACK
Expand Down
23 changes: 19 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
using EzXML
using Test
using Logging: SimpleLogger, with_logger

# Capture logging messages using a local logger.
function capture_logging_messages(proc)
buf = IOBuffer()
ret = with_logger(proc, SimpleLogger(buf))
messages = String(take!(buf))
return ret, messages
end


# Unit tests
# ----------
Expand Down Expand Up @@ -93,10 +103,13 @@ end
&#124
<a href="http://mbgd.genome.ad.jp/sparql/index_2015.php">To Previous Version (2015)</a>
""")
@info("the following two warnings are expected:")
doc = readhtml(buf)
doc, messages = capture_logging_messages() do
readhtml(buf)
end
@test isa(doc, EzXML.Document)
@test nodetype(doc.node) === EzXML.HTML_DOCUMENT_NODE
@test occursin("Warning: XMLError: htmlParseCharRef: missing semicolon from HTML parser (code: 7, line: 2)", messages)
@test occursin("Warning: XMLError: htmlParseCharRef: missing semicolon from HTML parser (code: 7, line: 4)", messages)
end
end

Expand Down Expand Up @@ -167,8 +180,10 @@ end
@test_throws EzXML.XMLError parsexml("abracadabra")
@test_throws EzXML.XMLError parsexml("""<?xml version="1.0"?>""")

@info("the following warning is expected:")
@test_throws EzXML.XMLError parsexml("<gepa?>jgo<<<><<")
_, messages = capture_logging_messages() do
@test_throws EzXML.XMLError parsexml("<gepa?>jgo<<<><<")
end
@test occursin("caught 4 errors; showing the first one", messages)
end

@testset "HTML" begin
Expand Down