1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:07:46 +00:00

Everywhere: Rename {Deprecated => Byte}String

This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
This commit is contained in:
Ali Mohammad Pur 2023-12-16 17:49:34 +03:30 committed by Ali Mohammad Pur
parent 38d62563b3
commit 5e1499d104
1615 changed files with 10257 additions and 10257 deletions

View file

@ -18,7 +18,7 @@
namespace Test {
Crash::Crash(DeprecatedString test_type, Function<Crash::Failure()> crash_function, int crash_signal)
Crash::Crash(ByteString test_type, Function<Crash::Failure()> crash_function, int crash_signal)
: m_type(move(test_type))
, m_crash_function(move(crash_function))
, m_crash_signal(crash_signal)

View file

@ -8,7 +8,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Function.h>
#include <AK/Variant.h>
@ -28,7 +28,7 @@ public:
static constexpr int ANY_SIGNAL = -1;
Crash(DeprecatedString test_type, Function<Crash::Failure()> crash_function, int crash_signal = ANY_SIGNAL);
Crash(ByteString test_type, Function<Crash::Failure()> crash_function, int crash_signal = ANY_SIGNAL);
bool run(RunType run_type = RunType::UsingChildProcess);
@ -36,7 +36,7 @@ private:
using Report = Variant<Failure, int>;
bool do_report(Report report);
DeprecatedString m_type;
ByteString m_type;
Function<Crash::Failure()> m_crash_function;
int m_crash_signal;
};

View file

@ -87,16 +87,16 @@
} __testjs_flag_hook_##flag;
#define TEST_ROOT(path) \
DeprecatedString Test::JS::g_test_root_fragment = path
ByteString Test::JS::g_test_root_fragment = path
#define TESTJS_RUN_FILE_FUNCTION(...) \
struct __TestJS_run_file { \
__TestJS_run_file() \
{ \
::Test::JS::g_run_file = hook; \
} \
static ::Test::JS::IntermediateRunFileResult hook(DeprecatedString const&, JS::Realm&, JS::ExecutionContext&); \
} __testjs_common_run_file {}; \
#define TESTJS_RUN_FILE_FUNCTION(...) \
struct __TestJS_run_file { \
__TestJS_run_file() \
{ \
::Test::JS::g_run_file = hook; \
} \
static ::Test::JS::IntermediateRunFileResult hook(ByteString const&, JS::Realm&, JS::ExecutionContext&); \
} __testjs_common_run_file {}; \
::Test::JS::IntermediateRunFileResult __TestJS_run_file::hook(__VA_ARGS__)
namespace Test::JS {
@ -116,33 +116,33 @@ static consteval size_t __testjs_last()
static constexpr auto TOP_LEVEL_TEST_NAME = "__$$TOP_LEVEL$$__";
extern RefPtr<JS::VM> g_vm;
extern bool g_collect_on_every_allocation;
extern DeprecatedString g_currently_running_test;
extern ByteString g_currently_running_test;
struct FunctionWithLength {
JS::ThrowCompletionOr<JS::Value> (*function)(JS::VM&);
size_t length { 0 };
};
extern HashMap<DeprecatedString, FunctionWithLength> s_exposed_global_functions;
extern DeprecatedString g_test_root_fragment;
extern DeprecatedString g_test_root;
extern HashMap<ByteString, FunctionWithLength> s_exposed_global_functions;
extern ByteString g_test_root_fragment;
extern ByteString g_test_root;
extern int g_test_argc;
extern char** g_test_argv;
extern Function<void()> g_main_hook;
extern HashMap<bool*, Tuple<DeprecatedString, DeprecatedString, char>> g_extra_args;
extern HashMap<bool*, Tuple<ByteString, ByteString, char>> g_extra_args;
struct ParserError {
JS::ParserError error;
DeprecatedString hint;
ByteString hint;
};
struct JSFileResult {
DeprecatedString name;
ByteString name;
Optional<ParserError> error {};
double time_taken { 0 };
// A failed test takes precedence over a skipped test, which both have
// precedence over a passed test
Test::Result most_severe_test_result { Test::Result::Pass };
Vector<Test::Suite> suites {};
Vector<DeprecatedString> logged_messages {};
Vector<ByteString> logged_messages {};
};
enum class RunFileHookResult {
@ -151,11 +151,11 @@ enum class RunFileHookResult {
};
using IntermediateRunFileResult = AK::Result<JSFileResult, RunFileHookResult>;
extern IntermediateRunFileResult (*g_run_file)(DeprecatedString const&, JS::Realm&, JS::ExecutionContext&);
extern IntermediateRunFileResult (*g_run_file)(ByteString const&, JS::Realm&, JS::ExecutionContext&);
class TestRunner : public ::Test::TestRunner {
public:
TestRunner(DeprecatedString test_root, DeprecatedString common_path, bool print_times, bool print_progress, bool print_json, bool detailed_json)
TestRunner(ByteString test_root, ByteString common_path, bool print_times, bool print_progress, bool print_json, bool detailed_json)
: ::Test::TestRunner(move(test_root), print_times, print_progress, print_json, detailed_json)
, m_common_path(move(common_path))
{
@ -165,12 +165,12 @@ public:
virtual ~TestRunner() = default;
protected:
virtual void do_run_single_test(DeprecatedString const& test_path, size_t, size_t) override;
virtual Vector<DeprecatedString> get_test_paths() const override;
virtual JSFileResult run_file_test(DeprecatedString const& test_path);
virtual void do_run_single_test(ByteString const& test_path, size_t, size_t) override;
virtual Vector<ByteString> get_test_paths() const override;
virtual JSFileResult run_file_test(ByteString const& test_path);
void print_file_result(JSFileResult const& file_result) const;
DeprecatedString m_common_path;
ByteString m_common_path;
};
class TestRunnerGlobalObject final : public JS::GlobalObject {
@ -253,7 +253,7 @@ inline ErrorOr<JsonValue> get_test_results(JS::Realm& realm)
return JsonValue();
}
inline void TestRunner::do_run_single_test(DeprecatedString const& test_path, size_t, size_t)
inline void TestRunner::do_run_single_test(ByteString const& test_path, size_t, size_t)
{
auto file_result = run_file_test(test_path);
if (!m_print_json)
@ -263,10 +263,10 @@ inline void TestRunner::do_run_single_test(DeprecatedString const& test_path, si
ensure_suites().extend(file_result.suites);
}
inline Vector<DeprecatedString> TestRunner::get_test_paths() const
inline Vector<ByteString> TestRunner::get_test_paths() const
{
Vector<DeprecatedString> paths;
iterate_directory_recursively(m_test_root, [&](DeprecatedString const& file_path) {
Vector<ByteString> paths;
iterate_directory_recursively(m_test_root, [&](ByteString const& file_path) {
if (!file_path.ends_with(".js"sv))
return;
if (!file_path.ends_with("test-common.js"sv))
@ -276,7 +276,7 @@ inline Vector<DeprecatedString> TestRunner::get_test_paths() const
return paths;
}
inline JSFileResult TestRunner::run_file_test(DeprecatedString const& test_path)
inline JSFileResult TestRunner::run_file_test(ByteString const& test_path)
{
g_currently_running_test = test_path;
@ -342,7 +342,7 @@ inline JSFileResult TestRunner::run_file_test(DeprecatedString const& test_path)
auto result = parse_script(m_common_path, *realm);
if (result.is_error()) {
warnln("Unable to parse test-common.js");
warnln("{}", result.error().error.to_deprecated_string());
warnln("{}", result.error().error.to_byte_string());
warnln("{}", result.error().hint);
cleanup_and_exit();
}
@ -376,21 +376,21 @@ inline JSFileResult TestRunner::run_file_test(DeprecatedString const& test_path)
auto& arr = user_output.as_array();
for (auto& entry : arr.indexed_properties()) {
auto message = MUST(arr.get(entry.index()));
file_result.logged_messages.append(message.to_string_without_side_effects().to_deprecated_string());
file_result.logged_messages.append(message.to_string_without_side_effects().to_byte_string());
}
test_json.value().as_object().for_each_member([&](DeprecatedString const& suite_name, JsonValue const& suite_value) {
test_json.value().as_object().for_each_member([&](ByteString const& suite_name, JsonValue const& suite_value) {
Test::Suite suite { test_path, suite_name };
VERIFY(suite_value.is_object());
suite_value.as_object().for_each_member([&](const DeprecatedString& test_name, const JsonValue& test_value) {
suite_value.as_object().for_each_member([&](const ByteString& test_name, const JsonValue& test_value) {
Test::Case test { test_name, Test::Result::Fail, "", 0 };
VERIFY(test_value.is_object());
VERIFY(test_value.as_object().has("result"sv));
auto result = test_value.as_object().get_deprecated_string("result"sv);
auto result = test_value.as_object().get_byte_string("result"sv);
VERIFY(result.has_value());
auto result_string = result.value();
if (result_string == "pass") {
@ -401,7 +401,7 @@ inline JSFileResult TestRunner::run_file_test(DeprecatedString const& test_path)
m_counts.tests_failed++;
suite.most_severe_test_result = Test::Result::Fail;
VERIFY(test_value.as_object().has("details"sv));
auto details = test_value.as_object().get_deprecated_string("details"sv);
auto details = test_value.as_object().get_byte_string("details"sv);
VERIFY(result.has_value());
test.details = details.value();
} else if (result_string == "xfail") {
@ -462,9 +462,9 @@ inline JSFileResult TestRunner::run_file_test(DeprecatedString const& test_path)
detail_builder.append(error_as_error.stack_string());
}
test_case.details = detail_builder.to_deprecated_string();
test_case.details = detail_builder.to_byte_string();
} else {
test_case.details = error.to_string_without_side_effects().to_deprecated_string();
test_case.details = error.to_string_without_side_effects().to_byte_string();
}
suite.tests.append(move(test_case));
@ -542,7 +542,7 @@ inline void TestRunner::print_file_result(JSFileResult const& file_result) const
outln(" {}", message);
}
print_modifiers({ FG_RED });
outln(" {}", test_error.error.to_deprecated_string());
outln(" {}", test_error.error.to_byte_string());
outln();
return;
}

View file

@ -20,12 +20,12 @@ namespace JS {
RefPtr<::JS::VM> g_vm;
bool g_collect_on_every_allocation = false;
DeprecatedString g_currently_running_test;
HashMap<DeprecatedString, FunctionWithLength> s_exposed_global_functions;
ByteString g_currently_running_test;
HashMap<ByteString, FunctionWithLength> s_exposed_global_functions;
Function<void()> g_main_hook;
HashMap<bool*, Tuple<DeprecatedString, DeprecatedString, char>> g_extra_args;
IntermediateRunFileResult (*g_run_file)(DeprecatedString const&, JS::Realm&, JS::ExecutionContext&) = nullptr;
DeprecatedString g_test_root;
HashMap<bool*, Tuple<ByteString, ByteString, char>> g_extra_args;
IntermediateRunFileResult (*g_run_file)(ByteString const&, JS::Realm&, JS::ExecutionContext&) = nullptr;
ByteString g_test_root;
int g_test_argc;
char** g_test_argv;
@ -93,8 +93,8 @@ int main(int argc, char** argv)
bool print_json = false;
bool per_file = false;
StringView specified_test_root;
DeprecatedString common_path;
DeprecatedString test_glob;
ByteString common_path;
ByteString test_glob;
Core::ArgsParser args_parser;
args_parser.add_option(print_times, "Show duration of each test", "show-time", 't');
@ -128,27 +128,27 @@ int main(int argc, char** argv)
if (per_file)
print_json = true;
test_glob = DeprecatedString::formatted("*{}*", test_glob);
test_glob = ByteString::formatted("*{}*", test_glob);
if (getenv("DISABLE_DBG_OUTPUT")) {
AK::set_debug_enabled(false);
}
DeprecatedString test_root;
ByteString test_root;
if (!specified_test_root.is_empty()) {
test_root = DeprecatedString { specified_test_root };
test_root = ByteString { specified_test_root };
} else {
#ifdef AK_OS_SERENITY
test_root = LexicalPath::join("/home/anon/Tests"sv, DeprecatedString::formatted("{}-tests", program_name.split_view('-').last())).string();
test_root = LexicalPath::join("/home/anon/Tests"sv, ByteString::formatted("{}-tests", program_name.split_view('-').last())).string();
#else
char* serenity_source_dir = getenv("SERENITY_SOURCE_DIR");
if (!serenity_source_dir) {
warnln("No test root given, {} requires the SERENITY_SOURCE_DIR environment variable to be set", g_program_name);
return 1;
}
test_root = DeprecatedString::formatted("{}/{}", serenity_source_dir, g_test_root_fragment);
common_path = DeprecatedString::formatted("{}/Userland/Libraries/LibJS/Tests/test-common.js", serenity_source_dir);
test_root = ByteString::formatted("{}/{}", serenity_source_dir, g_test_root_fragment);
common_path = ByteString::formatted("{}/Userland/Libraries/LibJS/Tests/test-common.js", serenity_source_dir);
#endif
}
if (!FileSystem::is_directory(test_root)) {
@ -165,7 +165,7 @@ int main(int argc, char** argv)
warnln("No test root given, {} requires the SERENITY_SOURCE_DIR environment variable to be set", g_program_name);
return 1;
}
common_path = DeprecatedString::formatted("{}/Userland/Libraries/LibJS/Tests/test-common.js", serenity_source_dir);
common_path = ByteString::formatted("{}/Userland/Libraries/LibJS/Tests/test-common.js", serenity_source_dir);
#endif
}
@ -174,14 +174,14 @@ int main(int argc, char** argv)
warnln("Failed to resolve test root: {}", test_root_or_error.error());
return 1;
}
test_root = test_root_or_error.release_value().to_deprecated_string();
test_root = test_root_or_error.release_value().to_byte_string();
auto common_path_or_error = FileSystem::real_path(common_path);
if (common_path_or_error.is_error()) {
warnln("Failed to resolve common path: {}", common_path_or_error.error());
return 1;
}
common_path = common_path_or_error.release_value().to_deprecated_string();
common_path = common_path_or_error.release_value().to_byte_string();
if (chdir(test_root.characters()) < 0) {
auto saved_errno = errno;

View file

@ -9,7 +9,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Vector.h>
namespace Test {
@ -23,15 +23,15 @@ enum class Result {
};
struct Case {
DeprecatedString name;
ByteString name;
Result result;
DeprecatedString details;
ByteString details;
u64 duration_us;
};
struct Suite {
DeprecatedString path;
DeprecatedString name;
ByteString path;
ByteString name;
// A failed test takes precedence over a skipped test, which both have
// precedence over a passed test
Result most_severe_test_result { Result::Pass };

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Function.h>
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
@ -31,7 +31,7 @@ inline void run_with_randomness_source(Randomized::RandomnessSource source, Test
class TestCase : public RefCounted<TestCase> {
public:
TestCase(DeprecatedString const& name, TestFunction&& fn, bool is_benchmark)
TestCase(ByteString const& name, TestFunction&& fn, bool is_benchmark)
: m_name(name)
, m_function(move(fn))
, m_is_benchmark(is_benchmark)
@ -39,10 +39,10 @@ public:
}
bool is_benchmark() const { return m_is_benchmark; }
DeprecatedString const& name() const { return m_name; }
ByteString const& name() const { return m_name; }
TestFunction const& func() const { return m_function; }
static NonnullRefPtr<TestCase> randomized(DeprecatedString const& name, TestFunction&& test_function)
static NonnullRefPtr<TestCase> randomized(ByteString const& name, TestFunction&& test_function)
{
using namespace Randomized;
@ -101,7 +101,7 @@ public:
}
private:
DeprecatedString m_name;
ByteString m_name;
TestFunction m_function;
bool m_is_benchmark;
};

View file

@ -10,7 +10,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Format.h>
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
@ -29,7 +29,7 @@ public:
return s_the;
}
TestRunner(DeprecatedString test_root, bool print_times, bool print_progress, bool print_json, bool detailed_json = false)
TestRunner(ByteString test_root, bool print_times, bool print_progress, bool print_json, bool detailed_json = false)
: m_test_root(move(test_root))
, m_print_times(print_times)
, m_print_progress(print_progress)
@ -42,7 +42,7 @@ public:
virtual ~TestRunner() { s_the = nullptr; }
virtual void run(DeprecatedString test_glob);
virtual void run(ByteString test_glob);
Test::Counts const& counts() const { return m_counts; }
@ -64,11 +64,11 @@ protected:
void print_test_results() const;
void print_test_results_as_json() const;
virtual Vector<DeprecatedString> get_test_paths() const = 0;
virtual void do_run_single_test(DeprecatedString const&, size_t current_test_index, size_t num_tests) = 0;
virtual Vector<DeprecatedString> const* get_failed_test_names() const { return nullptr; }
virtual Vector<ByteString> get_test_paths() const = 0;
virtual void do_run_single_test(ByteString const&, size_t current_test_index, size_t num_tests) = 0;
virtual Vector<ByteString> const* get_failed_test_names() const { return nullptr; }
DeprecatedString m_test_root;
ByteString m_test_root;
bool m_print_times;
bool m_print_progress;
bool m_print_json;
@ -92,7 +92,7 @@ inline void cleanup()
exit(1);
}
inline void TestRunner::run(DeprecatedString test_glob)
inline void TestRunner::run(ByteString test_glob)
{
size_t progress_counter = 0;
auto test_paths = get_test_paths();
@ -243,11 +243,11 @@ inline void TestRunner::print_test_results_as_json() const
auto name = suite.name;
if (name == "__$$TOP_LEVEL$$__"sv)
name = DeprecatedString::empty();
name = ByteString::empty();
auto path = LexicalPath::relative_path(suite.path, m_test_root);
tests.set(DeprecatedString::formatted("{}/{}::{}", path, name, case_.name), result_name);
tests.set(ByteString::formatted("{}/{}::{}", path, name, case_.name), result_name);
}
}
@ -274,7 +274,7 @@ inline void TestRunner::print_test_results_as_json() const
root.set("files_total", m_counts.files_total);
root.set("duration", m_total_elapsed_time_in_ms / 1000.0);
}
outln("{}", root.to_deprecated_string());
outln("{}", root.to_byte_string());
}
}

View file

@ -22,7 +22,7 @@ inline double get_time_in_ms()
}
template<typename Callback>
inline void iterate_directory_recursively(DeprecatedString const& directory_path, Callback callback)
inline void iterate_directory_recursively(ByteString const& directory_path, Callback callback)
{
Core::DirIterator directory_iterator(directory_path, Core::DirIterator::Flags::SkipDots);
@ -32,7 +32,7 @@ inline void iterate_directory_recursively(DeprecatedString const& directory_path
if (fstatat(directory_iterator.fd(), name.characters(), &st, AT_SYMLINK_NOFOLLOW) < 0)
continue;
bool is_directory = S_ISDIR(st.st_mode);
auto full_path = DeprecatedString::formatted("{}/{}", directory_path, name);
auto full_path = ByteString::formatted("{}/{}", directory_path, name);
if (is_directory && name != "/Fixtures"sv) {
iterate_directory_recursively(full_path, callback);
} else if (!is_directory) {

View file

@ -99,7 +99,7 @@ void disable_reporting()
TestSuite::the().disable_reporting();
}
static DeprecatedString test_result_to_string(TestResult result)
static ByteString test_result_to_string(TestResult result)
{
switch (result) {
case TestResult::NotRun:
@ -117,7 +117,7 @@ static DeprecatedString test_result_to_string(TestResult result)
}
}
int TestSuite::main(DeprecatedString const& suite_name, Span<StringView> arguments)
int TestSuite::main(ByteString const& suite_name, Span<StringView> arguments)
{
m_suite_name = suite_name;
@ -154,7 +154,7 @@ int TestSuite::main(DeprecatedString const& suite_name, Span<StringView> argumen
return run(matching_tests);
}
Vector<NonnullRefPtr<TestCase>> TestSuite::find_cases(DeprecatedString const& search, bool find_tests, bool find_benchmarks)
Vector<NonnullRefPtr<TestCase>> TestSuite::find_cases(ByteString const& search, bool find_tests, bool find_benchmarks)
{
Vector<NonnullRefPtr<TestCase>> matches;
for (auto& t : m_cases) {

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Function.h>
#include <AK/Vector.h>
#include <LibTest/Macros.h>
@ -34,8 +34,8 @@ public:
}
int run(Vector<NonnullRefPtr<TestCase>> const&);
int main(DeprecatedString const& suite_name, Span<StringView> arguments);
Vector<NonnullRefPtr<TestCase>> find_cases(DeprecatedString const& search, bool find_tests, bool find_benchmarks);
int main(ByteString const& suite_name, Span<StringView> arguments);
Vector<NonnullRefPtr<TestCase>> find_cases(ByteString const& search, bool find_tests, bool find_benchmarks);
void add_case(NonnullRefPtr<TestCase> const& test_case)
{
m_cases.append(test_case);
@ -67,7 +67,7 @@ private:
Vector<NonnullRefPtr<TestCase>> m_cases;
u64 m_testtime = 0;
u64 m_benchtime = 0;
DeprecatedString m_suite_name;
ByteString m_suite_name;
u64 m_benchmark_repetitions = 1;
u64 m_randomized_runs = 100;
Function<void()> m_setup;