mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
LibTest: Extract some useful functions from TestRunner.h
This allows other test like programs to use these without needing to link to LibTest.
This commit is contained in:
parent
6b437c576f
commit
b6094b7a3d
2 changed files with 46 additions and 31 deletions
|
@ -12,13 +12,12 @@
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/JsonValue.h>
|
#include <AK/JsonValue.h>
|
||||||
|
#include <AK/LexicalPath.h>
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibCore/DirIterator.h>
|
|
||||||
#include <LibTest/Results.h>
|
#include <LibTest/Results.h>
|
||||||
#include <fcntl.h>
|
#include <LibTest/TestRunnerUtil.h>
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
namespace Test {
|
namespace Test {
|
||||||
|
|
||||||
|
@ -92,34 +91,6 @@ inline void cleanup()
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double get_time_in_ms()
|
|
||||||
{
|
|
||||||
struct timeval tv1;
|
|
||||||
auto return_code = gettimeofday(&tv1, nullptr);
|
|
||||||
VERIFY(return_code >= 0);
|
|
||||||
return static_cast<double>(tv1.tv_sec) * 1000.0 + static_cast<double>(tv1.tv_usec) / 1000.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Callback>
|
|
||||||
inline void iterate_directory_recursively(String const& directory_path, Callback callback)
|
|
||||||
{
|
|
||||||
Core::DirIterator directory_iterator(directory_path, Core::DirIterator::Flags::SkipDots);
|
|
||||||
|
|
||||||
while (directory_iterator.has_next()) {
|
|
||||||
auto name = directory_iterator.next_path();
|
|
||||||
struct stat st = {};
|
|
||||||
if (fstatat(directory_iterator.fd(), name.characters(), &st, AT_SYMLINK_NOFOLLOW) < 0)
|
|
||||||
continue;
|
|
||||||
bool is_directory = S_ISDIR(st.st_mode);
|
|
||||||
auto full_path = String::formatted("{}/{}", directory_path, name);
|
|
||||||
if (is_directory && name != "/Fixtures"sv) {
|
|
||||||
iterate_directory_recursively(full_path, callback);
|
|
||||||
} else if (!is_directory) {
|
|
||||||
callback(full_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void TestRunner::run(String test_glob)
|
inline void TestRunner::run(String test_glob)
|
||||||
{
|
{
|
||||||
size_t progress_counter = 0;
|
size_t progress_counter = 0;
|
||||||
|
|
44
Userland/Libraries/LibTest/TestRunnerUtil.h
Normal file
44
Userland/Libraries/LibTest/TestRunnerUtil.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, the SerenityOS developers.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibCore/DirIterator.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
namespace Test {
|
||||||
|
|
||||||
|
inline double get_time_in_ms()
|
||||||
|
{
|
||||||
|
struct timeval tv1;
|
||||||
|
auto return_code = gettimeofday(&tv1, nullptr);
|
||||||
|
VERIFY(return_code >= 0);
|
||||||
|
return static_cast<double>(tv1.tv_sec) * 1000.0 + static_cast<double>(tv1.tv_usec) / 1000.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Callback>
|
||||||
|
inline void iterate_directory_recursively(String const& directory_path, Callback callback)
|
||||||
|
{
|
||||||
|
Core::DirIterator directory_iterator(directory_path, Core::DirIterator::Flags::SkipDots);
|
||||||
|
|
||||||
|
while (directory_iterator.has_next()) {
|
||||||
|
auto name = directory_iterator.next_path();
|
||||||
|
struct stat st = {};
|
||||||
|
if (fstatat(directory_iterator.fd(), name.characters(), &st, AT_SYMLINK_NOFOLLOW) < 0)
|
||||||
|
continue;
|
||||||
|
bool is_directory = S_ISDIR(st.st_mode);
|
||||||
|
auto full_path = String::formatted("{}/{}", directory_path, name);
|
||||||
|
if (is_directory && name != "/Fixtures"sv) {
|
||||||
|
iterate_directory_recursively(full_path, callback);
|
||||||
|
} else if (!is_directory) {
|
||||||
|
callback(full_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue