1
0

feat: add current_exe in rust env

This commit is contained in:
2025-10-02 18:06:24 +08:00
parent d69563b5df
commit 5859264eca
3 changed files with 141 additions and 24 deletions

View File

@ -1,6 +1,8 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/rust/env.hpp>
#include <yycc/macro/os_detector.hpp>
#include <filesystem>
#define ENV ::yycc::rust::env
@ -9,7 +11,7 @@ namespace yycctest::rust::env {
constexpr char8_t VAR_NAME[] = u8"HOMER";
constexpr char8_t VAR_VALUE[] = u8"doh";
TEST(RustEnv, All) {
TEST(RustEnv, EnvVar) {
// Write a new variable should okey
{
auto rv = ENV::set_var(VAR_NAME, VAR_VALUE);
@ -42,4 +44,19 @@ namespace yycctest::rust::env {
}
}
}
TEST(RustEnv, CurrentExe) {
auto rv = ENV::current_exe();
ASSERT_TRUE(rv.has_value());
std::filesystem::path p(rv.value());
auto filename = p.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::rust::env