use ^@, ^A,... escapes in XML output + test
to avoid writing non-printable characters to the XML file.
This commit is contained in:
@ -93,11 +93,18 @@ module Cmdtest
|
||||
xml_tag,
|
||||
@message,
|
||||
@type,
|
||||
@text,
|
||||
_asciify(@text),
|
||||
xml_tag,
|
||||
]
|
||||
f.put ' </testcase>'
|
||||
end
|
||||
|
||||
def _asciify(str)
|
||||
res = str.gsub(/[\x00-\x09\x0b-\x1f]/) do |x|
|
||||
"^" + (x.ord + 64).chr
|
||||
end
|
||||
return res
|
||||
end
|
||||
end
|
||||
|
||||
#----------
|
||||
|
45
t/CMDTEST_junit.rb
Normal file
45
t/CMDTEST_junit.rb
Normal file
@ -0,0 +1,45 @@
|
||||
|
||||
require "selftest_utils"
|
||||
|
||||
class CMDTEST_junit < Cmdtest::Testcase
|
||||
|
||||
include SelftestUtils
|
||||
|
||||
def make_files(cmd="true")
|
||||
create_file "CMDTEST_foo.rb", [
|
||||
"class CMDTEST_foo1 < Cmdtest::Testcase",
|
||||
" def setup",
|
||||
" prepend_path #{BIN.inspect}",
|
||||
" prepend_path #{PLATFORM_BIN.inspect}",
|
||||
" end",
|
||||
"",
|
||||
|
||||
' def test_foo1',
|
||||
' cmd "%s" do' % cmd,
|
||||
' end',
|
||||
' end',
|
||||
'',
|
||||
'end',
|
||||
]
|
||||
end
|
||||
|
||||
def test_1
|
||||
make_files("echo_ctrl_chars.rb 1:5 27:32")
|
||||
|
||||
cmd_cmdtest_verbose "--quiet --xml=tmp.xml" do
|
||||
exit_nonzero
|
||||
stdout_contain [
|
||||
"### echo_ctrl_chars.rb 1:5 27:32",
|
||||
"--- ERROR: wrong stdout",
|
||||
/--- \^A --- \x01 ---/,
|
||||
/--- \^B --- \x02 ---/,
|
||||
]
|
||||
created_files "tmp.xml"
|
||||
file_equal "tmp.xml", /--- \^A --- \^A ---/
|
||||
file_equal "tmp.xml", /--- \^B --- \^B ---/
|
||||
file_equal "tmp.xml", /--- \^\[ --- \^\[ ---/
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user