Skip to content

Commit

Permalink
Improved directory scan and group parser
Browse files Browse the repository at this point in the history
  • Loading branch information
rfdavid committed May 7, 2023
1 parent 63be7c6 commit a7bf7f4
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 38 deletions.
10 changes: 10 additions & 0 deletions src/common/file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,15 @@ std::vector<std::string> FileUtils::globFilePath(const std::string& path) {
return result;
}

std::vector<std::string> FileUtils::findAllDirectories(const std::string& path) {
std::vector<std::string> directories;
for (const auto& entry : std::filesystem::recursive_directory_iterator(path)) {
if (entry.is_directory()) {
directories.push_back(entry.path().string());
}
}
return directories;
}

} // namespace common
} // namespace kuzu
2 changes: 2 additions & 0 deletions src/include/common/file_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class FileUtils {

static std::vector<std::string> globFilePath(const std::string& path);

static std::vector<std::string> findAllDirectories(const std::string& path);

static inline std::string getParentPath(const std::filesystem::path& path) {
return path.parent_path().string();
}
Expand Down
5 changes: 5 additions & 0 deletions test/include/test_helper/test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class TestHelper {
private:
static void initializeConnection(TestQueryConfig* config, Connection& conn);
static bool testQuery(TestQueryConfig* config, Connection& conn);
static void setConfigValue(
const std::string& line, std::string& configValue, const std::string& configKey);
static void setConfigValue(
const std::string& line, bool& configValue, const std::string& configKey);
static std::string extractConfigValue(const std::string& line, const std::string& configKey);
};

} // namespace testing
Expand Down
42 changes: 18 additions & 24 deletions test/runner/e2e_read_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ using namespace kuzu::common;

class EndToEndReadTest : public DBTest {
public:
EndToEndReadTest(TestConfig testConfig) : testConfig(std::move(testConfig)) {}
std::string getInputDir() override {
return TestHelper::appendKuzuRootPath("dataset/" + testConfig.dataset + "/");
}
EndToEndReadTest(TestConfig testConfig) : testConfig(std::move(testConfig)) {}
void TestBody() override {
for (auto& file : testConfig.files) {
if (testConfig.checkOrder) {
Expand All @@ -32,35 +32,29 @@ void registerTests(const std::vector<TestConfig> testConfig) {
}
}

std::vector<TestConfig> scanTestFiles(const std::string& path) {
TestConfig testConfig;
std::vector<TestConfig> tests;
std::string previousDirectory;
for (const auto& entry : std::filesystem::recursive_directory_iterator(path)) {
if (!entry.is_regular_file())
continue;
std::string testGroupFile = FileUtils::getParentPath(entry) + "/test.group";
if (!FileUtils::fileOrPathExists(testGroupFile))
continue;
if (FileUtils::getParentPathStem(entry) != previousDirectory) {
if (testConfig.isValid())
tests.push_back(testConfig);
testConfig = TestHelper::parseGroupFile(testGroupFile);
}
if (FileUtils::getFileExtension(entry) == ".test") {
TestConfig parseTestGroup(const std::string& path) {
auto testConfig = TestHelper::parseGroupFile(path + "/test.group");
for (const auto& entry : std::filesystem::directory_iterator(path)) {
if (entry.is_regular_file() && FileUtils::getFileExtension(entry) == ".test") {
testConfig.files.push_back(entry.path().string());
}
previousDirectory = FileUtils::getParentPathStem(entry);
}
if (testConfig.isValid())
tests.push_back(testConfig);
return tests;
return testConfig;
}

void scanTestFiles(const std::string& path, std::vector<TestConfig>& configs) {
for (const auto& directory : FileUtils::findAllDirectories(path)) {
if (FileUtils::fileOrPathExists(directory + "/test.group")) {
TestConfig config = parseTestGroup(directory);
configs.push_back(config);
}
}
}

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
std::vector<TestConfig> tests =
scanTestFiles(TestHelper::appendKuzuRootPath("test/test_files"));
registerTests(tests);
std::vector<TestConfig> configs;
scanTestFiles(TestHelper::appendKuzuRootPath("test/test_files"), configs);
registerTests(configs);
return RUN_ALL_TESTS();
}
4 changes: 2 additions & 2 deletions test/test_files/tinysnb/acc/test.group
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-GROUP TinySnbReadTest
-TEST Acc
-GROUP TinySnbReadTest
-TEST Acc
-DATASET tinysnb
-READ_ONLY TRUE
39 changes: 27 additions & 12 deletions test/test_helper/test_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,37 @@ TestConfig TestHelper::parseGroupFile(const std::string& path) {
std::ifstream ifs(path);
std::string line;
while (getline(ifs, line)) {
if (line.starts_with("-GROUP")) {
result.testGroup = line.substr(7, line.length());
}
if (line.starts_with("-TEST")) {
result.testName = line.substr(6, line.length());
}
if (line.starts_with("-DATASET")) {
result.dataset = line.substr(9, line.length());
}
if (line.starts_with("-CHECK_ORDER")) {
result.checkOrder = (line.substr(13, line.length()) == "TRUE");
}
setConfigValue(line, result.testGroup, "-GROUP");
setConfigValue(line, result.testName, "-TEST");
setConfigValue(line, result.dataset, "-DATASET");
setConfigValue(line, result.checkOrder, "-CHECK_ORDER");
}
return result;
}

void TestHelper::setConfigValue(
const std::string& line, std::string& configItem, const std::string& configKey) {
std::string value = extractConfigValue(line, configKey);
if (!value.empty())
configItem = value;
}

void TestHelper::setConfigValue(
const std::string& line, bool& configItem, const std::string& configKey) {
std::string value = extractConfigValue(line, configKey);
if (!value.empty())
configItem = (value == "TRUE");
}

std::string TestHelper::extractConfigValue(const std::string& line, const std::string& configKey) {
std::string value;
if (line.starts_with(configKey)) {
value = line.substr(configKey.length() + 1, line.length());
value.erase(remove_if(value.begin(), value.end(), isspace), value.end());
}
return value;
}

std::vector<std::unique_ptr<TestQueryConfig>> TestHelper::parseTestFile(
const std::string& path, bool checkOutputOrder) {
std::vector<std::unique_ptr<TestQueryConfig>> result;
Expand Down

0 comments on commit a7bf7f4

Please sign in to comment.