Skip to content

Commit d95b504

Browse files
committed
attempt #3
1 parent 100b985 commit d95b504

3 files changed

Lines changed: 107 additions & 80 deletions

File tree

Cargo.lock

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ license = "Apache-2.0"
2828
keywords = ["fuzzing", "pickle", "security", "testing", "generator", "corpus"]
2929
categories = ["development-tools::testing", "command-line-utilities"]
3030

31-
[lints.rust]
32-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin)'] }
33-
3431
[[bin]]
3532
name = "pickle-fuzzer"
3633
path = "src/main.rs"
@@ -51,6 +48,7 @@ rayon = "1.11.0"
5148
serde = { version = "1.0.228", features = ["derive"] }
5249

5350
[dev-dependencies]
51+
assert_cmd = "2.0"
5452
criterion = { version = "0.5", features = ["html_reports"] }
5553
tempfile = "3.8"
5654

tests/integration_test.rs

Lines changed: 31 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
16+
use std::fs;
17+
18+
use tempfile::NamedTempFile;
19+
use tempfile::TempDir;
20+
use assert_cmd::cargo::cargo_bin_cmd;
1621

1722
use pickle_fuzzer::{Generator, Version};
1823

@@ -138,25 +143,15 @@ fn test_protocol_v2_and_above_have_proto() {
138143
}
139144

140145
#[test]
141-
#[cfg_attr(tarpaulin, ignore)]
142146
fn test_cli_single_file_generation() {
143-
use std::fs;
144-
use std::process::Command;
145-
use tempfile::NamedTempFile;
146-
147147
let temp_file = NamedTempFile::new().expect("failed to create temp file");
148148
let temp_path = temp_file.path().to_str().unwrap();
149149

150-
let output = Command::new("cargo")
151-
.args(["run", "--quiet", "--", temp_path])
152-
.output()
153-
.expect("failed to execute command");
150+
cargo_bin_cmd!("pickle-fuzzer")
151+
.arg(temp_path)
152+
.assert()
153+
.success();
154154

155-
assert!(
156-
output.status.success(),
157-
"CLI command failed: {:?}",
158-
String::from_utf8_lossy(&output.stderr)
159-
);
160155
assert!(fs::metadata(temp_path).is_ok(), "output file not created");
161156

162157
let contents = fs::read(temp_path).expect("failed to read output file");
@@ -165,49 +160,37 @@ fn test_cli_single_file_generation() {
165160
}
166161

167162
#[test]
168-
#[cfg_attr(tarpaulin, ignore)]
169163
fn test_cli_with_protocol_flag() {
170-
use std::fs;
171-
use std::process::Command;
172-
use tempfile::NamedTempFile;
173-
174164
let temp_file = NamedTempFile::new().expect("failed to create temp file");
175165
let temp_path = temp_file.path().to_str().unwrap();
176166

177-
let output = Command::new("cargo")
178-
.args(["run", "--quiet", "--", "--protocol", "4", temp_path])
179-
.output()
180-
.expect("failed to execute command");
181-
182-
assert!(output.status.success(), "CLI command failed");
167+
cargo_bin_cmd!("pickle-fuzzer")
168+
.args(["--protocol", "4", temp_path])
169+
.assert()
170+
.success();
183171

184172
let contents = fs::read(temp_path).expect("failed to read output file");
185173
assert_eq!(contents[0], 0x80, "should start with PROTO opcode");
186174
assert_eq!(contents[1], 4, "should be protocol 4");
187175
}
188176

189177
#[test]
190-
#[cfg_attr(tarpaulin, ignore)]
191178
fn test_cli_with_seed_produces_deterministic_output() {
192-
use std::fs;
193-
use std::process::Command;
194-
use tempfile::NamedTempFile;
195-
196179
let temp_file1 = NamedTempFile::new().expect("failed to create temp file 1");
197180
let temp_file2 = NamedTempFile::new().expect("failed to create temp file 2");
198181
let temp_path1 = temp_file1.path().to_str().unwrap();
199182
let temp_path2 = temp_file2.path().to_str().unwrap();
200183

201184
// generate with same seed twice
202-
Command::new("cargo")
203-
.args(["run", "--quiet", "--", "--seed", "42", temp_path1])
204-
.output()
205-
.expect("failed to execute command");
185+
cargo_bin_cmd!("pickle-fuzzer")
186+
.args(["--seed", "42", temp_path1])
187+
.assert()
188+
.success();
206189

207-
Command::new("cargo")
208-
.args(["run", "--quiet", "--", "--seed", "42", temp_path2])
209-
.output()
210-
.expect("failed to execute command");
190+
cargo_bin_cmd!("pickle-fuzzer")
191+
.args(["--seed", "42", temp_path2])
192+
.assert()
193+
.success();
211194

212195
let contents1 = fs::read(temp_path1).expect("failed to read file 1");
213196
let contents2 = fs::read(temp_path2).expect("failed to read file 2");
@@ -219,25 +202,14 @@ fn test_cli_with_seed_produces_deterministic_output() {
219202
}
220203

221204
#[test]
222-
#[cfg_attr(tarpaulin, ignore)]
223205
fn test_cli_batch_mode() {
224-
use std::fs;
225-
use std::process::Command;
226-
use tempfile::TempDir;
227-
228206
let temp_dir = TempDir::new().expect("failed to create temp dir");
229207
let temp_path = temp_dir.path().to_str().unwrap();
230208

231-
let output = Command::new("cargo")
232-
.args(["run", "--quiet", "--", "--dir", temp_path, "--samples", "5"])
233-
.output()
234-
.expect("failed to execute command");
235-
236-
assert!(
237-
output.status.success(),
238-
"batch generation failed: {:?}",
239-
String::from_utf8_lossy(&output.stderr)
240-
);
209+
cargo_bin_cmd!("pickle-fuzzer")
210+
.args(["--dir", temp_path, "--samples", "5"])
211+
.assert()
212+
.success();
241213

242214
// check that files were created
243215
let entries = fs::read_dir(temp_path).expect("failed to read dir");
@@ -252,58 +224,40 @@ fn test_cli_batch_mode() {
252224
}
253225

254226
#[test]
255-
#[cfg_attr(tarpaulin, ignore)]
256227
fn test_cli_with_opcode_range() {
257-
use std::fs;
258-
use std::process::Command;
259-
use tempfile::NamedTempFile;
260-
261228
let temp_file = NamedTempFile::new().expect("failed to create temp file");
262229
let temp_path = temp_file.path().to_str().unwrap();
263230

264-
let output = Command::new("cargo")
231+
cargo_bin_cmd!("pickle-fuzzer")
265232
.args([
266-
"run",
267-
"--quiet",
268-
"--",
269233
"--min-opcodes",
270234
"10",
271235
"--max-opcodes",
272236
"20",
273237
temp_path,
274238
])
275-
.output()
276-
.expect("failed to execute command");
239+
.assert()
240+
.success();
277241

278-
assert!(output.status.success(), "CLI command failed");
279242
assert!(fs::metadata(temp_path).is_ok(), "output file not created");
280243
}
281244

282245
#[test]
283-
#[cfg_attr(tarpaulin, ignore)]
284246
fn test_cli_with_mutators() {
285-
use std::fs;
286-
use std::process::Command;
287-
use tempfile::NamedTempFile;
288-
289247
let temp_file = NamedTempFile::new().expect("failed to create temp file");
290248
let temp_path = temp_file.path().to_str().unwrap();
291249

292-
let output = Command::new("cargo")
250+
cargo_bin_cmd!("pickle-fuzzer")
293251
.args([
294-
"run",
295-
"--quiet",
296-
"--",
297252
"--mutators",
298253
"bitflip",
299254
"boundary",
300255
"--mutation-rate",
301256
"0.5",
302257
temp_path,
303258
])
304-
.output()
305-
.expect("failed to execute command");
259+
.assert()
260+
.success();
306261

307-
assert!(output.status.success(), "CLI command with mutators failed");
308262
assert!(fs::metadata(temp_path).is_ok(), "output file not created");
309263
}

0 commit comments

Comments
 (0)