| 36 | } |
| 37 | |
| 38 | Status TestReportFile::Initialize() { |
| 39 | if (fname_.empty()) { |
| 40 | return Status::OK(); |
| 41 | } |
| 42 | string mangled_fname = strings::StrCat( |
| 43 | fname_, absl::StrJoin(str_util::Split(test_name_, '/'), "__")); |
| 44 | Env* env = Env::Default(); |
| 45 | if (env->FileExists(mangled_fname).ok()) { |
| 46 | return errors::InvalidArgument( |
| 47 | "Cannot create TestReportFile, file exists: ", mangled_fname); |
| 48 | } |
| 49 | TF_RETURN_IF_ERROR(env->NewWritableFile(mangled_fname, &log_file_)); |
| 50 | TF_RETURN_IF_ERROR(log_file_->Flush()); |
| 51 | |
| 52 | closed_ = false; |
| 53 | return Status::OK(); |
| 54 | } |
| 55 | |
| 56 | TestReporter::TestReporter(const string& fname, const string& test_name) |
| 57 | : report_file_(fname, test_name) { |