| 1 | module main |
| 2 | |
| 3 | import os |
| 4 | import encoding.xml |
| 5 | |
| 6 | // All the XML files in the spec directory obtained recursively |
| 7 | const spec_files = os.walk_ext(os.join_path(os.dir(@FILE), 'local'), 'xml') |
| 8 | |
| 9 | fn 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 | |