2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for --offline flag.
|
|
|
|
|
2023-02-28 22:46:45 +00:00
|
|
|
use cargo_test_support::{
|
|
|
|
basic_manifest, git, main_file, path2url, project,
|
|
|
|
registry::{Package, RegistryBuilder},
|
2023-04-27 07:39:23 +00:00
|
|
|
Execs,
|
2023-02-28 22:46:45 +00:00
|
|
|
};
|
2019-04-23 22:13:55 +00:00
|
|
|
use std::fs;
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-23 22:13:55 +00:00
|
|
|
fn offline_unused_target_dep() {
|
2019-05-12 17:49:45 +00:00
|
|
|
// --offline with a target dependency that is not used and not downloaded.
|
2019-04-23 22:13:55 +00:00
|
|
|
Package::new("unused_dep", "1.0.0").publish();
|
|
|
|
Package::new("used_dep", "1.0.0").publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
[dependencies]
|
|
|
|
used_dep = "1.0"
|
|
|
|
[target.'cfg(unused)'.dependencies]
|
|
|
|
unused_dep = "1.0"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
// Do a build that downloads only what is necessary.
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check")
|
2019-04-23 22:13:55 +00:00
|
|
|
.with_stderr_contains("[DOWNLOADED] used_dep [..]")
|
|
|
|
.with_stderr_does_not_contain("[DOWNLOADED] unused_dep [..]")
|
|
|
|
.run();
|
|
|
|
p.cargo("clean").run();
|
|
|
|
// Build offline, make sure it works.
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check --offline").run();
|
2019-04-23 22:13:55 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-23 22:13:55 +00:00
|
|
|
fn offline_missing_optional() {
|
|
|
|
Package::new("opt_dep", "1.0.0").publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
[dependencies]
|
|
|
|
opt_dep = { version = "1.0", optional = true }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
// Do a build that downloads only what is necessary.
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check")
|
2019-04-23 22:13:55 +00:00
|
|
|
.with_stderr_does_not_contain("[DOWNLOADED] opt_dep [..]")
|
|
|
|
.run();
|
|
|
|
p.cargo("clean").run();
|
|
|
|
// Build offline, make sure it works.
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check --offline").run();
|
|
|
|
p.cargo("check --offline --features=opt_dep")
|
2019-04-23 22:13:55 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] failed to download `opt_dep v1.0.0`
|
|
|
|
|
|
|
|
Caused by:
|
2022-03-09 22:10:22 +00:00
|
|
|
attempting to make an HTTP request, but --offline was specified
|
2019-04-23 22:13:55 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-23 22:13:55 +00:00
|
|
|
fn cargo_compile_path_with_offline() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check --offline").run();
|
2019-04-23 22:13:55 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-23 22:13:55 +00:00
|
|
|
fn cargo_compile_with_downloaded_dependency_with_offline() {
|
|
|
|
Package::new("present_dep", "1.2.3")
|
|
|
|
.file("Cargo.toml", &basic_manifest("present_dep", "1.2.3"))
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
// make package downloaded
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
present_dep = "1.2.3"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check").run();
|
2019-04-23 22:13:55 +00:00
|
|
|
|
|
|
|
let p2 = project()
|
|
|
|
.at("bar")
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
present_dep = "1.2.3"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2023-02-16 00:14:53 +00:00
|
|
|
p2.cargo("check --offline")
|
2019-04-23 22:13:55 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
2023-02-16 00:14:53 +00:00
|
|
|
[CHECKING] present_dep v1.2.3
|
|
|
|
[CHECKING] bar v0.1.0 ([..])
|
2019-04-23 22:13:55 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-23 22:13:55 +00:00
|
|
|
fn cargo_compile_offline_not_try_update() {
|
2019-12-03 19:52:10 +00:00
|
|
|
// When --offline needs to download the registry, provide a reasonable
|
|
|
|
// error hint to run without --offline.
|
2019-04-23 22:13:55 +00:00
|
|
|
let p = project()
|
|
|
|
.at("bar")
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
not_cached_dep = "1.2.5"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2019-12-03 19:52:10 +00:00
|
|
|
let msg = "\
|
|
|
|
[ERROR] no matching package named `not_cached_dep` found
|
2021-06-27 19:18:36 +00:00
|
|
|
location searched: registry `crates-io`
|
2019-12-03 19:52:10 +00:00
|
|
|
required by package `bar v0.1.0 ([..]/bar)`
|
|
|
|
As a reminder, you're using offline mode (--offline) which can sometimes cause \
|
|
|
|
surprising resolution failures, if this error is too confusing you may wish to \
|
|
|
|
retry without the offline flag.
|
|
|
|
";
|
|
|
|
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check --offline")
|
2019-04-23 22:13:55 +00:00
|
|
|
.with_status(101)
|
2019-12-03 19:52:10 +00:00
|
|
|
.with_stderr(msg)
|
2019-04-23 22:13:55 +00:00
|
|
|
.run();
|
2019-05-12 17:49:45 +00:00
|
|
|
|
2019-12-03 19:52:10 +00:00
|
|
|
// While we're here, also check the config works.
|
2024-01-26 19:40:46 +00:00
|
|
|
p.change_file(".cargo/config.toml", "net.offline = true");
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check").with_status(101).with_stderr(msg).run();
|
2019-04-23 22:13:55 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-23 22:13:55 +00:00
|
|
|
fn compile_offline_without_maxvers_cached() {
|
|
|
|
Package::new("present_dep", "1.2.1").publish();
|
|
|
|
Package::new("present_dep", "1.2.2").publish();
|
|
|
|
|
|
|
|
Package::new("present_dep", "1.2.3")
|
|
|
|
.file("Cargo.toml", &basic_manifest("present_dep", "1.2.3"))
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"pub fn get_version()->&'static str {"1.2.3"}"#,
|
|
|
|
)
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
Package::new("present_dep", "1.2.5")
|
|
|
|
.file("Cargo.toml", &basic_manifest("present_dep", "1.2.5"))
|
|
|
|
.file("src/lib.rs", r#"pub fn get_version(){"1.2.5"}"#)
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
// make package cached
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
present_dep = "=1.2.3"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
p.cargo("build").run();
|
|
|
|
|
|
|
|
let p2 = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
present_dep = "1.2"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"\
|
|
|
|
extern crate present_dep;
|
|
|
|
fn main(){
|
|
|
|
println!(\"{}\", present_dep::get_version());
|
|
|
|
}",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
2019-05-12 17:49:45 +00:00
|
|
|
p2.cargo("run --offline")
|
2019-04-23 22:13:55 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] present_dep v1.2.3
|
|
|
|
[COMPILING] foo v0.1.0 ([CWD])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
Running `[..]`",
|
|
|
|
)
|
|
|
|
.with_stdout("1.2.3")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-23 22:13:55 +00:00
|
|
|
fn cargo_compile_forbird_git_httpsrepo_offline() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["chabapok@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
git = 'https://github.com/some_user/dep1.git'
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check --offline").with_status(101).with_stderr("\
|
2020-02-27 16:17:18 +00:00
|
|
|
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 [..]`
|
2020-02-25 18:17:11 +00:00
|
|
|
|
|
|
|
Caused by:
|
|
|
|
failed to load source for dependency `dep1`
|
2019-04-23 22:13:55 +00:00
|
|
|
|
|
|
|
Caused by:
|
|
|
|
Unable to update https://github.com/some_user/dep1.git
|
|
|
|
|
|
|
|
Caused by:
|
2019-05-12 17:49:45 +00:00
|
|
|
can't checkout from 'https://github.com/some_user/dep1.git': you are in the offline mode (--offline)").run();
|
2019-04-23 22:13:55 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-23 22:13:55 +00:00
|
|
|
fn compile_offline_while_transitive_dep_not_cached() {
|
|
|
|
let baz = Package::new("baz", "1.0.0");
|
|
|
|
let baz_path = baz.archive_dst();
|
|
|
|
baz.publish();
|
|
|
|
|
|
|
|
let baz_content = fs::read(&baz_path).unwrap();
|
|
|
|
// Truncate the file to simulate a download failure.
|
|
|
|
fs::write(&baz_path, &[]).unwrap();
|
|
|
|
|
|
|
|
Package::new("bar", "0.1.0").dep("baz", "1.0.0").publish();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = "0.1.0"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main(){}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// simulate download bar, but fail to download baz
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check")
|
2019-04-23 22:13:55 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[..]failed to verify the checksum of `baz[..]")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
// Restore the file contents.
|
|
|
|
fs::write(&baz_path, &baz_content).unwrap();
|
|
|
|
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check --offline")
|
2019-04-23 22:13:55 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2020-03-22 22:08:02 +00:00
|
|
|
[ERROR] failed to download `bar v0.1.0`
|
2019-04-23 22:13:55 +00:00
|
|
|
|
|
|
|
Caused by:
|
2022-03-09 22:10:22 +00:00
|
|
|
attempting to make an HTTP request, but --offline was specified
|
2019-04-23 22:13:55 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2021-03-18 14:33:55 +00:00
|
|
|
fn update_offline_not_cached() {
|
2019-04-23 22:13:55 +00:00
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = "*"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2019-05-12 17:49:45 +00:00
|
|
|
p.cargo("update --offline")
|
2019-04-23 22:13:55 +00:00
|
|
|
.with_status(101)
|
2021-03-18 14:33:55 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] no matching package named `bar` found
|
|
|
|
location searched: registry `[..]`
|
|
|
|
required by package `foo v0.0.1 ([..]/foo)`
|
|
|
|
As a reminder, you're using offline mode (--offline) which can sometimes cause \
|
|
|
|
surprising resolution failures, if this error is too confusing you may wish to \
|
|
|
|
retry without the offline flag.",
|
|
|
|
)
|
2019-04-23 22:13:55 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2023-02-28 22:46:45 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn update_offline_not_cached_sparse() {
|
|
|
|
let _registry = RegistryBuilder::new().http_index().build();
|
|
|
|
update_offline_not_cached()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn update_offline_not_cached_git() {
|
|
|
|
update_offline_not_cached()
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-23 22:13:55 +00:00
|
|
|
fn cargo_compile_offline_with_cached_git_dep() {
|
2023-04-27 07:39:23 +00:00
|
|
|
compile_offline_with_cached_git_dep(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn gitoxide_cargo_compile_offline_with_cached_git_dep_shallow_dep() {
|
|
|
|
compile_offline_with_cached_git_dep(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compile_offline_with_cached_git_dep(shallow: bool) {
|
2019-04-23 22:13:55 +00:00
|
|
|
let git_project = git::new("dep1", |project| {
|
|
|
|
project
|
|
|
|
.file("Cargo.toml", &basic_manifest("dep1", "0.5.0"))
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub static COOL_STR:&str = "cached git repo rev1";
|
|
|
|
"#,
|
|
|
|
)
|
2019-08-13 05:25:36 +00:00
|
|
|
});
|
2019-04-23 22:13:55 +00:00
|
|
|
|
|
|
|
let repo = git2::Repository::open(&git_project.root()).unwrap();
|
|
|
|
let rev1 = repo.revparse_single("HEAD").unwrap().id();
|
|
|
|
|
|
|
|
// Commit the changes and make sure we trigger a recompile
|
|
|
|
git_project.change_file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"pub static COOL_STR:&str = "cached git repo rev2";"#,
|
|
|
|
);
|
|
|
|
git::add(&repo);
|
|
|
|
let rev2 = git::commit(&repo);
|
|
|
|
|
|
|
|
// cache to registry rev1 and rev2
|
|
|
|
let prj = project()
|
|
|
|
.at("cache_git_dep")
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "cache_git_dep"
|
|
|
|
version = "0.5.0"
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
git = '{}'
|
|
|
|
rev = "{}"
|
|
|
|
"#,
|
|
|
|
git_project.url(),
|
|
|
|
rev1
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main(){}")
|
|
|
|
.build();
|
2023-04-27 07:39:23 +00:00
|
|
|
let maybe_use_shallow = |mut cargo: Execs| -> Execs {
|
|
|
|
if shallow {
|
|
|
|
cargo
|
2024-01-05 14:17:39 +00:00
|
|
|
.arg("-Zgitoxide=fetch")
|
|
|
|
.arg("-Zgit=shallow-deps")
|
2023-04-27 07:39:23 +00:00
|
|
|
.masquerade_as_nightly_cargo(&[
|
2024-01-05 14:17:39 +00:00
|
|
|
"unstable features must be available for -Z gitoxide and -Z git",
|
2023-04-27 07:39:23 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
cargo
|
|
|
|
};
|
|
|
|
maybe_use_shallow(prj.cargo("build")).run();
|
2019-04-23 22:13:55 +00:00
|
|
|
|
|
|
|
prj.change_file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "cache_git_dep"
|
|
|
|
version = "0.5.0"
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
git = '{}'
|
|
|
|
rev = "{}"
|
|
|
|
"#,
|
|
|
|
git_project.url(),
|
|
|
|
rev2
|
|
|
|
),
|
|
|
|
);
|
2023-04-27 07:39:23 +00:00
|
|
|
maybe_use_shallow(prj.cargo("build")).run();
|
2019-04-23 22:13:55 +00:00
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
git = '{}'
|
|
|
|
"#,
|
|
|
|
git_project.url()
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
&main_file(r#""hello from {}", dep1::COOL_STR"#, &["dep1"]),
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let git_root = git_project.root();
|
|
|
|
|
2023-04-27 07:39:23 +00:00
|
|
|
let mut cargo = p.cargo("build --offline");
|
|
|
|
cargo.with_stderr(format!(
|
|
|
|
"\
|
2019-04-23 22:13:55 +00:00
|
|
|
[COMPILING] dep1 v0.5.0 ({}#[..])
|
|
|
|
[COMPILING] foo v0.5.0 ([CWD])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
|
2023-04-27 07:39:23 +00:00
|
|
|
path2url(git_root),
|
|
|
|
));
|
|
|
|
maybe_use_shallow(cargo).run();
|
2019-04-23 22:13:55 +00:00
|
|
|
|
|
|
|
assert!(p.bin("foo").is_file());
|
|
|
|
|
|
|
|
p.process(&p.bin("foo"))
|
|
|
|
.with_stdout("hello from cached git repo rev2\n")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.change_file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2019-04-23 22:13:55 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
git = '{}'
|
|
|
|
rev = "{}"
|
|
|
|
"#,
|
|
|
|
git_project.url(),
|
|
|
|
rev1
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2023-04-27 07:39:23 +00:00
|
|
|
maybe_use_shallow(p.cargo("build --offline")).run();
|
2019-04-23 22:13:55 +00:00
|
|
|
p.process(&p.bin("foo"))
|
|
|
|
.with_stdout("hello from cached git repo rev1\n")
|
|
|
|
.run();
|
|
|
|
}
|
2019-04-24 00:45:22 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-24 00:45:22 +00:00
|
|
|
fn offline_resolve_optional_fail() {
|
|
|
|
// Example where resolve fails offline.
|
|
|
|
//
|
|
|
|
// This happens if at least 1 version of an optional dependency is
|
|
|
|
// available, but none of them satisfy the requirements. The current logic
|
|
|
|
// that handles this is `RegistryIndex::query_inner`, and it doesn't know
|
|
|
|
// if the package being queried is an optional one. This is not ideal, it
|
|
|
|
// would be best if it just ignored optional (unselected) dependencies.
|
|
|
|
Package::new("dep", "1.0.0").publish();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
dep = { version = "1.0", optional = true }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("fetch").run();
|
|
|
|
|
|
|
|
// Change dep to 2.0.
|
|
|
|
p.change_file(
|
|
|
|
"Cargo.toml",
|
2019-05-01 21:39:15 +00:00
|
|
|
r#"
|
2019-04-24 00:45:22 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
dep = { version = "2.0", optional = true }
|
2020-09-27 00:59:58 +00:00
|
|
|
"#,
|
2019-04-24 00:45:22 +00:00
|
|
|
);
|
|
|
|
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check --offline")
|
2019-04-24 00:45:22 +00:00
|
|
|
.with_status(101)
|
2021-06-27 19:18:36 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
2019-04-24 00:45:22 +00:00
|
|
|
[ERROR] failed to select a version for the requirement `dep = \"^2.0\"`
|
2020-06-25 15:25:52 +00:00
|
|
|
candidate versions found which didn't match: 1.0.0
|
2021-06-27 19:18:36 +00:00
|
|
|
location searched: `[..]` index (which is replacing registry `crates-io`)
|
2019-04-24 00:45:22 +00:00
|
|
|
required by package `foo v0.1.0 ([..]/foo)`
|
|
|
|
perhaps a crate was updated and forgotten to be re-vendored?
|
2019-05-12 17:49:45 +00:00
|
|
|
As a reminder, you're using offline mode (--offline) which can sometimes cause \
|
2019-04-24 00:45:22 +00:00
|
|
|
surprising resolution failures, if this error is too confusing you may wish to \
|
|
|
|
retry without the offline flag.
|
2021-06-27 19:18:36 +00:00
|
|
|
",
|
|
|
|
)
|
2019-04-24 00:45:22 +00:00
|
|
|
.run();
|
|
|
|
}
|
2019-12-03 19:52:10 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn offline_with_all_patched() {
|
|
|
|
// Offline works if everything is patched.
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
dep = "1.0"
|
|
|
|
|
|
|
|
[patch.crates-io]
|
|
|
|
dep = {path = "dep"}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "pub fn f() { dep::foo(); }")
|
|
|
|
.file("dep/Cargo.toml", &basic_manifest("dep", "1.0.0"))
|
|
|
|
.file("dep/src/lib.rs", "pub fn foo() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check --offline").run();
|
|
|
|
}
|
2021-03-14 12:36:36 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
2021-03-18 14:33:55 +00:00
|
|
|
fn update_offline_cached() {
|
2021-03-14 12:36:36 +00:00
|
|
|
// Cache a few versions to update against
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
|
|
|
let versions = ["1.2.3", "1.2.5", "1.2.9"];
|
|
|
|
for vers in versions.iter() {
|
|
|
|
Package::new("present_dep", vers)
|
|
|
|
.file("Cargo.toml", &basic_manifest("present_dep", vers))
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
format!(r#"pub fn get_version()->&'static str {{ "{}" }}"#, vers).as_str(),
|
|
|
|
)
|
|
|
|
.publish();
|
|
|
|
// make package cached
|
|
|
|
p.change_file(
|
|
|
|
"Cargo.toml",
|
|
|
|
format!(
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2021-03-14 12:36:36 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
present_dep = "={}"
|
|
|
|
"#,
|
|
|
|
vers
|
|
|
|
)
|
|
|
|
.as_str(),
|
|
|
|
);
|
|
|
|
p.cargo("build").run();
|
|
|
|
}
|
|
|
|
|
|
|
|
let p2 = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2021-03-14 12:36:36 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
present_dep = "1.2"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"\
|
|
|
|
extern crate present_dep;
|
|
|
|
fn main(){
|
|
|
|
println!(\"{}\", present_dep::get_version());
|
|
|
|
}",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p2.cargo("build --offline")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] present_dep v1.2.9
|
|
|
|
[COMPILING] foo v0.1.0 ([CWD])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
p2.rename_run("foo", "with_1_2_9")
|
|
|
|
.with_stdout("1.2.9")
|
|
|
|
.run();
|
|
|
|
// updates happen without updating the index
|
2023-08-23 14:13:34 +00:00
|
|
|
p2.cargo("update present_dep --precise 1.2.3 --offline")
|
2021-03-14 12:36:36 +00:00
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2023-03-13 09:27:57 +00:00
|
|
|
[DOWNGRADING] present_dep v1.2.9 -> v1.2.3
|
2021-03-14 12:36:36 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p2.cargo("build --offline")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] present_dep v1.2.3
|
|
|
|
[COMPILING] foo v0.1.0 ([CWD])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
2021-03-18 14:04:42 +00:00
|
|
|
p2.rename_run("foo", "with_1_2_3")
|
2021-03-14 12:36:36 +00:00
|
|
|
.with_stdout("1.2.3")
|
|
|
|
.run();
|
|
|
|
|
2021-03-18 14:04:42 +00:00
|
|
|
// Offline update should only print package details and not index updating
|
|
|
|
p2.cargo("update --offline")
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[UPDATING] present_dep v1.2.3 -> v1.2.9
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
2021-03-14 12:36:36 +00:00
|
|
|
// No v1.2.8 loaded into the cache so expect failure.
|
2023-08-23 14:13:34 +00:00
|
|
|
p2.cargo("update present_dep --precise 1.2.8 --offline")
|
2021-03-14 12:36:36 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] no matching package named `present_dep` found
|
|
|
|
location searched: registry `[..]`
|
|
|
|
required by package `foo v0.1.0 ([..]/foo)`
|
|
|
|
As a reminder, you're using offline mode (--offline) which can sometimes cause \
|
|
|
|
surprising resolution failures, if this error is too confusing you may wish to \
|
|
|
|
retry without the offline flag.
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2021-07-01 22:58:45 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn offline_and_frozen_and_no_lock() {
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check --frozen --offline")
|
2021-07-01 22:58:45 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("\
|
|
|
|
error: the lock file [ROOT]/foo/Cargo.lock needs to be updated but --frozen was passed to prevent this
|
|
|
|
If you want to try to generate the lock file without accessing the network, \
|
|
|
|
remove the --frozen flag and use --offline instead.
|
|
|
|
")
|
|
|
|
.run();
|
|
|
|
}
|
2022-03-27 03:13:24 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn offline_and_locked_and_no_frozen() {
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2023-02-16 00:14:53 +00:00
|
|
|
p.cargo("check --locked --offline")
|
2022-03-27 03:13:24 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("\
|
|
|
|
error: the lock file [ROOT]/foo/Cargo.lock needs to be updated but --locked was passed to prevent this
|
|
|
|
If you want to try to generate the lock file without accessing the network, \
|
|
|
|
remove the --locked flag and use --offline instead.
|
|
|
|
")
|
|
|
|
.run();
|
|
|
|
}
|