1
0
Files
YYCCommonplace/test/yycc/env.cpp
yyc12345 8b7ab2c870 feat: add lost functions for env namespace.
- add some lost functions for env namespace according to Rust std library. hiwever some functions are not implemented.
- change some function's signatures located in env namespace.
- reduce some useless error kine in env namespace.
2025-12-07 21:47:54 +08:00

62 lines
1.6 KiB
C++

#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/env.hpp>
#include <yycc/macro/os_detector.hpp>
#include <filesystem>
#define ENV ::yycc::env
namespace yycctest::env {
constexpr char8_t VAR_NAME[] = u8"HOMER";
constexpr char8_t VAR_VALUE[] = u8"doh";
TEST(Env, EnvVar) {
// Write a new variable should okey
{
auto rv = ENV::set_var(VAR_NAME, VAR_VALUE);
ASSERT_TRUE(rv.has_value());
}
// After writing, we can fetch it and check its value.
{
auto rv = ENV::get_var(VAR_NAME);
ASSERT_TRUE(rv.has_value());
EXPECT_EQ(rv.value(), VAR_VALUE);
}
// The we can delete it.
{
auto rv = ENV::del_var(VAR_NAME);
ASSERT_TRUE(rv.has_value());
}
// Delete inexisting variable also should be okey
{
auto rv = ENV::del_var(VAR_NAME);
ASSERT_TRUE(rv.has_value());
}
// After deleting, we can not fetch it anymore.
{
auto rv = ENV::get_var(VAR_NAME);
ASSERT_FALSE(rv.has_value());
}
}
TEST(Env, CurrentExe) {
auto rv = ENV::current_exe();
ASSERT_TRUE(rv.has_value());
auto filename = rv.value().filename().u8string();
#if defined(YYCC_OS_WINDOWS)
// Only Windows has special ext.
EXPECT_EQ(filename, u8"YYCCTest.exe");
#else
// Executable in other system are all in plain name.
EXPECT_EQ(filename, u8"YYCCTest");
#endif
}
} // namespace yycctest::env