@@ -169,12 +169,26 @@ TEST_VM(LogFileOutput, invalid_file) {
169169 ResourceMark rm;
170170 stringStream ss;
171171
172+ // Generate sufficiently unique directory path and log spec for that path
173+ ss.print (" %s%s%s%d" , os::get_temp_directory (), os::file_separator (), " tmplogdir" , os::current_process_id ());
174+ char * path = ss.as_string ();
175+ ss.reset ();
176+
177+ ss.print (" %s%s" , " file=" , path);
178+ char * log_spec = ss.as_string ();
179+ ss.reset ();
180+
181+ ss.print (" %s is not a regular file" , path);
182+ char * expected_output_substring = ss.as_string ();
183+ ss.reset ();
184+
172185 // Attempt to log to a directory (existing log not a regular file)
173- create_directory (" tmplogdir " );
174- LogFileOutput bad_file (" file=tmplogdir " );
186+ create_directory (path );
187+ LogFileOutput bad_file (log_spec );
175188 EXPECT_FALSE (bad_file.initialize (" " , &ss))
176189 << " file was initialized when there was an existing directory with the same name" ;
177- EXPECT_TRUE (string_contains_substring (ss.as_string (), " tmplogdir is not a regular file" ))
178- << " missing expected error message, received msg: %s" << ss.as_string ();
179- delete_empty_directory (" tmplogdir" );
190+ char * logger_output = ss.as_string ();
191+ EXPECT_TRUE (string_contains_substring (logger_output, expected_output_substring))
192+ << " missing expected error message, received msg: %s" << logger_output;
193+ delete_empty_directory (path);
180194}
0 commit comments