From 15b096d6951860fae40a04a25225e382f69007fd Mon Sep 17 00:00:00 2001 From: Jacob Mitchell Date: Thu, 14 Mar 2019 21:48:29 -0700 Subject: [PATCH] Extract graph log validation into a specialized test --- cli/src/tests/parser_test.rs | 23 +++++++++++++++++++++++ cli/src/util.rs | 19 ------------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/cli/src/tests/parser_test.rs b/cli/src/tests/parser_test.rs index 01724daf..6afac6ab 100644 --- a/cli/src/tests/parser_test.rs +++ b/cli/src/tests/parser_test.rs @@ -62,6 +62,29 @@ fn test_parsing_with_logging() { } } +#[test] +#[cfg(unix)] +fn test_parsing_with_debug_graph_enabled() { + use std::io::{BufRead, BufReader, Seek}; + + let has_zero_indexed_row = |s: &str| s.contains("position: 0,"); + + let mut parser = Parser::new(); + parser.set_language(get_language("javascript")).unwrap(); + + let mut debug_graph_file = tempfile::tempfile().unwrap(); + parser.print_dot_graphs(&debug_graph_file); + parser.parse("const zero = 0", None).unwrap(); + + debug_graph_file.seek(std::io::SeekFrom::Start(0)).unwrap(); + let log_reader = BufReader::new(debug_graph_file) + .lines() + .map(|l| l.expect("Failed to read line from graph log")); + for line in log_reader { + assert!(!has_zero_indexed_row(&line), "Graph log output includes zero-indexed row: {}", line); + } +} + #[test] fn test_parsing_with_custom_utf8_input() { let mut parser = Parser::new(); diff --git a/cli/src/util.rs b/cli/src/util.rs index c4d4f9c9..e880bea1 100644 --- a/cli/src/util.rs +++ b/cli/src/util.rs @@ -55,9 +55,6 @@ impl Drop for LogSession { { Command::new("open").arg(&self.0).output().unwrap(); } - - #[cfg(any(debug_assertions, test))] - validate_graph_log(&self); } else { eprintln!( "Dot failed: {} {}", @@ -67,19 +64,3 @@ impl Drop for LogSession { } } } - -#[cfg(all(unix, any(debug_assertions, test)))] -fn validate_graph_log(session: &LogSession) { - use std::io::{BufRead, BufReader}; - - let has_zero_indexed_row = |s: &str| s.contains("position: 0,"); - - let graph_log = std::fs::File::open(&session.0) - .expect("Failed to open graph log"); - let log_reader = BufReader::new(graph_log) - .lines() - .map(|l| l.expect("Failed to read line from graph log")); - for line in log_reader { - assert!(!has_zero_indexed_row(&line), "Graph log output includes zero-indexed row: {}", line); - } -}