-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Update TRPL to add new Chapter 17: Async and Await #131859
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
7 commits
Select commit
Hold shift + click to select a range
b64da63
Update TRPL to latest, including new Chapter 17: Async and Await
chriskrycho 5e36076
Update messages which reference book chs. 17-20
chriskrycho f7409e8
Add support for `--library-path` to `rustbook test`
chriskrycho d34d426
Update bootstrap tests to support book dependencies
chriskrycho 559a2d2
rustbook: fix two small typos
chriskrycho d4275e0
Update tests for new TRPL chapter order
chriskrycho 7630b49
Vendor `trpl` crate so The Book tests work offline
chriskrycho 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
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 |
---|---|---|
|
@@ -31,6 +31,20 @@ fn main() { | |
(Defaults to the current directory when omitted)") | ||
.value_parser(clap::value_parser!(PathBuf)); | ||
|
||
// Note: we don't parse this into a `PathBuf` because it is comma separated | ||
// strings *and* we will ultimately pass it into `MDBook::test()`, which | ||
// accepts `Vec<&str>`. Although it is a bit annoying that `-l/--lang` and | ||
// `-L/--library-path` are so close, this is the same set of arguments we | ||
// would pass when invoking mdbook on the CLI, so making them match when | ||
// invoking rustbook makes for good consistency. | ||
let library_path_arg = arg!( | ||
-L --"library-path" <PATHS> | ||
"A comma-separated list of directories to add to the crate search\n\ | ||
path when building tests" | ||
) | ||
.required(false) | ||
.value_parser(parse_library_paths); | ||
|
||
let matches = Command::new("rustbook") | ||
.about("Build a book with mdBook") | ||
.author("Steve Klabnik <[email protected]>") | ||
|
@@ -48,11 +62,12 @@ fn main() { | |
.subcommand( | ||
Command::new("test") | ||
.about("Tests that a book's Rust code samples compile") | ||
.arg(dir_arg), | ||
.arg(dir_arg) | ||
.arg(library_path_arg), | ||
) | ||
.get_matches(); | ||
|
||
// Check which subcomamnd the user ran... | ||
// Check which subcommand the user ran... | ||
match matches.subcommand() { | ||
Some(("build", sub_matches)) => { | ||
if let Err(e) = build(sub_matches) { | ||
|
@@ -113,8 +128,12 @@ pub fn build(args: &ArgMatches) -> Result3<()> { | |
|
||
fn test(args: &ArgMatches) -> Result3<()> { | ||
let book_dir = get_book_dir(args); | ||
let library_paths = args | ||
.try_get_one::<Vec<String>>("library-path")? | ||
.map(|v| v.iter().map(|s| s.as_str()).collect::<Vec<&str>>()) | ||
.unwrap_or_default(); | ||
let mut book = load_book(&book_dir)?; | ||
book.test(vec![]) | ||
book.test(library_paths) | ||
} | ||
|
||
fn get_book_dir(args: &ArgMatches) -> PathBuf { | ||
|
@@ -132,12 +151,16 @@ fn load_book(book_dir: &Path) -> Result3<MDBook> { | |
Ok(book) | ||
} | ||
|
||
fn parse_library_paths(input: &str) -> Result<Vec<String>, String> { | ||
Ok(input.split(",").map(String::from).collect()) | ||
} | ||
|
||
fn handle_error(error: mdbook::errors::Error) -> ! { | ||
eprintln!("Error: {}", error); | ||
|
||
for cause in error.chain().skip(1) { | ||
eprintln!("\tCaused By: {}", cause); | ||
} | ||
|
||
::std::process::exit(101); | ||
std::process::exit(101); | ||
} |
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
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
Oops, something went wrong.
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.