Skip to content

Commit

Permalink
Merge pull request #100 from lipanski/fix_appveyor_builds
Browse files Browse the repository at this point in the history
Fix Appveyor tests by disabling the color feature for Appveyor builds
  • Loading branch information
lipanski authored Jan 19, 2020
2 parents 8827fbb + ec2edb2 commit 6ece388
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ install:
- cargo -vV
build: false
test_script:
- cargo test
# Appveyor seems to fail the color tests, so we disable this feature
- cargo test --no-default-features
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<p align="center"><img src="https://raw.githubusercontent.com/lipanski/mockito/master/docs/logo-black.png"></p>
<p align="center">
<a href="https://docs.rs/mockito"><img src="https://docs.rs/mockito/badge.svg"></a>
<a href="https://crates.io/crates/mockito"><img src="https://img.shields.io/crates/d/mockito"></a>
<img src="https://img.shields.io/badge/rust%20version-%3E%3D1.35.0-orange">
<a href="https://crates.io/crates/mockito"><img src="https://img.shields.io/crates/v/mockito.svg"></a>
<img src="https://img.shields.io/badge/rust%20version-%3E%3D1.35.0-orange">
<a href="https://crates.io/crates/mockito"><img src="https://img.shields.io/crates/d/mockito"></a>
<a href="https://travis-ci.org/lipanski/mockito"><img src="https://travis-ci.org/lipanski/mockito.svg?branch=master"></a>
<a href="https://ci.appveyor.com/project/lipanski/mockito"><img src="https://ci.appveyor.com/api/projects/status/github/lipanski/mockito?branch=master&svg=true"></a>
</p>
Expand Down Expand Up @@ -34,6 +34,18 @@ Run tests:
cargo test
```

...or run tests using a different toolchain:

```sh
rustup run --install 1.35.0 cargo test
```

...or run tests while disabling the default features (e.g. the colors):

```sh
cargo test --no-default-features
```

### Code style

Mockito uses [rustfmt](https://github.com/rust-lang/rustfmt) as a general code style.
Expand Down Expand Up @@ -71,6 +83,12 @@ touch src/lib.rs
cargo clippy --lib --tests --all-features -- -D clippy::pedantic -D clippy::nursery
```

...or run the linter using a different toolchain:

```sh
rustup run --install 1.35.0 cargo clippy --lib --tests --all-features -- -D clippy::pedantic -D clippy::nursery
```

### Release

Release:
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,11 @@ impl PathAndQueryMatcher {
match self {
PathAndQueryMatcher::Unified(matcher) => matcher.matches_value(other),
PathAndQueryMatcher::Split(ref path_matcher, ref query_matcher) => {
let mut parts = other.splitn(2, "?");
let mut parts = other.splitn(2, '?');
let path = parts.next().unwrap();
let query = parts.next().unwrap_or("");

return path_matcher.matches_value(path) && query_matcher.matches_value(query);
path_matcher.matches_value(path) && query_matcher.matches_value(query)
}
}
}
Expand Down Expand Up @@ -932,6 +932,7 @@ impl Mock {
/// This is only enforced when calling the `assert` method.
/// Defaults to 1 request.
///
#[allow(clippy::missing_const_for_fn)]
pub fn expect(mut self, hits: usize) -> Self {
self.expected_hits = hits;

Expand Down Expand Up @@ -1004,6 +1005,7 @@ impl Mock {
self
}

#[allow(clippy::missing_const_for_fn)]
fn is_local(&self) -> bool {
!self.is_remote
}
Expand Down
1 change: 1 addition & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct State {
}

impl State {
#[allow(clippy::missing_const_for_fn)]
fn new() -> Self {
Self {
listening_addr: None,
Expand Down
30 changes: 30 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,21 @@ fn test_assert_panics_with_too_many_requests() {
#[should_panic(
expected = "\n> Expected 1 request(s) to:\n\r\nGET /hello\r\n\n...but received 0\n\n> The last unmatched request was:\n\r\nGET /bye\r\n\n> Difference:\n\n\u{1b}[31mGET /hello\u{1b}[0m\n\u{1b}[32mGET\u{1b}[0m \u{1b}[42;37m/bye\u{1b}[0m\n\n\n"
)]
#[cfg(feature = "color")]
fn test_assert_with_last_unmatched_request() {
let mock = mock("GET", "/hello").create();

request("GET /bye", "");

mock.assert();
}

// Same test but without colors (for Appveyor)
#[test]
#[should_panic(
expected = "\n> Expected 1 request(s) to:\n\r\nGET /hello\r\n\n...but received 0\n\n> The last unmatched request was:\n\r\nGET /bye\r\n\n> Difference:\n\nGET /hello\nGET /bye\n\n\n"
)]
#[cfg(not(feature = "color"))]
fn test_assert_with_last_unmatched_request() {
let mock = mock("GET", "/hello").create();

Expand All @@ -928,6 +943,21 @@ fn test_assert_with_last_unmatched_request() {
#[should_panic(
expected = "\n> Expected 1 request(s) to:\n\r\nGET /hello\r\n\n...but received 0\n\n> The last unmatched request was:\n\r\nGET /bye\r\nauthorization: 1234\r\naccept: text\r\n\n> Difference:\n\n\u{1b}[31mGET /hello\u{1b}[0m\n\u{1b}[32mGET\u{1b}[0m \u{1b}[42;37m/bye\nauthorization: 1234\naccept: text\u{1b}[0m\n\n\n"
)]
#[cfg(feature = "color")]
fn test_assert_with_last_unmatched_request_and_headers() {
let mock = mock("GET", "/hello").create();

request("GET /bye", "authorization: 1234\r\naccept: text\r\n");

mock.assert();
}

// Same test but without colors (for Appveyor)
#[test]
#[should_panic(
expected = "\n> Expected 1 request(s) to:\n\r\nGET /hello\r\n\n...but received 0\n\n> The last unmatched request was:\n\r\nGET /bye\r\nauthorization: 1234\r\naccept: text\r\n\n> Difference:\n\nGET /hello\nGET /bye\nauthorization: 1234\naccept: text\n\n\n"
)]
#[cfg(not(feature = "color"))]
fn test_assert_with_last_unmatched_request_and_headers() {
let mock = mock("GET", "/hello").create();

Expand Down

0 comments on commit 6ece388

Please sign in to comment.