Make 'cargo test' work without '--all-features'.

This commit is contained in:
Sergio Benitez 2017-01-05 14:51:00 -06:00
parent 2da08a975c
commit 069f09cb7e
4 changed files with 125 additions and 110 deletions

View File

@ -4,7 +4,6 @@
extern crate rocket;
use rocket::request::Form;
use rocket::http::Status;
#[derive(FromForm)]
struct FormData {
@ -17,9 +16,12 @@ fn bug(form_data: Form<FormData>) -> &'static str {
"OK"
}
#[cfg(feature = "testing")]
mod tests {
use super::*;
use rocket::testing::MockRequest;
use rocket::http::Method::*;
use rocket::http::ContentType;
use rocket::http::{Status, ContentType};
#[test]
fn method_eval() {
@ -45,3 +47,4 @@ fn get_passes_through() {
let response = req.dispatch_with(&rocket);
assert_eq!(response.status(), Status::NotFound);
}
}

View File

@ -15,6 +15,9 @@ fn bug(form_data: Form<FormData>) -> String {
form_data.into_inner().form_data
}
#[cfg(feature = "testing")]
mod tests {
use super::*;
use rocket::testing::MockRequest;
use rocket::http::Method::*;
use rocket::http::ContentType;
@ -43,3 +46,4 @@ fn test_proper_decoding() {
check_decoding("1%2B1", "1+1");
check_decoding("%3Fa%3D1%26b%3D2", "?a=1&b=2");
}
}

View File

@ -3,9 +3,7 @@
extern crate rocket;
use rocket::Route;
use rocket::response::{status, content};
use rocket::http::ContentType;
#[get("/empty")]
fn empty() -> status::NoContent {
@ -22,15 +20,20 @@ fn other() -> content::JSON<()> {
content::JSON(())
}
#[cfg(feature = "testing")]
mod tests {
use super::*;
use rocket::Route;
use rocket::testing::MockRequest;
use rocket::http::Method::*;
use rocket::http::{Status, ContentType};
use rocket::response::Body;
fn routes() -> Vec<Route> {
routes![index, empty, other]
}
use rocket::testing::MockRequest;
use rocket::http::Method::*;
use rocket::http::Status;
use rocket::response::Body;
#[test]
fn auto_head() {
let rocket = rocket::ignite().mount("/", routes());
@ -70,3 +73,4 @@ fn user_head() {
let content_type: Vec<_> = response.header_values("Content-Type").collect();
assert_eq!(content_type, vec![ContentType::JSON.to_string()]);
}
}

View File

@ -30,6 +30,9 @@ fn dual(user: String, path: Segments) -> String {
user + "/is/" + &path.collect::<Vec<_>>().join("/")
}
#[cfg(feature = "testing")]
mod tests {
use super::*;
use rocket::testing::MockRequest;
use rocket::http::Method::*;
@ -53,3 +56,4 @@ fn segments_works() {
assert_eq!(body_str, Some(path.into()));
}
}
}