@@ -6,6 +6,7 @@ import std;
66import mcpplibs.mtest;
77import mcpp.config;
88import mcpp.home.files;
9+ import mcpplibs.os.fs;
910import mcpp.fallback.config_migration;
1011import mcpp.pm.index_spec;
1112
@@ -350,22 +351,39 @@ UTest config_value_is_replaced_whole{"Config/ConfigValueIsReplacedWhole", [] {
350351 std::ofstream (cfg.configFile ) << " [xlings]\n binary = \" bundled\"\n " << padding << " \n [toolchain]\n default = \" gcc@16.1.0\"\n " ;
351352 }
352353 std::atomic<int > partial{0 };
354+ // What the first reader that missed the value saw: the failure should say
355+ // whether the read was refused or read something else.
356+ std::string first;
353357 // Windows refuses a rename over a file a reader holds open, and the writer retries
354358 // (replace_file); a reader there pauses between reads, as the readers of a home do, where
355359 // elsewhere it reads without a pause. A failed write stops and joins the reader (jthread).
356360 const bool pauses = host () == platform::windows;
357361 std::jthread reader ([&](std::stop_token stop) {
358362 while (!stop.stop_requested ()) {
359363 // As mcpp reads it (read_whole), which waits out a replacement on Windows.
360- if (!mcpp::home::read_whole (cfg.configFile ).value_or (" " ).contains (" [toolchain]\n default = \" " )) ++partial;
364+ const auto text = mcpp::home::read_whole (cfg.configFile );
365+ if (!text.value_or (" " ).contains (" [toolchain]\n default = \" " ) && partial++ == 0 ) {
366+ if (!text) {
367+ const auto again = mcpplibs::os::fs::read (cfg.configFile );
368+ first = std::format (" no text; read at once after it: {}" ,
369+ again ? std::format (" {} bytes" , again->size ()) : again.error ().message ());
370+ } else {
371+ const auto at = text->find (" [toolchain]" );
372+ std::string excerpt;
373+ for (char c : text->substr (at == std::string::npos ? 0 : at, 48 ))
374+ excerpt += c == ' \n ' ? std::string (" \\ n" ) : c == ' \r ' ? std::string (" \\ r" ) : std::string (1 , c);
375+ first = std::format (" {} bytes, at [toolchain]: {}" , text->size (),
376+ at == std::string::npos ? std::string (" (absent)" ) : excerpt);
377+ }
378+ }
361379 if (pauses) std::this_thread::sleep_for (std::chrono::milliseconds{1 });
362380 }
363381 });
364382 for (int i = 0 ; i < 200 ; ++i)
365383 expect (fatal (mcpp::config::write_config_value (cfg, " toolchain" , " default" , i % 2 ? " \" llvm@23.1.3\" " : " \" gcc@16.1.0\" " ).has_value ()));
366384 reader.request_stop ();
367385 reader.join ();
368- expect (eq (partial.load (), 0 )) << " a reader saw config.toml without its [toolchain] default" ;
386+ expect (eq (partial.load (), 0 )) << " a reader saw config.toml without its [toolchain] default; the first saw: " << first ;
369387 std::size_t files = 0 ;
370388 for ([[maybe_unused]] const auto & e : std::filesystem::directory_iterator (home)) ++files;
371389 expect (eq (files, std::size_t {1 })) << " a writer left a file beside config.toml" ;
0 commit comments