Skip to content

Commit

Permalink
Move compile-fail tests to doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Feb 21, 2018
1 parent b85397e commit 11d7890
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 123 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ version = "0.2.0"
readme = "README.md"

[dependencies]
num-traits = "0.2"
proc-macro2 = "0.2.1"
quote = "0.4.2"
syn = "0.12.7"

[dev-dependencies]
compiletest_rs = "0.3.5"
num-traits = "0.2"
num = "0.1"

[features]
Expand Down
9 changes: 1 addition & 8 deletions ci/test_full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ set -ex

echo Testing num-derive on rustc ${TRAVIS_RUST_VERSION}

# num-derive should build everywhere.
# num-derive should build and test everywhere.
cargo build --verbose --features="$FEATURES"

# We have no features to test...


if [ "$TRAVIS_RUST_VERSION" != nightly ]; then exit; fi

# num-derive testing requires compiletest_rs, which requires nightly
cargo test --verbose --features="$FEATURES"
90 changes: 90 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,51 @@ use syn::{Data, Fields, Ident};
/// Derives [`num_traits::FromPrimitive`][from] for simple enums.
///
/// [from]: https://docs.rs/num-traits/0.2/num_traits/cast/trait.FromPrimitive.html
///
/// # Examples
///
/// Simple enums can be derived:
///
/// ```rust
/// # #[macro_use]
/// # extern crate num_derive;
///
/// #[derive(FromPrimitive)]
/// enum Color {
/// Red,
/// Blue,
/// Green = 42,
/// }
/// # fn main() {}
/// ```
///
/// Enums that contain data are not allowed:
///
/// ```compile_fail
/// # #[macro_use]
/// # extern crate num_derive;
///
/// #[derive(FromPrimitive)]
/// enum Color {
/// Rgb(u8, u8, u8),
/// Hsv(u8, u8, u8),
/// }
/// # fn main() {}
/// ```
///
/// Structs are not allowed:
///
/// ```compile_fail
/// # #[macro_use]
/// # extern crate num_derive;
/// #[derive(FromPrimitive)]
/// struct Color {
/// r: u8,
/// g: u8,
/// b: u8,
/// }
/// # fn main() {}
/// ```
#[proc_macro_derive(FromPrimitive)]
pub fn from_primitive(input: TokenStream) -> TokenStream {
let ast: syn::DeriveInput = syn::parse(input).unwrap();
Expand Down Expand Up @@ -112,6 +157,51 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
/// Derives [`num_traits::ToPrimitive`][to] for simple enums.
///
/// [to]: https://docs.rs/num-traits/0.2/num_traits/cast/trait.ToPrimitive.html
///
/// # Examples
///
/// Simple enums can be derived:
///
/// ```rust
/// # #[macro_use]
/// # extern crate num_derive;
///
/// #[derive(ToPrimitive)]
/// enum Color {
/// Red,
/// Blue,
/// Green = 42,
/// }
/// # fn main() {}
/// ```
///
/// Enums that contain data are not allowed:
///
/// ```compile_fail
/// # #[macro_use]
/// # extern crate num_derive;
///
/// #[derive(ToPrimitive)]
/// enum Color {
/// Rgb(u8, u8, u8),
/// Hsv(u8, u8, u8),
/// }
/// # fn main() {}
/// ```
///
/// Structs are not allowed:
///
/// ```compile_fail
/// # #[macro_use]
/// # extern crate num_derive;
/// #[derive(ToPrimitive)]
/// struct Color {
/// r: u8,
/// g: u8,
/// b: u8,
/// }
/// # fn main() {}
/// ```
#[proc_macro_derive(ToPrimitive)]
pub fn to_primitive(input: TokenStream) -> TokenStream {
let ast: syn::DeriveInput = syn::parse(input).unwrap();
Expand Down
22 changes: 0 additions & 22 deletions tests/compile-fail/from-primitive/derive_on_struct.rs

This file was deleted.

21 changes: 0 additions & 21 deletions tests/compile-fail/from-primitive/enum_with_associated_data.rs

This file was deleted.

22 changes: 0 additions & 22 deletions tests/compile-fail/to-primitive/derive_on_struct.rs

This file was deleted.

21 changes: 0 additions & 21 deletions tests/compile-fail/to-primitive/enum_with_associated_data.rs

This file was deleted.

27 changes: 0 additions & 27 deletions tests/compiletest.rs

This file was deleted.

0 comments on commit 11d7890

Please sign in to comment.