Skip to content

Commit

Permalink
Make list option comply with official spec (#112)
Browse files Browse the repository at this point in the history
Separate page list with newlines, not with commas.

From the official spec:

> Additional decoration MAY be printed if the standard output is a TTY.
> If not, then the output MUST not contain any additional decorations.
> For example a page list MUST be formatted with 1 page name per line
> (to enable easy manipulation using standard CLI tools such as grep etc.).
  • Loading branch information
michaeldel authored Apr 16, 2020
1 parent 39b1d19 commit 5dd9457
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ fn main() {
});

// Print pages
println!("{}", pages.join(", "));
println!("{}", pages.join("\n"));
process::exit(0);
}

Expand Down
43 changes: 42 additions & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate predicates;
extern crate tempdir;
extern crate utime;

use std::fs::File;
use std::fs::{create_dir_all, File};
use std::io::Write;
use std::process::Command;

Expand Down Expand Up @@ -34,6 +34,15 @@ impl TestEnv {
}
}

/// Add entry for that environment.
fn add_entry(&self, name: &str, contents: &str) {
let dir = self.cache_dir.path().join("tldr-master").join("pages").join("common");
create_dir_all(&dir).unwrap();

let mut file = File::create(&dir.join(format!("{}.md", name))).unwrap();
file.write_all(&contents.as_bytes()).unwrap();
}

/// Disable default features.
fn no_default_features(mut self) -> Self {
self.default_features = false;
Expand Down Expand Up @@ -311,3 +320,35 @@ fn test_pager_flag_enable() {
.assert()
.success();
}

#[test]
fn test_list_flag_rendering() {
let testenv = TestEnv::new();

testenv
.command()
.args(&["--list"])
.assert()
.failure()
.stderr(contains("Cache not found. Please run `tldr --update`."));

testenv.add_entry("foo", "");

testenv
.command()
.args(&["--list"])
.assert()
.success()
.stdout("foo\n");

testenv.add_entry("bar", "");
testenv.add_entry("baz", "");
testenv.add_entry("qux", "");

testenv
.command()
.args(&["--list"])
.assert()
.success()
.stdout("bar\nbaz\nfoo\nqux\n");
}

0 comments on commit 5dd9457

Please sign in to comment.