Skip to content
This repository has been archived by the owner on Jan 12, 2020. It is now read-only.

Use strum::EnumCount to derive Op counts #13

Merged
merged 7 commits into from Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions .travis.yml
Expand Up @@ -10,9 +10,11 @@ matrix:
include:
- rust: stable
before_script:
- rustup component add rustfmt-preview
- rustup component add rustfmt
- rustup component add clippy
script:
- cargo fmt -- --check
- cargo clippy
- cargo test
- rust: stable
script:
Expand All @@ -24,10 +26,7 @@ matrix:
script:
- cargo test --release
- rust: nightly
before_script:
- rustup component add clippy-preview
script:
- cargo clippy
- cargo test
- rust: nightly
script:
Expand Down
7 changes: 6 additions & 1 deletion Cargo.toml
Expand Up @@ -6,7 +6,9 @@ authors = ["Brian L. Troutwine <brian@troutwine.us>"]
[dependencies]
afl = "0.4"
arbitrary = "0.2"
bh_alloc = "0.1"
bh_alloc = "0.2.4"
strum = "0.13.0"
strum_macros = "0.13.0"

[[bin]]
path = "src/bin/stdlib/str/repeat.rs"
Expand All @@ -19,3 +21,6 @@ name = "hash_map"
[[bin]]
path = "src/bin/stdlib/collections/vec_deque.rs"
name = "vec_deque"

[patch.crates-io]
strum_macros = { git = "https://github.com/Peternator7/strum" }
3 changes: 3 additions & 0 deletions src/lib.rs
@@ -1,4 +1,7 @@
extern crate arbitrary;
extern crate strum;
#[macro_use]
extern crate strum_macros;
#[deny(warnings)]
#[deny(bad_style)]
#[deny(missing_docs)]
Expand Down
10 changes: 2 additions & 8 deletions src/stdlib/collections/hash_map.rs
Expand Up @@ -157,7 +157,7 @@ where
/// `HashMap<K, V>` and `PropHashMap<K, V>`. Some map directly to functions
/// available on the types, others require a more elaborate interpretation
/// step.
#[derive(Clone, Debug)]
#[derive(Clone, EnumCount, Debug)]
pub enum Op<K, V> {
/// This operation triggers `std::collections::HashMap::shrink_to_fit`
ShrinkToFit,
Expand Down Expand Up @@ -196,13 +196,7 @@ where
where
U: Unstructured + ?Sized,
{
// ================ WARNING ================
//
// `total_enum_fields` is a goofy annoyance but it should match
// _exactly_ the number of fields available in `Op<K, V>`. If it
// does not then we'll fail to generate `Op` variants for use in our
// QC tests.
let total_enum_fields = 6;
let total_enum_fields = OP_COUNT as u8;
dwijnand marked this conversation as resolved.
Show resolved Hide resolved
let variant: u8 = Arbitrary::arbitrary(u)?;
let op = match variant % total_enum_fields {
0 => {
Expand Down
10 changes: 2 additions & 8 deletions src/stdlib/collections/vec_deque.rs
Expand Up @@ -143,7 +143,7 @@ impl<T> PropVecDeque<T> {
/// The `Op<T>` defines the set of operations that are available against
/// `VecDeque<K, V>` and `PropVecDeque<T>`. Some map directly to functions
/// available on the types, others require a more elaborate interpretation step.
#[derive(Clone, Debug)]
#[derive(Clone, EnumCount, Debug)]
pub enum Op<T> {
/// This operation triggers `std::collections::VecDeque::shrink_to_fit`
ShrinkToFit,
Expand Down Expand Up @@ -173,13 +173,7 @@ where
where
U: Unstructured + ?Sized,
{
// ================ WARNING ================
//
// `total_enum_fields` is a goofy annoyance but it should match
// _exactly_ the number of fields available in `Op<T>`. If it
// does not then we'll fail to generate `Op` variants for use in our
// QC tests.
let total_enum_fields = 9;
let total_enum_fields = OP_COUNT as u8;
let variant: u8 = Arbitrary::arbitrary(u)?;
let op = match variant % total_enum_fields {
0 => {
Expand Down