Skip to content

Commit 7ebf78a

Browse files
apply change to acount for windows
1 parent 3bfe548 commit 7ebf78a

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

code/logic/fossil/crabdb/cacheshell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ bool fossil_bluecrab_cacheshell_load(const char *path);
260260
}
261261
#include <string>
262262
#include <vector>
263+
#include <filesystem>
263264
#include <functional>
264265
#include <cstring>
265266

code/tests/cases/test_cacheshell.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,22 +260,29 @@ FOSSIL_TEST(c_test_cacheshell_threadsafe_toggle) {
260260
}
261261

262262
FOSSIL_TEST(c_test_cacheshell_persistence_save_load) {
263-
fossil_bluecrab_cacheshell_init(0);
263+
#ifdef _WIN32
264+
const char *snapshot_path = ".\\cacheshell_test.snapshot";
265+
#else
266+
const char *snapshot_path = "/tmp/cacheshell_test.snapshot";
267+
#endif
268+
269+
remove(snapshot_path); // ensure clean start
270+
271+
ASSUME_ITS_TRUE(fossil_bluecrab_cacheshell_init(0));
264272
fossil_bluecrab_cacheshell_clear();
265273
ASSUME_ITS_TRUE(fossil_bluecrab_cacheshell_set("persist", "value"));
266-
ASSUME_ITS_TRUE(fossil_bluecrab_cacheshell_save("/tmp/cacheshell_test.snapshot"));
267-
274+
ASSUME_ITS_TRUE(fossil_bluecrab_cacheshell_save(snapshot_path));
268275
fossil_bluecrab_cacheshell_shutdown();
269276

270277
ASSUME_ITS_TRUE(fossil_bluecrab_cacheshell_init(0));
271-
272278
fossil_bluecrab_cacheshell_clear();
273279
ASSUME_ITS_FALSE(fossil_bluecrab_cacheshell_exists("persist"));
274280

275-
ASSUME_ITS_TRUE(fossil_bluecrab_cacheshell_load("/tmp/cacheshell_test.snapshot"));
276-
ASSUME_ITS_TRUE(fossil_bluecrab_cacheshell_load("/tmp/cacheshell_test.snapshot"));
281+
ASSUME_ITS_TRUE(fossil_bluecrab_cacheshell_load(snapshot_path));
282+
ASSUME_ITS_TRUE(fossil_bluecrab_cacheshell_load(snapshot_path)); // idempotent load
277283

278284
fossil_bluecrab_cacheshell_shutdown();
285+
remove(snapshot_path); // cleanup
279286
}
280287

281288
FOSSIL_TEST(c_test_cacheshell_init_with_limit) {

code/tests/cases/test_cacheshell.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,21 +257,34 @@ FOSSIL_TEST(cpp_test_cacheshell_threadsafe_toggle) {
257257
}
258258

259259
FOSSIL_TEST(cpp_test_cacheshell_persistence_save_load) {
260+
std::string snapshot;
261+
try {
262+
snapshot = (std::filesystem::temp_directory_path() / "cacheshell_test.snapshot").string();
263+
} catch (...) {
264+
snapshot = "cacheshell_test.snapshot"; // fallback
265+
}
266+
260267
CacheShell::init(0);
261268
CacheShell::clear();
262269
ASSUME_ITS_TRUE(CacheShell::set("persist", "value"));
263-
ASSUME_ITS_TRUE(CacheShell::save("/tmp/cacheshell_test.snapshot"));
264-
270+
ASSUME_ITS_TRUE(CacheShell::save(snapshot.c_str()));
265271
CacheShell::shutdown();
266272

267273
ASSUME_ITS_TRUE(CacheShell::init(0));
268274
CacheShell::clear();
269275
ASSUME_ITS_FALSE(CacheShell::exists("persist"));
270276

271-
ASSUME_ITS_TRUE(CacheShell::load("/tmp/cacheshell_test.snapshot"));
272-
ASSUME_ITS_TRUE(CacheShell::load("/tmp/cacheshell_test.snapshot"));
277+
// Load twice to ensure idempotent behavior
278+
ASSUME_ITS_TRUE(CacheShell::load(snapshot.c_str()));
279+
ASSUME_ITS_TRUE(CacheShell::load(snapshot.c_str()));
280+
std::string val;
281+
ASSUME_ITS_TRUE(CacheShell::get("persist", val));
282+
ASSUME_ITS_TRUE(val == "value");
273283

274284
CacheShell::shutdown();
285+
286+
// Best-effort cleanup
287+
(void)std::filesystem::remove(snapshot);
275288
}
276289

277290
FOSSIL_TEST(cpp_test_cacheshell_init_with_limit) {

0 commit comments

Comments
 (0)