Files
mandy/runtime/test/xdxr_build_output_test.cpp
thiefyzheng b17397f0dd tests: derive every test's scratch folder from test_temp_dir::temp_dir, not GetTempPath (TEST-TEMPDIR-STRIPPED-ENV)
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.
2026-11-28 19:01:06 +00:00

45 lines
1.6 KiB
C++

// Exercise the fixture's output preparation without initializing Vulkan.
#include "test_temp_dir.h"
#include "xdxr_build_output.h"
#include <chrono>
#include <cstdio>
#include <fstream>
#include <string>
namespace fs = std::filesystem;
#define CHECK(condition) do { \
if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \
} while (0)
int main() {
const auto suffix = std::chrono::steady_clock::now().time_since_epoch().count();
const auto root = testfiles::temp_dir() / ("leonida-xdxr-output-" + std::to_string(suffix));
CHECK(fs::create_directory(root));
struct Cleanup {
fs::path path;
~Cleanup() { std::error_code ec; fs::remove_all(path, ec); }
} cleanup{root};
const auto output = root / "relocated" / "xdxr_build_cases";
CHECK(!prepare_xdxr_build_output(output, true));
CHECK(!fs::exists(output.parent_path()));
CHECK(!prepare_xdxr_build_output(output, false));
CHECK(fs::is_directory(output));
CHECK(bool(std::ofstream(output / "old.json") << "{}"));
CHECK(bool(std::ofstream(output / "old.bin") << "case"));
CHECK(bool(std::ofstream(output / "keep.txt") << "keep"));
CHECK(!prepare_xdxr_build_output(output, true));
CHECK(fs::is_regular_file(output / "old.json"));
CHECK(fs::is_regular_file(output / "old.bin"));
CHECK(!prepare_xdxr_build_output(output, false));
CHECK(!fs::exists(output / "old.json"));
CHECK(!fs::exists(output / "old.bin"));
CHECK(fs::is_regular_file(output / "keep.txt"));
CHECK(prepare_xdxr_build_output(output / "keep.txt", false));
}