Sanity/publish_to_crates_io_warns: create test

Verify that cargo warns when publishng to crates.io

Downstreamed version of the upstream test publish_to_crates_io_warns:
https://github.com/rust-lang/cargo/blob/0.94.0/tests/testsuite/package.rs#L7741

Originally implemented in https://github.com/rust-lang/cargo/pull/16241
This commit is contained in:
Jesus Checa Hidalgo 2026-03-17 19:18:23 +01:00
commit 58f9334383
2 changed files with 63 additions and 0 deletions

View file

@ -0,0 +1,12 @@
summary: Test cargo warning when publish to crates.io
description: |
Downstreamed version of the upstream test publish_to_crates_io_warns:
https://github.com/rust-lang/cargo/blob/0.94.0/tests/testsuite/package.rs#L7741
Originally implemented in https://github.com/rust-lang/cargo/pull/16241
We need to downstream this test because koji builders don't have DNS resolving
to reach crates.io index. Hence, running this during the build will always
fail with an unexpected "Could not resolve host: index.crates.io" message.
tier: 1

View file

@ -0,0 +1,51 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
. /usr/share/beakerlib/beakerlib.sh || exit 1
CRATE_NAME="foo"
CRATE_VER="0.1.0"
function generate_cargo_toml() {
local dest_dir=$1
tee "$dest_dir/Cargo.toml" <<EOF
[package]
name = "$CRATE_NAME"
version = "$CRATE_VER"
description = "$CRATE_NAME"
edition = "2015"
EOF
}
rlJournalStart
rlPhaseStartSetup
declare tmp
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
rlRun "generate_cargo_toml $tmp"
rlRun "pushd $tmp"
rlRun "mkdir src"
rlRun "echo 'fn main () {}' > src/main.rs"
rlRun "set -o pipefail"
rlPhaseEnd
rlPhaseStartTest
# Publish using dry-run to avoid real operations.
rlRun "cargo publish --dry-run |& tee output.log"
# Ensure DNS was not able to resolve the remote
rlAssertGrep 'Updating crates.io index' output.log
# Verify that cargo raises the warning
rlAssertGrep 'warning: manifest' output.log
# Verify packaging is done
rlAssertGrep "Packaging $CRATE_NAME v$CRATE_VER" output.log
rlAssertGrep "Verifying $CRATE_NAME v$CRATE_VER" output.log
rlAssertGrep "Compiling $CRATE_NAME v$CRATE_VER" output.log
rlAssertGrep "Uploading $CRATE_NAME v$CRATE_VER" output.log
# Verify warning about upload cancel
rlAssertGrep 'warning: aborting upload due to dry run' output.log
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $tmp" 0 "Remove tmp directory"
rlPhaseEnd
rlJournalEnd