Skip to content

Commit

Permalink
refactor(tests): Create an actual debug feature
Browse files Browse the repository at this point in the history
Previously `cfg!(any(feature="debug", debug_assertions))`
was equivalent to `cfg!(debug_assertions)`.
Now test code relies on `debug` feature for panic messages.
  • Loading branch information
thecaralice committed Nov 30, 2023
1 parent 103b349 commit 019fefd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
11 changes: 9 additions & 2 deletions pallets/gear/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ demo-init-wait = { workspace = true, optional = true }
wabt.workspace = true
hex.workspace = true
blake2-rfc.workspace = true
gstd = { workspace = true, features = ["debug"] }
gstd.workspace = true
demo-async.workspace = true
demo-async-init.workspace = true
demo-async-recursion.workspace = true
Expand Down Expand Up @@ -98,7 +98,7 @@ demo-compose.workspace = true
demo-constructor.workspace = true
demo-mul-by-const.workspace = true
demo-wait.workspace = true
demo-waiter = { workspace = true, features = ["debug"] } # The 'debug' feature is required for some assertion in tests
demo-waiter.workspace = true
demo-wait-timeout.workspace = true
demo-wait-wake.workspace = true
demo-reserve-gas.workspace = true
Expand Down Expand Up @@ -195,3 +195,10 @@ runtime-benchmarks = [
runtime-benchmarks-checkers = []
try-runtime = ["frame-support/try-runtime"]
fuzz = ["pallet-gear-gas/fuzz", "common/fuzz"]
debug = [
"demo-async-tester/debug",
"demo-constructor/debug",
"demo-delayed-reservation-sender/debug",
"demo-waiter/debug",
"test-syscalls/debug",
]
28 changes: 16 additions & 12 deletions pallets/gear/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ fn delayed_reservations_sending_validation() {

run_to_next_block(None);

let error_text = if cfg!(any(feature = "debug", debug_assertions)) {
let error_text = if cfg!(feature = "debug") {
format!(
"{SENDING_EXPECT}: {:?}",
GstdError::Core(
Expand Down Expand Up @@ -377,7 +377,7 @@ fn delayed_reservations_sending_validation() {

run_for_blocks(wait_for + 1, None);

let error_text = if cfg!(any(feature = "debug", debug_assertions)) {
let error_text = if cfg!(feature = "debug") {
format!(
"{SENDING_EXPECT}: {:?}",
GstdError::Core(
Expand Down Expand Up @@ -492,7 +492,7 @@ fn default_wait_lock_timeout() {

run_to_block(expiration_block, None);

let error_text = if cfg!(any(feature = "debug", debug_assertions)) {
let error_text = if cfg!(feature = "debug") {
format!(
"ran into error-reply: {:?}",
GstdError::Timeout(expiration_block, expiration_block)
Expand Down Expand Up @@ -7402,7 +7402,7 @@ fn pay_program_rent_syscall_works() {

run_to_next_block(None);

let error_text = if cfg!(any(feature = "debug", debug_assertions)) {
let error_text = if cfg!(feature = "debug") {
format!(
"{PAY_PROGRAM_RENT_EXPECT}: {:?}",
GstdError::Core(ExtError::Execution(ExecutionError::NotEnoughValue).into())
Expand Down Expand Up @@ -7448,7 +7448,7 @@ fn pay_program_rent_syscall_works() {

run_to_next_block(None);

let error_text = if cfg!(any(feature = "debug", debug_assertions)) {
let error_text = if cfg!(feature = "debug") {
format!(
"{PAY_PROGRAM_RENT_EXPECT}: {:?}",
GstdError::Core(
Expand Down Expand Up @@ -8658,7 +8658,7 @@ fn test_create_program_with_value_lt_ed() {
// to send init message with value in invalid range.
assert_total_dequeued(1);

let error_text = if cfg!(any(feature = "debug", debug_assertions)) {
let error_text = if cfg!(feature = "debug") {
format!(
"Failed to create program: {:?}",
GstdError::Core(ExtError::Message(MessageError::InsufficientValue).into())
Expand Down Expand Up @@ -8712,7 +8712,7 @@ fn test_create_program_with_exceeding_value() {
// to send init message with value in invalid range.
assert_total_dequeued(1);

let error_text = if cfg!(any(feature = "debug", debug_assertions)) {
let error_text = if cfg!(feature = "debug") {
format!(
"Failed to create program: {:?}",
GstdError::Core(ExtError::Execution(ExecutionError::NotEnoughValue).into())
Expand Down Expand Up @@ -8804,7 +8804,7 @@ fn demo_constructor_works() {

run_to_next_block(None);

let error_text = if cfg!(any(feature = "debug", debug_assertions)) {
let error_text = if cfg!(feature = "debug") {
"I just panic every time"
} else {
"no info"
Expand Down Expand Up @@ -9799,10 +9799,14 @@ fn mx_lock_ownership_exceedance() {

let get_lock_ownership_exceeded_trap = |command_msg_id| {
ActorExecutionErrorReplyReason::Trap(TrapExplanation::Panic(
format!(
"Message 0x{} has exceeded lock ownership time",
hex::encode(command_msg_id)
)
if cfg!(feature = "debug") {
format!(
"Message 0x{} has exceeded lock ownership time",
hex::encode(command_msg_id)
)
} else {
"no info".to_owned()
}
.into(),
))
};
Expand Down

0 comments on commit 019fefd

Please sign in to comment.