-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix docs hashsumS and test #7936
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6a5dd14
fix docs hashsum
Its-Just-Nans 20fa881
fix the test to [
Its-Just-Nans d4971cf
fix suggested by @rwdj
Its-Just-Nans 74d04fb
remove super useful comment
Its-Just-Nans 01c1d0c
add uudoc tests
Its-Just-Nans a514be4
cargo clippy
Its-Just-Nans e5cfd44
change test message
Its-Just-Nans 2d4a8a7
make a function
Its-Just-Nans 13b80c4
gate behind feature
Its-Just-Nans 29512d3
Merge branch 'main' into fix-doc-hashs
Its-Just-Nans a2d6232
fix name variable
Its-Just-Nans 262c638
fmt
Its-Just-Nans 014f5c2
fix list
Its-Just-Nans f406d67
return bool
Its-Just-Nans bf9e988
fix: broken manpage displaying uudoc
Its-Just-Nans 0f10e21
fix: tests
Its-Just-Nans ce44b45
clippy
Its-Just-Nans 78a98c7
dumb clippy double fmt
Its-Just-Nans f8d8a73
Update build.rs
Its-Just-Nans b246f10
Update test_uudoc.rs
Its-Just-Nans cf0d4d6
Merge branch 'main' into fix-doc-hashs
sylvestre 2c04f5c
Merge branch 'main' into fix-doc-hashs
sylvestre ada45db
Merge branch 'main' into fix-doc-hashs
Its-Just-Nans ad0aec2
fix rm hashsum
Its-Just-Nans 2c3e55a
fix: space
Its-Just-Nans File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,122 @@ | ||
| //! Tests on the `uudoc` binary. | ||
| //! | ||
| //! To run the uudoc | ||
| //! ``` | ||
| //! cargo run --bin uudoc --features uudoc | ||
| //! ``` | ||
| //! | ||
| //! To run the tests | ||
| //! ``` | ||
| //! cargo test --features uudoc | ||
| //! ``` | ||
| #![cfg(feature = "uudoc")] | ||
|
|
||
| use std::env; | ||
| pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_uudoc"); | ||
|
|
||
| // Set the environment variable for any tests | ||
|
|
||
| // Use the ctor attribute to run this function before any tests | ||
| #[ctor::ctor] | ||
| fn init() { | ||
| // No need for unsafe here | ||
| unsafe { | ||
| std::env::set_var("UUTESTS_BINARY_PATH", TESTS_BINARY); | ||
| } | ||
| // Print for debugging | ||
| eprintln!("Setting UUTESTS_BINARY_PATH={TESTS_BINARY}"); | ||
| } | ||
|
|
||
| /// Run the `uudoc` command and return the output as a vector of strings. | ||
| /// # Errors | ||
| /// If the command fails to execute or if the output cannot be converted to UTF-8, an `io::Error` is returned. | ||
| fn run_write_doc() -> Vec<String> { | ||
| use std::process::Command; | ||
| use uutests::util::TestScenario; | ||
|
|
||
| let scenario = TestScenario::new(""); | ||
| let output = Command::new(&scenario.bin_path).output().unwrap(); | ||
| assert!( | ||
| output.status.success(), | ||
| "uudoc command failed: {}", | ||
| String::from_utf8_lossy(&output.stderr) | ||
| ); | ||
|
|
||
| String::from_utf8(output.stdout) | ||
| .unwrap() | ||
| .lines() | ||
| .map(String::from) | ||
| .filter(|line| line.starts_with("Wrote")) | ||
| .collect::<Vec<String>>() | ||
| } | ||
|
|
||
| fn get_doc_file_from_output(output: &str) -> (String, String) { | ||
| let correct_path_test = output | ||
| .strip_prefix("Wrote to '") | ||
| .unwrap() | ||
| .strip_suffix("'") | ||
| .unwrap() | ||
| .to_string(); | ||
| let content = std::fs::read_to_string(&correct_path_test); | ||
| let content = match content { | ||
| Ok(content) => content, | ||
| Err(e) => { | ||
| panic!( | ||
| "Failed to read file {}: {} from {:?}", | ||
| correct_path_test, | ||
| e, | ||
| env::current_dir() | ||
| ); | ||
| } | ||
| }; | ||
| (correct_path_test, content) | ||
| } | ||
|
|
||
| #[test] | ||
| fn uudoc_check_test() { | ||
| let pages = run_write_doc(); | ||
| // assert wrote to the correct file | ||
| let path_test = pages.iter().find(|line| line.contains("test.md")).unwrap(); | ||
| let (correct_path, content) = get_doc_file_from_output(path_test); | ||
|
|
||
| // open the file | ||
| assert!( | ||
| content.contains( | ||
| "``` | ||
| test EXPRESSION | ||
| test | ||
| [ EXPRESSION ] | ||
| [ ] | ||
| [ OPTION | ||
| ``` | ||
| ", | ||
| ), | ||
| "{correct_path} does not contains the required text" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn uudoc_check_sums() { | ||
| let pages = run_write_doc(); | ||
| let sums = [ | ||
| "md5sum", | ||
| "sha1sum", | ||
| "sha224sum", | ||
| "sha256sum", | ||
| "sha384sum", | ||
| "sha512sum", | ||
| "b2sum", | ||
| ]; | ||
| for one_sum in sums { | ||
| let output_path = pages | ||
| .iter() | ||
| .find(|one_line| one_line.contains(one_sum)) | ||
| .unwrap(); | ||
| let (correct_path, content) = get_doc_file_from_output(output_path); | ||
| let formatted = format!("```\n{one_sum} [OPTIONS] [FILE]...\n```"); | ||
| assert!( | ||
| content.contains(&formatted), | ||
| "Content of {correct_path} does not contain the expected format: {formatted}", | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.