mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:24:58 +00:00
Tests: Use Core::Environment instead of Core::System::*env()
This commit is contained in:
parent
7109f3706e
commit
dd92c33498
2 changed files with 11 additions and 11 deletions
|
@ -8,7 +8,7 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <LibCore/DateTime.h>
|
#include <LibCore/DateTime.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/Environment.h>
|
||||||
#include <LibTest/TestCase.h>
|
#include <LibTest/TestCase.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ class TimeZoneGuard {
|
||||||
public:
|
public:
|
||||||
explicit TimeZoneGuard(StringView time_zone)
|
explicit TimeZoneGuard(StringView time_zone)
|
||||||
{
|
{
|
||||||
if (auto const* current_time_zone = getenv("TZ"))
|
if (auto current_time_zone = Core::Environment::get("TZ"sv); current_time_zone.has_value())
|
||||||
m_time_zone = MUST(String::from_utf8({ current_time_zone, strlen(current_time_zone) }));
|
m_time_zone = MUST(String::from_utf8(*current_time_zone));
|
||||||
|
|
||||||
update(time_zone);
|
update(time_zone);
|
||||||
}
|
}
|
||||||
|
@ -25,16 +25,16 @@ public:
|
||||||
~TimeZoneGuard()
|
~TimeZoneGuard()
|
||||||
{
|
{
|
||||||
if (m_time_zone.has_value())
|
if (m_time_zone.has_value())
|
||||||
TRY_OR_FAIL(Core::System::setenv("TZ"sv, *m_time_zone, true));
|
TRY_OR_FAIL(Core::Environment::set("TZ"sv, *m_time_zone, Core::Environment::Overwrite::Yes));
|
||||||
else
|
else
|
||||||
TRY_OR_FAIL(Core::System::unsetenv("TZ"sv));
|
TRY_OR_FAIL(Core::Environment::unset("TZ"sv));
|
||||||
|
|
||||||
tzset();
|
tzset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(StringView time_zone)
|
void update(StringView time_zone)
|
||||||
{
|
{
|
||||||
TRY_OR_FAIL(Core::System::setenv("TZ"sv, time_zone, true));
|
TRY_OR_FAIL(Core::Environment::set("TZ"sv, time_zone, Core::Environment::Overwrite::Yes));
|
||||||
tzset();
|
tzset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/Environment.h>
|
||||||
#include <LibJS/Runtime/ArrayBuffer.h>
|
#include <LibJS/Runtime/ArrayBuffer.h>
|
||||||
#include <LibTest/JavaScriptTestRunner.h>
|
#include <LibTest/JavaScriptTestRunner.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -95,14 +95,14 @@ TESTJS_GLOBAL_FUNCTION(set_time_zone, setTimeZone)
|
||||||
{
|
{
|
||||||
auto current_time_zone = JS::js_null();
|
auto current_time_zone = JS::js_null();
|
||||||
|
|
||||||
if (auto const* time_zone = getenv("TZ"))
|
if (auto time_zone = Core::Environment::get("TZ"sv); time_zone.has_value())
|
||||||
current_time_zone = JS::PrimitiveString::create(vm, StringView { time_zone, strlen(time_zone) });
|
current_time_zone = JS::PrimitiveString::create(vm, *time_zone);
|
||||||
|
|
||||||
if (auto time_zone = vm.argument(0); time_zone.is_null()) {
|
if (auto time_zone = vm.argument(0); time_zone.is_null()) {
|
||||||
if (auto result = Core::System::unsetenv("TZ"sv); result.is_error())
|
if (auto result = Core::Environment::unset("TZ"sv); result.is_error())
|
||||||
return vm.throw_completion<JS::InternalError>(MUST(String::formatted("Could not unset time zone: {}", result.error())));
|
return vm.throw_completion<JS::InternalError>(MUST(String::formatted("Could not unset time zone: {}", result.error())));
|
||||||
} else {
|
} else {
|
||||||
if (auto result = Core::System::setenv("TZ"sv, TRY(time_zone.to_string(vm)), true); result.is_error())
|
if (auto result = Core::Environment::set("TZ"sv, TRY(time_zone.to_string(vm)), Core::Environment::Overwrite::Yes); result.is_error())
|
||||||
return vm.throw_completion<JS::InternalError>(MUST(String::formatted("Could not set time zone: {}", result.error())));
|
return vm.throw_completion<JS::InternalError>(MUST(String::formatted("Could not set time zone: {}", result.error())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue