v / vlib / encoding / xml / test / spec_test.v
25 lines · 22 sloc · 796 bytes · 35558df96c5c3645143a3b7c80e81c25c1ad90e3
Raw
1module main
2
3import os
4import encoding.xml
5
6// All the XML files in the spec directory obtained recursively
7const spec_files = os.walk_ext(os.join_path(os.dir(@FILE), 'local'), 'xml')
8
9fn test_can_parse_all_files() ! {
10 assert spec_files.len > 0, 'No XML files found in the spec directory'
11 for file in spec_files {
12 doc := xml.XMLDocument.from_file(file) or {
13 // Parsing failed. Check if this was an expected error.
14 parent := os.dir(file)
15 error_file := os.join_path(parent, 'expected_error.txt')
16 error_text := os.read_file(error_file) or {
17 // No expected error. Fail the test.
18 return error('Failed to parse XML file: ' + file)
19 }
20 // Check if the error message matches the expected error.
21 assert err.msg().trim_space() == error_text.trim_space()
22 continue
23 }
24 }
25}
26