diff --git a/crates/sui/src/client_commands.rs b/crates/sui/src/client_commands.rs index 169f2a01dbb3b..a31105a38d042 100644 --- a/crates/sui/src/client_commands.rs +++ b/crates/sui/src/client_commands.rs @@ -732,6 +732,19 @@ impl SuiClientCommands { serialize_signed_transaction, lint, } => { + if build_config.test_mode { + return Err(SuiError::ModulePublishFailure { + error: format!( + "The `publish` subcommand should not be used with the `--test` flag\n\ + \n\ + Library code in published packages must not depend on test code.\n\ + In order to fix this and publish the package without `--test`, search for, and remove \ + instances of e.g. test modules declared as `friend`s of modules from `sources/`." + ), + } + .into()); + } + let sender = context.try_get_object_owner(&gas).await?; let sender = sender.unwrap_or(context.active_address()?);