-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add file for integration tests
- Loading branch information
Showing
8 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Cargo.lock linguist-generated=true | ||
flake.lock linguist-generated=true | ||
|
||
tests/*.txt linguist-generated=true | ||
resources/test/* linguist-generated=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ target/ | |
.vscode/ | ||
|
||
.direnv/ | ||
|
||
resources/test/tmp/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# man_completions | ||
# man-completions | ||
|
||
Parse manpages to get completions for Zsh, Bash, and Nu | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Tests | ||
|
||
In the [`in`](./resources/in) folder are manpages for whom completions will be | ||
generated, as part of the integration tests. The expected outputs will be in the | ||
[`expected`](./resources/expected) folder. The [`tmp`](./resources/tmp) folder | ||
will hold the completions generated by the tests, which will then be compared to | ||
the files in the `expected` folder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use std::{env, fs, path::PathBuf, process::Command}; | ||
|
||
#[test] | ||
fn test() { | ||
// The project's root directory | ||
let root = env::var("CARGO_MANIFEST_DIR").unwrap(); | ||
|
||
let test_resources = PathBuf::from(root).join("tests/resources"); | ||
let in_dir = test_resources.join("in"); | ||
let expected_dir = test_resources.join("expected"); | ||
let out_dir = test_resources.join("tmp"); | ||
|
||
// The man-completions binary to test | ||
let bin = env::var("CARGO_BIN_EXE_man-completions").unwrap(); | ||
let status = Command::new(bin).env("MANPATH", in_dir).status().unwrap(); | ||
assert!(status.success()); | ||
|
||
// Files that didn't get generated | ||
let mut not_generated = Vec::new(); | ||
// Files that don't match the expected contents | ||
let mut not_match = Vec::new(); | ||
for exp_file in fs::read_dir(&expected_dir).unwrap() { | ||
let exp_file = exp_file.unwrap(); | ||
let file_name = exp_file.file_name().to_string_lossy().to_string(); | ||
let got_file = out_dir.join(&file_name); | ||
if !got_file.exists() { | ||
not_generated.push(file_name); | ||
continue; | ||
} | ||
|
||
let expected = fs::read(exp_file.path()).unwrap(); | ||
let got = fs::read(got_file).unwrap(); | ||
if expected != got { | ||
not_match.push(file_name); | ||
} | ||
} | ||
|
||
if !not_generated.is_empty() { | ||
println!("The following files weren't generated:"); | ||
for file_name in ¬_generated { | ||
println!("- {file_name}"); | ||
} | ||
} | ||
|
||
if !not_match.is_empty() { | ||
println!("The following files didn't match what was expected:"); | ||
for file_name in ¬_match { | ||
let exp = expected_dir.join(&file_name); | ||
let exp = exp.to_string_lossy(); | ||
let got = out_dir.join(&file_name); | ||
let got = got.to_string_lossy(); | ||
println!("Test for {file_name} failed: contents of {got} did not match those of {exp}"); | ||
println!("To see the diff, run `diff {exp} {got}`"); | ||
println!("To overwrite the expected file, run `cp {got} {exp}`") | ||
} | ||
} | ||
|
||
if !not_generated.is_empty() || !not_match.is_empty() { | ||
assert!(false); | ||
} | ||
} |
File renamed without changes.