Skip to content

Commit

Permalink
Make self_ty_in_mod_name the default
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Aug 21, 2024
1 parent 696f599 commit fcd3804
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 30 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ jobs:
package: [third-party, other]
serde_format: [bincode, postcard]
toolchain: [stable, nightly]
self_ty_in_mod_name: [false, true]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -188,10 +187,9 @@ jobs:
if [[ ${{ matrix.toolchain }} = nightly ]]; then
SHUFFLE='-Z unstable-options --shuffle --test-threads=1'
fi
SELF_TY_IN_MOD_NAME="$(${{ matrix.self_ty_in_mod_name }} && echo '--features test-fuzz/self_ty_in_mod_name')" || true
CONFIG_GROUP_RUNNER="--config target.'cfg(all())'.runner='group-runner'"
BUILD_CMD="cargo build $MAYBE_THIRD_PARTY $SERDE_FORMAT $SELF_TY_IN_MOD_NAME --all-targets"
TEST_CMD="cargo test $MAYBE_THIRD_PARTY $SERDE_FORMAT $SELF_TY_IN_MOD_NAME $CONFIG_GROUP_RUNNER -- --nocapture $SHUFFLE"
BUILD_CMD="cargo build $MAYBE_THIRD_PARTY $SERDE_FORMAT --all-targets"
TEST_CMD="cargo test $MAYBE_THIRD_PARTY $SERDE_FORMAT $CONFIG_GROUP_RUNNER -- --nocapture $SHUFFLE"
echo "BUILD_CMD=$BUILD_CMD" >> "$GITHUB_ENV"
echo "TEST_CMD=$TEST_CMD" >> "$GITHUB_ENV"
Expand Down
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ Note, however, that just because a target was called with certain parameters dur

##### `rename = "name"`

Treat the target as though its name is `name` when adding a module to the enclosing scope. Expansion of the `test_fuzz` macro adds a module definition to the enclosing scope. Currently, the module is named `target_fuzz`, where `target` is the name of the target. Use of this option causes the module to instead be be named `name_fuzz`. Example:
Treat the target as though its name is `name` when adding a module to the enclosing scope. Expansion of the `test_fuzz` macro adds a module definition to the enclosing scope. By default, the module is named as follows:

- If the target does not appear in an `impl` block, the module is named `target_fuzz`, where `target` is the name of the target.
- If the target appears in an `impl` block, the module is named `path_target_fuzz`, where `path` is the path of the `impl`'s `Self` type converted to snake case and joined with `_`.

However, use of this option causes the module to instead be named `name_fuzz`. Example:

```rust
#[test_fuzz(rename = "bar")]
Expand Down Expand Up @@ -329,7 +334,7 @@ impl<'de> serde::Deserialize<'de> for $ty {
}
```

If `$ty` is a unit struct, then `$expr` can be be omitted. That is, `dont_care!($ty)` is equivalent to `dont_care!($ty, $ty)`.
If `$ty` is a unit struct, then `$expr` can be omitted. That is, `dont_care!($ty)` is equivalent to `dont_care!($ty, $ty)`.

#### `leak!`

Expand Down Expand Up @@ -397,10 +402,10 @@ where

## `test-fuzz` package features

The features in this section apply to the `test-fuzz` package as a whole. Enable them in `test-fuzz`'s dependency specification as described in the [The Cargo Book]. For example, to enable the `self_ty_in_mod_name` feature, use:
The features in this section apply to the `test-fuzz` package as a whole. Enable them in `test-fuzz`'s dependency specification as described in the [The Cargo Book]. For example, to enable the `cast_checks` feature, use:

```toml
test-fuzz = { version = "*", features = ["self_ty_in_mod_name"] }
test-fuzz = { version = "*", features = ["cast_checks"] }
```

The `test-fuzz` package currently supports the following features:
Expand All @@ -409,12 +414,6 @@ The `test-fuzz` package currently supports the following features:

Use [`cast_checks`] to automatically check target functions for invalid casts.

### `self_ty_in_mod_name`

Incorporate an `impl`'s `Self` type into the names of modules generated for the `impl`. Expansion of the `test_fuzz` macro adds a module definition to the enclosing scope. By default, the module is named `target_fuzz`, where `target` is the name of the target. If the target appears in an `impl` block, then use of this feature causes the module to instead be named `path_target_fuzz`, where `path` is the path of the `impl`'s `Self` type converted to snake case and joined with `_`. (See also [`rename`] above.)

In a future version of `test-fuzz`, this behavior will be the default.

### Serde formats

`test-fuzz` can serialize target arguments in multiple Serde formats. The following are the features used to select a format.
Expand Down
8 changes: 5 additions & 3 deletions cargo-test-fuzz/tests/integration/fuzz_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ static MUTEX: Mutex<()> = Mutex::new(());
fn fuzz(test: &str, code: i32) {
let _lock = MUTEX.lock().unwrap();

let corpus = corpus_directory_from_target("generic", "target");
let corpus = corpus_directory_from_target("generic", "struct_target");

// smoelius: This call to `remove_dir_all` is protected by the mutex above.
#[cfg_attr(dylint_lib = "general", allow(non_thread_safe_call_in_test))]
remove_dir_all(corpus).unwrap_or_default();
remove_dir_all(&corpus).unwrap_or_default();

examples::test("generic", test)
.unwrap()
.logged_assert()
.success();

assert!(corpus.exists());

retry(3, || {
examples::test_fuzz("generic", "target")
examples::test_fuzz("generic", "struct_target")
.unwrap()
.args([
"--exit-code",
Expand Down
6 changes: 3 additions & 3 deletions cargo-test-fuzz/tests/integration/generic_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ fn generic() {
test(
"generic",
"test_bound",
"target_bound",
"struct_target_bound",
&impl_expected,
&expected,
);
test(
"generic",
"test_where_clause",
"target_where_clause",
"struct_target_where_clause",
&impl_expected,
&expected,
);
test(
"generic",
"test_only_generic_args",
"target_only_generic_args",
"struct_target_only_generic_args",
&impl_expected,
&expected,
);
Expand Down
3 changes: 1 addition & 2 deletions macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ proc-macro = true

[dependencies]
darling = { workspace = true }
heck = { workspace = true, optional = true }
heck = { workspace = true }
itertools = { workspace = true }
once_cell = { workspace = true }
prettyplease = { workspace = true }
Expand All @@ -25,7 +25,6 @@ syn = { workspace = true }
[features]
__cast_checks = []
__persistent = []
__self_ty_in_mod_name = ["heck"]

[lints]
workspace = true
1 change: 0 additions & 1 deletion macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,6 @@ fn mod_ident(opts: &TestFuzzOpts, self_ty_base: Option<&Ident>, target_ident: &I
if let Some(name) = &opts.rename {
s.push_str(&name.to_string());
} else {
#[cfg(feature = "__self_ty_in_mod_name")]
if let Some(ident) = self_ty_base {
s.push_str(&<str as heck::ToSnakeCase>::to_snake_case(
&ident.to_string(),
Expand Down
1 change: 0 additions & 1 deletion test-fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ testing = { workspace = true }

[features]
cast_checks = ["dep:cast_checks", "test-fuzz-macro/__cast_checks"]
self_ty_in_mod_name = ["test-fuzz-macro/__self_ty_in_mod_name"]
serde_bincode = ["internal/__serde_bincode"]
serde_postcard = ["internal/__serde_postcard"]
__persistent = ["afl", "test-fuzz-macro/__persistent"]
Expand Down
6 changes: 1 addition & 5 deletions test-fuzz/tests/integration/self_ty_in_mod_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ fn success() {
command.assert().success();
}

#[cfg_attr(not(feature = "self_ty_in_mod_name"), ignore)]
#[test]
fn self_ty_conflict() {
let mut command = test();

command
.args([
"--features=test-fuzz/self_ty_in_mod_name",
"--features=__self_ty_conflict",
])
.args(["--features=__self_ty_conflict"])
.assert()
.failure()
.stderr(predicate::str::contains(
Expand Down
2 changes: 1 addition & 1 deletion third-party/patches/solana_rbpf.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ index 781ce87..2a667b6 100644
thiserror = "1.0.26"

+serde = "1.0"
+test-fuzz = { path = "../../test-fuzz", features = ["self_ty_in_mod_name"] }
+test-fuzz = { path = "../../test-fuzz" }
+
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["memoryapi", "sysinfoapi", "winnt", "errhandlingapi"], optional = true }
Expand Down

0 comments on commit fcd3804

Please sign in to comment.