Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make list option display comply with official spec #112

Merged
merged 1 commit into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}