2021-08-13 19:24:16 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Itamar S. <itamar8910@gmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/LexicalPath.h>
|
|
|
|
#include <LibCore/DirIterator.h>
|
2022-03-10 15:27:32 +03:00
|
|
|
#include <LibCore/Stream.h>
|
2021-08-13 19:24:16 +03:00
|
|
|
#include <LibCpp/Parser.h>
|
|
|
|
#include <LibTest/TestCase.h>
|
|
|
|
|
2022-03-20 21:38:55 +03:00
|
|
|
constexpr char TESTS_ROOT_DIR[] = "/home/anon/Tests/cpp-tests/preprocessor";
|
2021-08-13 19:24:16 +03:00
|
|
|
|
2022-12-04 21:02:33 +03:00
|
|
|
static DeprecatedString read_all(DeprecatedString const& path)
|
2021-08-13 19:24:16 +03:00
|
|
|
{
|
2022-03-10 15:27:32 +03:00
|
|
|
auto file = MUST(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
|
|
|
|
auto file_size = MUST(file->size());
|
|
|
|
auto content = MUST(ByteBuffer::create_uninitialized(file_size));
|
2022-12-11 21:21:36 +03:00
|
|
|
MUST(file->read_entire_buffer(content.bytes()));
|
2022-12-04 21:02:33 +03:00
|
|
|
return DeprecatedString { content.bytes() };
|
2021-08-13 19:24:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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 };
|
2022-07-11 20:32:29 +03:00
|
|
|
if (!path.has_extension(".cpp"sv))
|
2021-08-13 19:24:16 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
outln("Checking {}...", path.basename());
|
|
|
|
|
2022-12-04 21:02:33 +03:00
|
|
|
auto ast_file_path = DeprecatedString::formatted("{}.txt", file_path.substring(0, file_path.length() - sizeof(".cpp") + 1));
|
2021-08-13 19:24:16 +03:00
|
|
|
|
|
|
|
auto source = read_all(file_path);
|
|
|
|
auto target = read_all(ast_file_path);
|
|
|
|
|
|
|
|
StringView source_view(source);
|
|
|
|
Cpp::Preprocessor preprocessor(file_path, source_view);
|
|
|
|
|
|
|
|
auto target_lines = target.split_view('\n');
|
|
|
|
auto tokens = preprocessor.process_and_lex();
|
|
|
|
|
|
|
|
EXPECT_EQ(tokens.size(), target_lines.size());
|
|
|
|
for (size_t i = 0; i < tokens.size(); ++i) {
|
2022-12-06 04:12:49 +03:00
|
|
|
EXPECT_EQ(tokens[i].to_deprecated_string(), target_lines[i]);
|
2021-08-13 19:24:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|