File tree Expand file tree Collapse file tree 3 files changed +31
-10
lines changed Expand file tree Collapse file tree 3 files changed +31
-10
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -260,22 +260,29 @@ FOSSIL_TEST(c_test_cacheshell_threadsafe_toggle) {
260260}
261261
262262FOSSIL_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
281288FOSSIL_TEST (c_test_cacheshell_init_with_limit ) {
Original file line number Diff line number Diff line change @@ -257,21 +257,34 @@ FOSSIL_TEST(cpp_test_cacheshell_threadsafe_toggle) {
257257}
258258
259259FOSSIL_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
277290FOSSIL_TEST (cpp_test_cacheshell_init_with_limit) {
You can’t perform that action at this time.
0 commit comments