Skip to content

Commit

Permalink
Make sure that files generated by tests are covered by .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Mar 26, 2019
1 parent 613ac1d commit 47cf346
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -8,3 +8,6 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# Directories created by integration tests
test-tmp/
8 changes: 7 additions & 1 deletion measureme/src/file_serialization_sink.rs
Expand Up @@ -10,15 +10,21 @@ 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)),
}
}

#[inline]
fn write_atomic<W>(&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());
Expand Down
25 changes: 18 additions & 7 deletions measureme/tests/serialization.rs
Expand Up @@ -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<S: SerializationSink>(filestem: &str) -> Vec<Event> {
fn generate_profiling_data<S: SerializationSink>(filestem: &Path) -> Vec<Event> {
let profiler = Arc::new(Profiler::<S>::new(Path::new(filestem)));

let event_id_reserved = StringId::reserved(42);
Expand Down Expand Up @@ -74,8 +84,8 @@ fn generate_profiling_data<S: SerializationSink>(filestem: &str) -> Vec<Event> {

// 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;

Expand All @@ -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::<FileSerializationSink>("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::<FileSerializationSink>(&filestem);
process_profiling_data(&filestem, &expected_events);
}

// #[test]
Expand Down

0 comments on commit 47cf346

Please sign in to comment.