Skip to content

Commit

Permalink
check captured logging messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bicycle1885 committed Jul 11, 2019
1 parent abd0be3 commit 7175c40
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
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

0 comments on commit 7175c40

Please sign in to comment.