From 8a6abc78f915e367a7ba4d006aae2c795b59c488 Mon Sep 17 00:00:00 2001 From: Dalton Maahs Date: Fri, 26 Mar 2021 08:49:22 -0500 Subject: [PATCH 1/2] Change update message to an eprintln instead of a println --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 4b4309057..7c69f651f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -175,7 +175,7 @@ fn update_cache(cache: &Cache, quietly: bool) { process::exit(1); }); if !quietly { - println!("Successfully updated cache."); + eprintln!("Successfully updated cache."); } } From 887c481fe5c9f5a9c471184c48a31a0ad7f69a3f Mon Sep 17 00:00:00 2001 From: Dalton Maahs Date: Sun, 9 May 2021 22:48:37 -0500 Subject: [PATCH 2/2] Change logging messeges to go to stderr - updated tests to expect these messages in stderr instead of stdout - changed test_markdown_rendering to no longer rely on the tldr pages repo. Instead manually adding a known page to use in this test, because it failed due to the tldr pages repo updating this command (so it no longer matched our expected output, which shouldn't cause our tests to fail). --- src/main.rs | 10 +++++----- tests/lib.rs | 21 ++++++++------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7c69f651f..62738ca0d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -160,7 +160,7 @@ fn clear_cache(quietly: bool) { process::exit(1); }); if !quietly { - println!("Successfully deleted cache."); + eprintln!("Successfully deleted cache."); } } @@ -239,7 +239,7 @@ fn show_paths() { fn create_config_and_exit() { match make_default_config() { Ok(config_file_path) => { - println!( + eprintln!( "Successfully created seed config file here: {}", config_file_path.to_str().unwrap() ); @@ -484,9 +484,9 @@ fn main() { } } else { if !args.flag_quiet { - println!("Page {} not found in cache", &command); - println!("Try updating with `tldr --update`, or submit a pull request to:"); - println!("https://github.com/tldr-pages/tldr"); + eprintln!("Page {} not found in cache", &command); + eprintln!("Try updating with `tldr --update`, or submit a pull request to:"); + eprintln!("https://github.com/tldr-pages/tldr"); } process::exit(1); } diff --git a/tests/lib.rs b/tests/lib.rs index 7f7ad4cae..0f9b791b4 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -115,7 +115,7 @@ fn test_update_cache() { .args(&["--update"]) .assert() .success() - .stdout(contains("Successfully updated cache.")); + .stderr(contains("Successfully updated cache.")); testenv.command().args(&["sl"]).assert().success(); } @@ -198,7 +198,7 @@ fn test_setup_seed_config() { .args(&["--seed-config"]) .assert() .success() - .stdout(contains("Successfully created seed config file")); + .stderr(contains("Successfully created seed config file here")); } #[test] @@ -242,12 +242,7 @@ fn test_show_paths() { fn test_markdown_rendering() { let testenv = TestEnv::new(); - testenv - .command() - .args(&["--update"]) - .assert() - .success() - .stdout(contains("Successfully updated cache.")); + testenv.add_entry("tar", include_str!("tar-markdown.expected")); let expected = include_str!("tar-markdown.expected"); testenv @@ -368,7 +363,7 @@ fn test_spaces_find_command() { .args(&["--update"]) .assert() .success() - .stdout(contains("Successfully updated cache.")); + .stderr(contains("Successfully updated cache.")); testenv .command() @@ -386,7 +381,7 @@ fn test_pager_flag_enable() { .args(&["--update"]) .assert() .success() - .stdout(contains("Successfully updated cache.")); + .stderr(contains("Successfully updated cache.")); testenv .command() @@ -455,9 +450,9 @@ fn test_autoupdate_cache() { let assert = testenv.command().args(&["--list"]).assert().success(); let pred = contains("Successfully updated cache"); if expected { - assert.stdout(pred) + assert.stderr(pred) } else { - assert.stdout(pred.not()) + assert.stderr(pred.not()) }; }; @@ -492,7 +487,7 @@ fn test_pager_warning() { .args(&["--update"]) .assert() .success() - .stdout(contains("Successfully updated cache.")); + .stderr(contains("Successfully updated cache.")); // Regular call should not show a "pager flag not available on windows" warning testenv