From 47cf346458c0295db83091a6b7a4ef4e4cd664ff Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 26 Mar 2019 16:16:52 +0100 Subject: [PATCH] Make sure that files generated by tests are covered by .gitignore --- .gitignore | 3 +++ measureme/src/file_serialization_sink.rs | 8 +++++++- measureme/tests/serialization.rs | 25 +++++++++++++++++------- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 088ba6b..eae600c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk + +# Directories created by integration tests +test-tmp/ diff --git a/measureme/src/file_serialization_sink.rs b/measureme/src/file_serialization_sink.rs index 2eee9ff..28a9453 100644 --- a/measureme/src/file_serialization_sink.rs +++ b/measureme/src/file_serialization_sink.rs @@ -10,7 +10,12 @@ pub struct FileSerializationSink { impl SerializationSink for FileSerializationSink { fn from_path(path: &Path) -> Self { + // TODO: This is very crude error handling. + // https://github.com/rust-lang/measureme/issues/9 + fs::create_dir_all(path.parent().unwrap()).unwrap(); + let file = fs::File::create(path).expect("couldn't open file: {}"); + FileSerializationSink { data: Mutex::new((BufWriter::new(file), 0)), } @@ -18,7 +23,8 @@ impl SerializationSink for FileSerializationSink { #[inline] fn write_atomic(&self, num_bytes: usize, write: W) -> Addr - where W: FnOnce(&mut [u8]), + where + W: FnOnce(&mut [u8]), { let mut buffer = vec![0; num_bytes]; write(buffer.as_mut_slice()); diff --git a/measureme/tests/serialization.rs b/measureme/tests/serialization.rs index b4f4c3a..17a14ee 100644 --- a/measureme/tests/serialization.rs +++ b/measureme/tests/serialization.rs @@ -5,12 +5,22 @@ use measureme::{ use rustc_hash::FxHashMap; use std::borrow::Cow; use std::default::Default; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::sync::Arc; use std::time::SystemTime; +fn mk_filestem(file_name_stem: &str) -> PathBuf { + let mut path = PathBuf::new(); + + path.push("test-tmp"); + path.push("end_to_end_serialization"); + path.push(file_name_stem); + + path +} + // Generate some profiling data. This is the part that would run in rustc. -fn generate_profiling_data(filestem: &str) -> Vec { +fn generate_profiling_data(filestem: &Path) -> Vec { let profiler = Arc::new(Profiler::::new(Path::new(filestem))); let event_id_reserved = StringId::reserved(42); @@ -74,8 +84,8 @@ fn generate_profiling_data(filestem: &str) -> Vec { // Process some profiling data. This is the part that would run in a // post processing tool. -fn process_profiling_data(filestem: &str, expected_events: &[Event]) { - let profiling_data = ProfilingData::new(Path::new(filestem)); +fn process_profiling_data(filestem: &Path, expected_events: &[Event]) { + let profiling_data = ProfilingData::new(filestem); let mut count = 0; @@ -95,9 +105,10 @@ fn process_profiling_data(filestem: &str, expected_events: &[Event]) { #[test] fn test_file_serialization_sink() { - let expected_events = - generate_profiling_data::("file_serialization_sink_test"); - process_profiling_data("file_serialization_sink_test", &expected_events); + let filestem = mk_filestem("file_serialization_sink_test"); + + let expected_events = generate_profiling_data::(&filestem); + process_profiling_data(&filestem, &expected_events); } // #[test]