mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:32:45 +00:00 
			
		
		
		
	xml: Port to Core::Stream
This commit is contained in:
		
							parent
							
								
									fde9cba2a0
								
							
						
					
					
						commit
						b8a1d04a49
					
				
					 1 changed files with 19 additions and 8 deletions
				
			
		|  | @ -10,6 +10,7 @@ | |||
| #include <AK/URLParser.h> | ||||
| #include <LibCore/ArgsParser.h> | ||||
| #include <LibCore/File.h> | ||||
| #include <LibCore/Stream.h> | ||||
| #include <LibMain/Main.h> | ||||
| #include <LibXML/DOM/Document.h> | ||||
| #include <LibXML/DOM/Node.h> | ||||
|  | @ -370,8 +371,8 @@ static auto parse(StringView contents) | |||
|                 if (url.scheme() != "file") | ||||
|                     return Error::from_string_literal("NYI: Nonlocal entity"); | ||||
| 
 | ||||
|                 auto file = TRY(Core::File::open(url.path(), Core::OpenMode::ReadOnly)); | ||||
|                 return String::copy(file->read_all()); | ||||
|                 auto file = TRY(Core::Stream::File::open(url.path(), Core::Stream::OpenMode::Read)); | ||||
|                 return String::copy(TRY(file->read_all())); | ||||
|             }, | ||||
|         }, | ||||
|     }; | ||||
|  | @ -439,7 +440,7 @@ static void do_run_tests(XML::Document& document) | |||
|                 continue; | ||||
|             } | ||||
| 
 | ||||
|             auto file_result = Core::File::open(url.path(), Core::OpenMode::ReadOnly); | ||||
|             auto file_result = Core::Stream::File::open(url.path(), Core::Stream::OpenMode::Read); | ||||
|             if (file_result.is_error()) { | ||||
|                 warnln("Read error for {}: {}", url.path(), file_result.error()); | ||||
|                 s_test_results.set(url.path(), TestResult::RunnerFailed); | ||||
|  | @ -449,7 +450,12 @@ static void do_run_tests(XML::Document& document) | |||
|             warnln("Running test {}", url.path()); | ||||
| 
 | ||||
|             auto contents = file_result.value()->read_all(); | ||||
|             auto parser = parse(contents); | ||||
|             if (contents.is_error()) { | ||||
|                 warnln("Read error for {}: {}", url.path(), contents.error()); | ||||
|                 s_test_results.set(url.path(), TestResult::RunnerFailed); | ||||
|                 continue; | ||||
|             } | ||||
|             auto parser = parse(contents.value()); | ||||
|             auto doc_or_error = parser.parse(); | ||||
|             if (doc_or_error.is_error()) { | ||||
|                 if (type == "invalid" || type == "error" || type == "not-wf") | ||||
|  | @ -462,14 +468,19 @@ static void do_run_tests(XML::Document& document) | |||
|             auto out = suite.attributes.find("OUTPUT"); | ||||
|             if (out != suite.attributes.end()) { | ||||
|                 auto out_path = LexicalPath::join(test_base_path, out->value).string(); | ||||
|                 auto file_result = Core::File::open(out_path, Core::OpenMode::ReadOnly); | ||||
|                 auto file_result = Core::Stream::File::open(out_path, Core::Stream::OpenMode::Read); | ||||
|                 if (file_result.is_error()) { | ||||
|                     warnln("Read error for {}: {}", out_path, file_result.error()); | ||||
|                     s_test_results.set(url.path(), TestResult::RunnerFailed); | ||||
|                     continue; | ||||
|                 } | ||||
|                 auto contents = file_result.value()->read_all(); | ||||
|                 auto parser = parse(contents); | ||||
|                 if (contents.is_error()) { | ||||
|                     warnln("Read error for {}: {}", out_path, contents.error()); | ||||
|                     s_test_results.set(url.path(), TestResult::RunnerFailed); | ||||
|                     continue; | ||||
|                 } | ||||
|                 auto parser = parse(contents.value()); | ||||
|                 auto out_doc_or_error = parser.parse(); | ||||
|                 if (out_doc_or_error.is_error()) { | ||||
|                     warnln("Parse error for {}: {}", out_path, out_doc_or_error.error()); | ||||
|  | @ -505,8 +516,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | |||
|     parser.parse(arguments); | ||||
| 
 | ||||
|     s_path = Core::File::real_path_for(filename); | ||||
|     auto file = TRY(Core::File::open(s_path, Core::OpenMode::ReadOnly)); | ||||
|     auto contents = file->read_all(); | ||||
|     auto file = TRY(Core::Stream::File::open(s_path, Core::Stream::OpenMode::Read)); | ||||
|     auto contents = TRY(file->read_all()); | ||||
| 
 | ||||
|     auto xml_parser = parse(contents); | ||||
|     auto result = xml_parser.parse(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sam Atkins
						Sam Atkins