summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2023-03-02 17:03:53 +0000
committerAndreas Kling <kling@serenityos.org>2023-03-05 20:23:42 +0100
commit728b07fbf64d4a34ef928fddc7ac185bf656c438 (patch)
tree3b754dae600b70f21f776a86e408c4434a4fdade
parent23aec16e8b0186171b471b375d6fa172efd2ed1d (diff)
downloadserenity-728b07fbf64d4a34ef928fddc7ac185bf656c438.zip
Tests: Migrate to Directory::for_each_entry()
-rw-r--r--Tests/LibAudio/TestFLACSpec.cpp17
-rw-r--r--Tests/LibCpp/test-cpp-parser.cpp18
-rw-r--r--Tests/LibCpp/test-cpp-preprocessor.cpp18
3 files changed, 23 insertions, 30 deletions
diff --git a/Tests/LibAudio/TestFLACSpec.cpp b/Tests/LibAudio/TestFLACSpec.cpp
index 515c72acb4..7c801ee0ca 100644
--- a/Tests/LibAudio/TestFLACSpec.cpp
+++ b/Tests/LibAudio/TestFLACSpec.cpp
@@ -5,9 +5,8 @@
*/
#include <AK/LexicalPath.h>
-#include <AK/Types.h>
#include <LibAudio/FlacLoader.h>
-#include <LibCore/DirIterator.h>
+#include <LibCore/Directory.h>
#include <LibTest/TestCase.h>
struct FlacTest : Test::TestCase {
@@ -46,14 +45,12 @@ struct DiscoverFLACTestsHack {
DiscoverFLACTestsHack()
{
// FIXME: Also run (our own) tests in this directory.
- auto test_iterator = Core::DirIterator { "./SpecTests", Core::DirIterator::Flags::SkipParentAndBaseDir };
-
- while (test_iterator.has_next()) {
- auto file = LexicalPath { test_iterator.next_full_path() };
- if (file.extension() == "flac"sv) {
- Test::add_test_case_to_suite(make_ref_counted<FlacTest>(move(file)));
- }
- }
+ (void)Core::Directory::for_each_entry("./SpecTests"sv, Core::DirIterator::Flags::SkipParentAndBaseDir, [](auto const& entry, auto const& directory) -> ErrorOr<IterationDecision> {
+ auto path = LexicalPath::join(directory.path().string(), entry.name);
+ if (path.extension() == "flac"sv)
+ Test::add_test_case_to_suite(make_ref_counted<FlacTest>(path));
+ return IterationDecision::Continue;
+ });
}
};
// Hack taken from TEST_CASE; the above constructor will run as part of global initialization before the tests are actually executed
diff --git a/Tests/LibCpp/test-cpp-parser.cpp b/Tests/LibCpp/test-cpp-parser.cpp
index 9e9f094997..5bcc7dabc1 100644
--- a/Tests/LibCpp/test-cpp-parser.cpp
+++ b/Tests/LibCpp/test-cpp-parser.cpp
@@ -5,13 +5,13 @@
*/
#include <AK/LexicalPath.h>
-#include <LibCore/DirIterator.h>
+#include <LibCore/Directory.h>
#include <LibCore/File.h>
#include <LibCpp/Parser.h>
#include <LibTest/TestCase.h>
#include <unistd.h>
-constexpr char TESTS_ROOT_DIR[] = "/home/anon/Tests/cpp-tests/parser";
+constexpr StringView TESTS_ROOT_DIR = "/home/anon/Tests/cpp-tests/parser"sv;
static DeprecatedString read_all(DeprecatedString const& path)
{
@@ -24,16 +24,13 @@ static DeprecatedString read_all(DeprecatedString const& path)
TEST_CASE(test_regression)
{
- Core::DirIterator directory_iterator(TESTS_ROOT_DIR, Core::DirIterator::Flags::SkipDots);
-
- while (directory_iterator.has_next()) {
- auto file_path = directory_iterator.next_full_path();
-
- auto path = LexicalPath { file_path };
+ MUST(Core::Directory::for_each_entry(TESTS_ROOT_DIR, Core::DirIterator::Flags::SkipDots, [](auto const& entry, auto const& directory) -> ErrorOr<IterationDecision> {
+ auto path = LexicalPath::join(directory.path().string(), entry.name);
if (!path.has_extension(".cpp"sv))
- continue;
+ return IterationDecision::Continue;
outln("Checking {}...", path.basename());
+ auto file_path = path.string();
auto ast_file_path = DeprecatedString::formatted("{}.ast", file_path.substring(0, file_path.length() - sizeof(".cpp") + 1));
@@ -75,5 +72,6 @@ TEST_CASE(test_regression)
auto equal = content == target_ast;
EXPECT(equal);
- }
+ return IterationDecision::Continue;
+ }));
}
diff --git a/Tests/LibCpp/test-cpp-preprocessor.cpp b/Tests/LibCpp/test-cpp-preprocessor.cpp
index 03bdf029db..39a50d3f59 100644
--- a/Tests/LibCpp/test-cpp-preprocessor.cpp
+++ b/Tests/LibCpp/test-cpp-preprocessor.cpp
@@ -5,12 +5,12 @@
*/
#include <AK/LexicalPath.h>
-#include <LibCore/DirIterator.h>
+#include <LibCore/Directory.h>
#include <LibCore/File.h>
#include <LibCpp/Parser.h>
#include <LibTest/TestCase.h>
-constexpr char TESTS_ROOT_DIR[] = "/home/anon/Tests/cpp-tests/preprocessor";
+constexpr StringView TESTS_ROOT_DIR = "/home/anon/Tests/cpp-tests/preprocessor"sv;
static DeprecatedString read_all(DeprecatedString const& path)
{
@@ -23,16 +23,13 @@ static DeprecatedString read_all(DeprecatedString const& path)
TEST_CASE(test_regression)
{
- Core::DirIterator directory_iterator(TESTS_ROOT_DIR, Core::DirIterator::Flags::SkipDots);
-
- while (directory_iterator.has_next()) {
- auto file_path = directory_iterator.next_full_path();
-
- auto path = LexicalPath { file_path };
+ MUST(Core::Directory::for_each_entry(TESTS_ROOT_DIR, Core::DirIterator::Flags::SkipDots, [](auto const& entry, auto const& directory) -> ErrorOr<IterationDecision> {
+ auto path = LexicalPath::join(directory.path().string(), entry.name);
if (!path.has_extension(".cpp"sv))
- continue;
+ return IterationDecision::Continue;
outln("Checking {}...", path.basename());
+ auto file_path = path.string();
auto ast_file_path = DeprecatedString::formatted("{}.txt", file_path.substring(0, file_path.length() - sizeof(".cpp") + 1));
@@ -49,5 +46,6 @@ TEST_CASE(test_regression)
for (size_t i = 0; i < tokens.size(); ++i) {
EXPECT_EQ(tokens[i].to_deprecated_string(), target_lines[i]);
}
- }
+ return IterationDecision::Continue;
+ }));
}