mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 19:38:36 +00:00
With TMP, TEMP and USERPROFILE all unset, GetTempPathW returns C:\Windows\, and the throwing create_directories/copy_file/ofstream on C:\Windows\leonida_* aborts with 0xc0000409 before the test body runs. runtime/test/test_temp_dir.h grows one entry, testfiles::temp_dir(): LEONIDA_TEST_DIR when set, the current directory when the temp environment is stripped (Windows), else the standard temp resolution. Fifty-two test files and the tiny_game fixture that called GetTempPathA/W or temp_directory_path directly now use it; d3d12_queue_handover_test.cpp also checks the _sopen_s result in capture_stderr instead of silently returning empty stderr. One runtime source function needed the same fallback because tests exercise it: tls_host_clone_dir in runtime/src/pe_loader.cpp (the loader_tls tests). Rebased onto current main after its D3D-448 additions to d3d12_mesh_test.cpp (3-way; the mesh test keeps both). Verification on a Windows VM: stripped environment - the previously crashing d3d12 tests exit 77 (no usable Vulkan device) instead of aborting, file_system_test runs all 505 checks and loader_test all 95 with zero failures; normal environment - identical outcomes; LEONIDA_TEST_DIR honored under a fully stripped environment (the scratch folder observed mid-run inside it, cleaned up after the pass). The finding is whoalin1's (coordination issue #14, 02:37:44Z). AI-assisted.
47 lines
2.1 KiB
C++
47 lines
2.1 KiB
C++
#include "test_temp_dir.h"
|
|
#include "shader_fixture_path.h"
|
|
#include <cstdio>
|
|
#include <chrono>
|
|
#include <fstream>
|
|
#include <string>
|
|
|
|
int main() {
|
|
namespace fs = std::filesystem;
|
|
const auto root = testfiles::temp_dir() / ("leonida_fixture_path_" +
|
|
std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
|
fs::create_directories(root / "generated");
|
|
const auto previous = fs::current_path();
|
|
int result = 0;
|
|
try {
|
|
fs::current_path(root);
|
|
std::ofstream("generated/test.spv") << "packaged";
|
|
const auto original = root / "build" / "test.spv";
|
|
if (vktest::shader_fixture_path(original) != fs::path("generated/test.spv")) result = 1;
|
|
fs::create_directory("build");
|
|
std::ofstream(original) << "local";
|
|
if (vktest::shader_fixture_path(original) != original) result = 1;
|
|
const auto missing = root / "build" / "missing.spv";
|
|
if (vktest::shader_fixture_path(missing) != missing) result = 1;
|
|
fs::remove(original);
|
|
fs::remove("generated/test.spv");
|
|
fs::create_directory("generated/test.spv");
|
|
if (vktest::shader_fixture_path(original) != original) result = 1;
|
|
|
|
// The CMake fixture macros pass narrow UTF-8 strings.
|
|
const auto unicode = root / u8"\u6771\u4eac" / u8"\u96ea.spv";
|
|
const auto encoded = unicode.u8string();
|
|
const std::string compiled_utf8(encoded.begin(), encoded.end());
|
|
fs::create_directory(unicode.parent_path());
|
|
std::ofstream(unicode) << "local unicode";
|
|
if (vktest::shader_fixture_path(compiled_utf8.c_str()) != unicode) result = 1;
|
|
fs::remove(unicode);
|
|
const auto packaged_unicode = fs::path("generated") / unicode.filename();
|
|
std::ofstream(packaged_unicode) << "packaged unicode";
|
|
if (vktest::shader_fixture_path(compiled_utf8.c_str()) != packaged_unicode) result = 1;
|
|
} catch (...) { result = 1; }
|
|
fs::current_path(previous);
|
|
fs::remove_all(root);
|
|
std::puts(result ? "shader fixture lookup failed" : "shader fixture lookup passed");
|
|
return result;
|
|
}
|