mirror of
https://github.com/rust-lang-nursery/rust-cookbook
synced 2024-11-24 04:23:06 +00:00
test fixes (#600)
* test fixes * filter mac osx until stable pulls right crate
This commit is contained in:
parent
3c32c84475
commit
203b108521
15 changed files with 42 additions and 41 deletions
|
@ -24,6 +24,8 @@ matrix:
|
||||||
- rust: stable
|
- rust: stable
|
||||||
os: linux
|
os: linux
|
||||||
env: CONTENT_TESTS=1 CONTENT_TESTS_LINKS=1
|
env: CONTENT_TESTS=1 CONTENT_TESTS_LINKS=1
|
||||||
|
- rust: stable
|
||||||
|
os: osx
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
|
|
|
@ -23,7 +23,7 @@ data-encoding = "2.1.0"
|
||||||
env_logger = "0.5"
|
env_logger = "0.5"
|
||||||
error-chain = "0.12"
|
error-chain = "0.12"
|
||||||
flate2 = "1.0"
|
flate2 = "1.0"
|
||||||
glob = "0.2"
|
glob = "0.3"
|
||||||
image = "0.20"
|
image = "0.20"
|
||||||
lazy_static = "1.0"
|
lazy_static = "1.0"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
@ -63,9 +63,9 @@ walkdir = "2.0"
|
||||||
syslog = "5.0"
|
syslog = "5.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
skeptic = "0.13"
|
skeptic = { git = 'https://github.com/andygauge/rust-skeptic'}
|
||||||
walkdir = "2.0"
|
walkdir = "2.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
skeptic = "0.13"
|
skeptic = { git = 'https://github.com/andygauge/rust-skeptic'}
|
||||||
walkdir = "2.0"
|
walkdir = "2.0"
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
Randomly generates a tuple `(i32, bool, f64)` and variable of user defined type `Point`.
|
Randomly generates a tuple `(i32, bool, f64)` and variable of user defined type `Point`.
|
||||||
Implements the [`Distribution`] trait on type Point for [`Standard`] in order to allow random generation.
|
Implements the [`Distribution`] trait on type Point for [`Standard`] in order to allow random generation.
|
||||||
|
|
||||||
```rust,edition2018,ignore
|
```rust,edition2018
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand::distributions::{Distribution, Standard};
|
use rand::distributions::{Distribution, Standard};
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,10 @@ An example using the [`Normal`] distribution is shown below.
|
||||||
|
|
||||||
```rust,edition2018,ignore
|
```rust,edition2018,ignore
|
||||||
use rand_distr::{Distribution, Normal, NormalError};
|
use rand_distr::{Distribution, Normal, NormalError};
|
||||||
|
use rand::thread_rng;
|
||||||
|
|
||||||
fn main() -> Result<(), NormalError> {
|
fn main() -> Result<(), NormalError> {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = thread_rng();
|
||||||
let normal = Normal::new(2.0, 3.0)?;
|
let normal = Normal::new(2.0, 3.0)?;
|
||||||
let v = normal.sample(&mut rng);
|
let v = normal.sample(&mut rng);
|
||||||
println!("{} is from a N(2, 9) distribution", v);
|
println!("{} is from a N(2, 9) distribution", v);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
Randomly generates a string of given length ASCII characters in the range `A-Z,
|
Randomly generates a string of given length ASCII characters in the range `A-Z,
|
||||||
a-z, 0-9`, with [`Alphanumeric`] sample.
|
a-z, 0-9`, with [`Alphanumeric`] sample.
|
||||||
|
|
||||||
```rust,edition2018,ignore
|
```rust,edition2018
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
Generates a random value within half-open `[0, 10)` range (not including `10`) with [`Rng::gen_range`].
|
Generates a random value within half-open `[0, 10)` range (not including `10`) with [`Rng::gen_range`].
|
||||||
|
|
||||||
```rust,edition2018,ignore
|
```rust,edition2018
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -18,7 +18,7 @@ fn main() {
|
||||||
This has the same effect, but may be faster when repeatedly generating numbers
|
This has the same effect, but may be faster when repeatedly generating numbers
|
||||||
in the same range.
|
in the same range.
|
||||||
|
|
||||||
```rust,edition2018,ignore
|
```rust,edition2018
|
||||||
|
|
||||||
use rand::distributions::{Distribution, Uniform};
|
use rand::distributions::{Distribution, Uniform};
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ values in parallel. Although [multiple options]
|
||||||
exist to sort an enumerable data type, [`par_sort_unstable`]
|
exist to sort an enumerable data type, [`par_sort_unstable`]
|
||||||
is usually faster than [stable sorting] algorithms.
|
is usually faster than [stable sorting] algorithms.
|
||||||
|
|
||||||
```rust,edition2018,ignore
|
```rust,edition2018
|
||||||
|
|
||||||
use rand::{Rng, thread_rng};
|
use rand::{Rng, thread_rng};
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
|
|
|
@ -29,7 +29,7 @@ use rayon::prelude::*;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let options: MatchOptions = Default::default();
|
let options: MatchOptions = Default::default();
|
||||||
let files: Vec<_> = glob_with("*.jpg", &options)?
|
let files: Vec<_> = glob_with("*.jpg", options)?
|
||||||
.filter_map(|x| x.ok())
|
.filter_map(|x| x.ok())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ function [`pbkdf2::derive`]. Verifies the hash is correct with
|
||||||
[`SecureRandom::fill`], which fills the salt byte array with
|
[`SecureRandom::fill`], which fills the salt byte array with
|
||||||
securely generated random numbers.
|
securely generated random numbers.
|
||||||
|
|
||||||
```rust,edition2018,ignore
|
```rust,edition2018
|
||||||
|
|
||||||
use data_encoding::HEXUPPER;
|
use data_encoding::HEXUPPER;
|
||||||
use ring::error::Unspecified;
|
use ring::error::Unspecified;
|
||||||
|
|
|
@ -56,24 +56,24 @@ void greet(const char* name) {
|
||||||
### `src/main.rs`
|
### `src/main.rs`
|
||||||
|
|
||||||
```rust,edition2018,ignore
|
```rust,edition2018,ignore
|
||||||
|
use error_chain::error_chain;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
#
|
|
||||||
# error_chain! {
|
error_chain! {
|
||||||
# foreign_links {
|
foreign_links {
|
||||||
# NulError(::std::ffi::NulError);
|
NulError(::std::ffi::NulError);
|
||||||
# Io(::std::io::Error);
|
Io(::std::io::Error);
|
||||||
# }
|
}
|
||||||
# }
|
}
|
||||||
#
|
fn prompt(s: &str) -> Result<String> {
|
||||||
# fn prompt(s: &str) -> Result<String> {
|
use std::io::Write;
|
||||||
# use std::io::Write;
|
print!("{}", s);
|
||||||
# print!("{}", s);
|
std::io::stdout().flush()?;
|
||||||
# std::io::stdout().flush()?;
|
let mut input = String::new();
|
||||||
# let mut input = String::new();
|
std::io::stdin().read_line(&mut input)?;
|
||||||
# std::io::stdin().read_line(&mut input)?;
|
Ok(input.trim().to_string())
|
||||||
# Ok(input.trim().to_string())
|
}
|
||||||
# }
|
|
||||||
|
|
||||||
extern {
|
extern {
|
||||||
fn hello();
|
fn hello();
|
||||||
|
|
|
@ -6,7 +6,7 @@ Encode an input string with [percent-encoding] using the [`utf8_percent_encode`]
|
||||||
function from the `percent-encoding` crate. Then decode using the [`percent_decode`]
|
function from the `percent-encoding` crate. Then decode using the [`percent_decode`]
|
||||||
function.
|
function.
|
||||||
|
|
||||||
```rust,edition2018,ignore
|
```rust,edition2018
|
||||||
use percent_encoding::{utf8_percent_encode, percent_decode, AsciiSet, CONTROLS};
|
use percent_encoding::{utf8_percent_encode, percent_decode, AsciiSet, CONTROLS};
|
||||||
use std::str::Utf8Error;
|
use std::str::Utf8Error;
|
||||||
|
|
||||||
|
|
|
@ -7,16 +7,15 @@ Find all image files in the `/media/` directory matching the `img_[0-9]*.png` pa
|
||||||
A custom [`MatchOptions`] struct is passed to the [`glob_with`] function making the glob pattern case insensitive while keeping the other options [`Default`].
|
A custom [`MatchOptions`] struct is passed to the [`glob_with`] function making the glob pattern case insensitive while keeping the other options [`Default`].
|
||||||
|
|
||||||
```rust,edition2018,no_run
|
```rust,edition2018,no_run
|
||||||
# use error_chain::error_chain;
|
use error_chain::error_chain;
|
||||||
|
|
||||||
use glob::{glob_with, MatchOptions};
|
use glob::{glob_with, MatchOptions};
|
||||||
#
|
|
||||||
# error_chain! {
|
error_chain! {
|
||||||
# foreign_links {
|
foreign_links {
|
||||||
# Glob(glob::GlobError);
|
Glob(glob::GlobError);
|
||||||
# Pattern(glob::PatternError);
|
Pattern(glob::PatternError);
|
||||||
# }
|
}
|
||||||
# }
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let options = MatchOptions {
|
let options = MatchOptions {
|
||||||
|
@ -24,7 +23,7 @@ fn main() -> Result<()> {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
for entry in glob_with("/media/img_[0-9]*.png", &options)? {
|
for entry in glob_with("/media/img_[0-9]*.png", options)? {
|
||||||
println!("{}", entry?.display());
|
println!("{}", entry?.display());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ handle remote server errors. This example uses the [`hyper::header!`] macro
|
||||||
to parse the response header and checks for [`reqwest::StatusCode::Forbidden`].
|
to parse the response header and checks for [`reqwest::StatusCode::Forbidden`].
|
||||||
If the response exceeds the rate limit, the example waits and retries.
|
If the response exceeds the rate limit, the example waits and retries.
|
||||||
|
|
||||||
```rust,edition2018,no_run,ignore
|
```rust,edition2018,no_run
|
||||||
# use error_chain::error_chain;
|
# use error_chain::error_chain;
|
||||||
|
|
||||||
use std::time::{Duration, UNIX_EPOCH};
|
use std::time::{Duration, UNIX_EPOCH};
|
||||||
|
|
|
@ -14,7 +14,7 @@ with [`RequestBuilder::header`] then makes the request with
|
||||||
The request targets <http://httpbin.org/headers> service which responds with
|
The request targets <http://httpbin.org/headers> service which responds with
|
||||||
a JSON dict containing all request headers for easy verification.
|
a JSON dict containing all request headers for easy verification.
|
||||||
|
|
||||||
```rust,edition2018,no_run,ignore
|
```rust,edition2018,no_run
|
||||||
# use error_chain::error_chain;
|
# use error_chain::error_chain;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ use reqwest::StatusCode;
|
||||||
use select::document::Document;
|
use select::document::Document;
|
||||||
use select::predicate::Name;
|
use select::predicate::Name;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use tokio::stream::{self, StreamExt};
|
|
||||||
use url::{Position, Url};
|
use url::{Position, Url};
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
|
|
Loading…
Reference in a new issue