Skip to content

Commit ae523ba

Browse files
committed
Refactor common assertion to shared module.
1 parent b4e7f50 commit ae523ba

File tree

6 files changed

+15
-41
lines changed

6 files changed

+15
-41
lines changed

crates/resolc/src/tests/cli/asm.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
33
#![cfg(test)]
44

5-
use revive_common;
6-
75
use crate::tests::cli::utils;
86

97
const ASM_OPTION: &str = "--asm";
@@ -12,13 +10,7 @@ const ASM_OPTION: &str = "--asm";
1210
fn runs_with_valid_input_file() {
1311
const ARGUMENTS: &[&str] = &[utils::SOLIDITY_CONTRACT_PATH, ASM_OPTION];
1412
let resolc_result = utils::execute_resolc(ARGUMENTS);
15-
assert!(
16-
resolc_result.success,
17-
"Providing a valid input file should succeed with exit code {}, got {}.\nDetails: {}",
18-
revive_common::EXIT_CODE_SUCCESS,
19-
resolc_result.code,
20-
resolc_result.output
21-
);
13+
utils::assert_command_success(&resolc_result, "Providing a valid input file");
2214

2315
for pattern in &["deploy", "call", "seal_return"] {
2416
assert!(

crates/resolc/src/tests/cli/output_dir.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use std::path::Path;
66

7-
use revive_common;
87
use rstest::rstest;
98

109
use crate::tests::cli::utils;
@@ -30,13 +29,7 @@ fn assert_valid_output_file(
3029
output_file_type: &str,
3130
output_file_path: &str,
3231
) {
33-
assert!(
34-
result.success,
35-
"Providing an output directory should succeed with exit code {}, got {}.\nDetails: {}",
36-
revive_common::EXIT_CODE_SUCCESS,
37-
result.code,
38-
result.output
39-
);
32+
utils::assert_command_success(&result, "Providing an output directory");
4033

4134
assert!(
4235
result.output.contains("Compiler run successful"),

crates/resolc/src/tests/cli/standard_json.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
33
#![cfg(test)]
44

5-
use revive_common;
6-
75
use crate::tests::cli::utils;
86

97
const JSON_OPTION: &str = "--standard-json";
@@ -13,13 +11,7 @@ fn runs_with_valid_input_file() {
1311
const ARGUMENTS: &[&str] = &[JSON_OPTION];
1412
let resolc_result =
1513
utils::execute_resolc_with_stdin_input(ARGUMENTS, utils::STANDARD_JSON_CONTRACTS_PATH);
16-
assert!(
17-
resolc_result.success,
18-
"Providing a valid input file to stdin should succeed with exit code {}, got {}.\nDetails: {}",
19-
revive_common::EXIT_CODE_SUCCESS,
20-
resolc_result.code,
21-
resolc_result.output
22-
);
14+
utils::assert_command_success(&resolc_result, "Providing a valid input file to stdin");
2315

2416
assert!(
2517
resolc_result.output.contains("contracts"),

crates/resolc/src/tests/cli/usage.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ use crate::tests::cli::utils;
99
fn shows_usage_with_help() {
1010
const ARGUMENTS: &[&str] = &["--help"];
1111
let resolc_result = utils::execute_resolc(ARGUMENTS);
12-
assert!(
13-
resolc_result.success,
14-
"Providing the `--help` option should succeed with exit code {}, got {}.",
15-
revive_common::EXIT_CODE_SUCCESS,
16-
resolc_result.code
17-
);
12+
utils::assert_command_success(&resolc_result, "Providing the `--help` option");
1813

1914
assert!(
2015
resolc_result.output.contains("Usage: resolc"),

crates/resolc/src/tests/cli/utils.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ pub fn assert_equal_exit_codes(solc_result: &CommandResult, resolc_result: &Comm
8383
);
8484
}
8585

86+
pub fn assert_command_success(result: &CommandResult, error_message_prefix: &str) {
87+
assert!(
88+
result.success,
89+
"{error_message_prefix} should succeed with exit code {}, got {}.\nDetails: {}",
90+
revive_common::EXIT_CODE_SUCCESS,
91+
result.code,
92+
result.output
93+
);
94+
}
95+
8696
pub fn assert_command_failure(result: &CommandResult, error_message_prefix: &str) {
8797
assert!(
8898
!result.success,

crates/resolc/src/tests/cli/yul.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
33
#![cfg(test)]
44

5-
use revive_common;
6-
75
use crate::tests::cli::utils;
86

97
pub const YUL_OPTION: &str = "--yul";
@@ -15,13 +13,7 @@ const SOLC_YUL_OPTION: &str = "--strict-assembly";
1513
fn runs_with_valid_input_file() {
1614
const ARGUMENTS: &[&str] = &[utils::YUL_CONTRACT_PATH, YUL_OPTION];
1715
let resolc_result = utils::execute_resolc(ARGUMENTS);
18-
assert!(
19-
resolc_result.success,
20-
"Providing a valid input file should succeed with exit code {}, got {}.\nDetails: {}",
21-
revive_common::EXIT_CODE_SUCCESS,
22-
resolc_result.code,
23-
resolc_result.output
24-
);
16+
utils::assert_command_success(&resolc_result, "Providing a valid input file");
2517

2618
assert!(
2719
resolc_result

0 commit comments

Comments
 (0)