From 82dbd02c032532003136a3a79bf69540f974e1b8 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Sat, 9 May 2015 23:38:48 -0400 Subject: [PATCH] Add initial test for tsort. --- Makefile | 1 + test/fixtures/tsort/call_graph.expected | 17 ++++++++++++++++ test/fixtures/tsort/call_graph.txt | 22 +++++++++++++++++++++ test/tsort.rs | 26 +++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 test/fixtures/tsort/call_graph.expected create mode 100644 test/fixtures/tsort/call_graph.txt create mode 100644 test/tsort.rs diff --git a/Makefile b/Makefile index 05808dc7b..c1e47ce61 100644 --- a/Makefile +++ b/Makefile @@ -179,6 +179,7 @@ TEST_PROGS := \ tr \ true \ truncate \ + tsort \ unexpand TEST ?= $(TEST_PROGS) diff --git a/test/fixtures/tsort/call_graph.expected b/test/fixtures/tsort/call_graph.expected new file mode 100644 index 000000000..e33aa72bd --- /dev/null +++ b/test/fixtures/tsort/call_graph.expected @@ -0,0 +1,17 @@ +main +parse_options +tail_file +tail_forever +tail +recheck +write_header +tail_lines +tail_bytes +pretty_name +start_lines +file_lines +pipe_lines +xlseek +start_bytes +pipe_bytes +dump_remainder diff --git a/test/fixtures/tsort/call_graph.txt b/test/fixtures/tsort/call_graph.txt new file mode 100644 index 000000000..c6f94e5b6 --- /dev/null +++ b/test/fixtures/tsort/call_graph.txt @@ -0,0 +1,22 @@ +main parse_options +main tail_file +main tail_forever +tail_file pretty_name +tail_file write_header +tail_file tail +tail_forever recheck +tail_forever pretty_name +tail_forever write_header +tail_forever dump_remainder +tail tail_lines +tail tail_bytes +tail_lines start_lines +tail_lines dump_remainder +tail_lines file_lines +tail_lines pipe_lines +tail_bytes xlseek +tail_bytes start_bytes +tail_bytes dump_remainder +tail_bytes pipe_bytes +file_lines dump_remainder +recheck pretty_name diff --git a/test/tsort.rs b/test/tsort.rs new file mode 100644 index 000000000..c90c3368f --- /dev/null +++ b/test/tsort.rs @@ -0,0 +1,26 @@ +use std::fs::File; +use std::io::Read; +use std::path::Path; +use std::process::Command; + +static PROGNAME: &'static str = "./tsort"; + +fn get_file_contents(name: &str) -> Vec { + let mut f = File::open(Path::new(name)).unwrap(); + let mut contents: Vec = vec!(); + let _ = f.read_to_end(&mut contents); + contents +} + +#[test] +fn test_sort_call_graph() { + let input = "call_graph.txt"; + let output = "call_graph.expected"; + + let po = Command::new(PROGNAME) + .arg(input) + .output() + .unwrap_or_else(|err| panic!("{}", err)); + + assert_eq!(String::from_utf8(po.stdout).unwrap(), String::from_utf8(get_file_contents(output)).unwrap()); +}