-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_compliance.exs
More file actions
169 lines (142 loc) · 4.51 KB
/
debug_compliance.exs
File metadata and controls
169 lines (142 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Debug failing tests
xmlconf_base = "test/xmlconf/xmlconf"
test_suites = [
{"xmltest/xmltest.xml", "xmltest/"},
{"sun/sun-valid.xml", "sun/"},
{"sun/sun-not-wf.xml", "sun/"},
{"oasis/oasis.xml", "oasis/"},
{"ibm/ibm_oasis_valid.xml", "ibm/"},
{"ibm/ibm_oasis_not-wf.xml", "ibm/"}
]
extract_attr = fn attrs, name ->
case Regex.run(~r/#{name}="([^"]*)"/, attrs) do
[_, value] -> value
_ -> nil
end
end
safe_preview = fn xml ->
# Check if it's UTF-16
case xml do
<<0xFF, 0xFE, _::binary>> -> "[UTF-16 LE encoded]"
<<0xFE, 0xFF, _::binary>> -> "[UTF-16 BE encoded]"
_ ->
xml
|> String.slice(0, 200)
|> String.replace(~r/[^\x20-\x7E\n\r\t]/, "?")
|> String.replace("\n", "\\n")
end
end
IO.puts("=== VALID TESTS THAT FAIL (should accept but we reject) ===\n")
valid_failures = []
valid_failures = Enum.reduce(test_suites, valid_failures, fn {catalog_file, base_path}, acc ->
catalog_path = Path.join(xmlconf_base, catalog_file)
if File.exists?(catalog_path) do
content = File.read!(catalog_path)
Regex.scan(~r/<TEST\s+([^>]+)>([^<]*)<\/TEST>/s, content)
|> Enum.reduce(acc, fn [_full, attrs, desc], inner_acc ->
type = extract_attr.(attrs, "TYPE")
entities = extract_attr.(attrs, "ENTITIES")
uri = extract_attr.(attrs, "URI")
id = extract_attr.(attrs, "ID")
sections = extract_attr.(attrs, "SECTIONS")
if entities == "none" and type == "valid" and uri do
full_path = Path.join([xmlconf_base, base_path, uri])
if File.exists?(full_path) do
xml = File.read!(full_path)
result = try do
doc = RustyXML.parse(xml)
RustyXML.root(doc)
:ok
rescue
e -> {:error, Exception.message(e)}
catch
_, e -> {:error, inspect(e)}
end
case result do
{:error, reason} ->
[{id, sections, String.trim(desc), reason, full_path, safe_preview.(xml)} | inner_acc]
_ -> inner_acc
end
else
inner_acc
end
else
inner_acc
end
end)
else
acc
end
end)
Enum.each(valid_failures, fn {id, sections, desc, reason, path, preview} ->
IO.puts("FAIL: #{id}")
IO.puts(" Sections: #{sections}")
IO.puts(" Description: #{desc}")
IO.puts(" Error: #{reason}")
IO.puts(" File: #{path}")
IO.puts(" XML preview: #{preview}")
IO.puts("")
end)
IO.puts("Total valid failures: #{length(valid_failures)}")
IO.puts("\n=== NOT-WF TESTS THAT PASS (should reject but we accept) ===\n")
# Categorize not-wf failures by section
notwf_failures = []
notwf_failures = Enum.reduce(test_suites, notwf_failures, fn {catalog_file, base_path}, acc ->
catalog_path = Path.join(xmlconf_base, catalog_file)
if File.exists?(catalog_path) do
content = File.read!(catalog_path)
Regex.scan(~r/<TEST\s+([^>]+)>([^<]*)<\/TEST>/s, content)
|> Enum.reduce(acc, fn [_full, attrs, desc], inner_acc ->
type = extract_attr.(attrs, "TYPE")
entities = extract_attr.(attrs, "ENTITIES")
uri = extract_attr.(attrs, "URI")
id = extract_attr.(attrs, "ID")
sections = extract_attr.(attrs, "SECTIONS")
if entities == "none" and type == "not-wf" and uri do
full_path = Path.join([xmlconf_base, base_path, uri])
if File.exists?(full_path) do
xml = File.read!(full_path)
result = try do
doc = RustyXML.parse(xml)
RustyXML.root(doc)
:ok
rescue
_ -> :error
catch
_, _ -> :error
end
if result == :ok do
[{id, sections, String.trim(desc), full_path, safe_preview.(xml)} | inner_acc]
else
inner_acc
end
else
inner_acc
end
else
inner_acc
end
end)
else
acc
end
end)
# Group by section
by_section = Enum.group_by(notwf_failures, fn {_id, sections, _desc, _path, _xml} -> sections end)
IO.puts("Not-WF failures by XML spec section:")
by_section
|> Enum.sort_by(fn {section, items} -> -length(items) end)
|> Enum.each(fn {section, items} ->
IO.puts(" Section #{section}: #{length(items)} failures")
end)
IO.puts("\nTotal not-wf failures: #{length(notwf_failures)}")
# Show first 10 examples
IO.puts("\n=== First 10 not-wf examples ===\n")
notwf_failures
|> Enum.take(10)
|> Enum.each(fn {id, sections, desc, path, xml} ->
IO.puts("#{id} (Section #{sections})")
IO.puts(" #{desc}")
IO.puts(" XML: #{xml}")
IO.puts("")
end)