-use serde_json;
+//! Tests for directory sources.
+
use std::collections::HashMap;
-use std::fs::{self, File};
-use std::io::prelude::*;
+use std::fs;
use std::str;
-use crate::support::cargo_process;
-use crate::support::git;
-use crate::support::paths;
-use crate::support::registry::{cksum, Package};
-use crate::support::{basic_manifest, project, ProjectBuilder};
+use serde::Serialize;
+
+use cargo_test_support::cargo_process;
+use cargo_test_support::git;
+use cargo_test_support::paths;
+use cargo_test_support::registry::{cksum, Package};
+use cargo_test_support::{basic_manifest, project, t, ProjectBuilder};
fn setup() {
let root = paths::root();
t!(fs::create_dir(&root.join(".cargo")));
- t!(t!(File::create(root.join(".cargo/config"))).write_all(
- br#"
+ t!(fs::write(
+ root.join(".cargo/config"),
+ r#"
[source.crates-io]
replace-with = 'my-awesome-local-registry'
}
}
-#[test]
+#[cargo_test]
fn simple() {
setup();
.file(
"Cargo.toml",
r#"
- [package]
- name = "foo"
- version = "0.1.0"
- authors = []
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
- [dependencies]
- bar = "0.1.0"
- "#,
+ [dependencies]
+ bar = "0.1.0"
+ "#,
)
.file(
"src/lib.rs",
.run();
}
-#[test]
+#[cargo_test]
fn simple_install() {
setup();
.file(
"Cargo.toml",
r#"
- [package]
- name = "bar"
- version = "0.1.0"
- authors = []
+ [package]
+ name = "bar"
+ version = "0.1.0"
+ authors = []
- [dependencies]
- foo = "0.0.1"
- "#,
+ [dependencies]
+ foo = "0.0.1"
+ "#,
)
.file(
"src/main.rs",
cargo_process("install bar")
.with_stderr(
- " Installing bar v0.1.0
- Compiling foo v0.0.1
- Compiling bar v0.1.0
- Finished release [optimized] target(s) in [..]s
- Installing [..]bar[..]
-warning: be sure to add `[..]` to your PATH to be able to run the installed binaries
+ "\
+[INSTALLING] bar v0.1.0
+[COMPILING] foo v0.0.1
+[COMPILING] bar v0.1.0
+[FINISHED] release [optimized] target(s) in [..]s
+[INSTALLING] [..]bar[..]
+[INSTALLED] package `bar v0.1.0` (executable `bar[EXE]`)
+[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
",
)
.run();
}
-#[test]
+#[cargo_test]
fn simple_install_fail() {
setup();
.file(
"Cargo.toml",
r#"
- [package]
- name = "bar"
- version = "0.1.0"
- authors = []
+ [package]
+ name = "bar"
+ version = "0.1.0"
+ authors = []
- [dependencies]
- foo = "0.1.0"
- baz = "9.8.7"
- "#,
+ [dependencies]
+ foo = "0.1.0"
+ baz = "9.8.7"
+ "#,
)
.file(
"src/main.rs",
Caused by:
no matching package named `baz` found
-location searched: registry `https://github.com/rust-lang/crates.io-index`
-did you mean: bar, foo
-required by package `bar v0.1.0`
+ location searched: registry `https://github.com/rust-lang/crates.io-index`
+ perhaps you meant: bar or foo
+ required by package `bar v0.1.0`
",
)
.run();
}
-#[test]
+#[cargo_test]
fn install_without_feature_dep() {
setup();
.file(
"Cargo.toml",
r#"
- [package]
- name = "bar"
- version = "0.1.0"
- authors = []
+ [package]
+ name = "bar"
+ version = "0.1.0"
+ authors = []
- [dependencies]
- foo = "0.0.1"
- baz = { version = "9.8.7", optional = true }
+ [dependencies]
+ foo = "0.0.1"
+ baz = { version = "9.8.7", optional = true }
- [features]
- wantbaz = ["baz"]
- "#,
+ [features]
+ wantbaz = ["baz"]
+ "#,
)
.file(
"src/main.rs",
cargo_process("install bar")
.with_stderr(
- " Installing bar v0.1.0
- Compiling foo v0.0.1
- Compiling bar v0.1.0
- Finished release [optimized] target(s) in [..]s
- Installing [..]bar[..]
-warning: be sure to add `[..]` to your PATH to be able to run the installed binaries
+ "\
+[INSTALLING] bar v0.1.0
+[COMPILING] foo v0.0.1
+[COMPILING] bar v0.1.0
+[FINISHED] release [optimized] target(s) in [..]s
+[INSTALLING] [..]bar[..]
+[INSTALLED] package `bar v0.1.0` (executable `bar[EXE]`)
+[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
",
)
.run();
}
-#[test]
+#[cargo_test]
fn not_there() {
setup();
.file(
"Cargo.toml",
r#"
- [package]
- name = "foo"
- version = "0.1.0"
- authors = []
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
- [dependencies]
- bar = "0.1.0"
- "#,
+ [dependencies]
+ bar = "0.1.0"
+ "#,
)
.file(
"src/lib.rs",
.run();
}
-#[test]
+#[cargo_test]
fn multiple() {
setup();
.file(
"Cargo.toml",
r#"
- [package]
- name = "foo"
- version = "0.1.0"
- authors = []
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
- [dependencies]
- bar = "0.1.0"
- "#,
+ [dependencies]
+ bar = "0.1.0"
+ "#,
)
.file(
"src/lib.rs",
.run();
}
-#[test]
+#[cargo_test]
fn crates_io_then_directory() {
let p = project()
.file(
"Cargo.toml",
r#"
- [package]
- name = "foo"
- version = "0.1.0"
- authors = []
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
- [dependencies]
- bar = "0.1.0"
- "#,
+ [dependencies]
+ bar = "0.1.0"
+ "#,
)
.file(
"src/lib.rs",
.run();
}
-#[test]
+#[cargo_test]
fn crates_io_then_bad_checksum() {
let p = project()
.file(
"Cargo.toml",
r#"
- [package]
- name = "foo"
- version = "0.1.0"
- authors = []
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
- [dependencies]
- bar = "0.1.0"
- "#,
+ [dependencies]
+ bar = "0.1.0"
+ "#,
)
.file("src/lib.rs", "")
.build();
this could be indicative of a few possible errors:
* the lock file is corrupt
- * a replacement source in use (e.g. a mirror) returned a different checksum
+ * a replacement source in use (e.g., a mirror) returned a different checksum
* the source itself may be corrupt in one way or another
unable to verify that `bar v0.1.0` is the same as when the lockfile was generated
.run();
}
-#[test]
+#[cargo_test]
fn bad_file_checksum() {
setup();
.file("src/lib.rs", "")
.build();
- let mut f = t!(File::create(paths::root().join("index/bar/src/lib.rs")));
- t!(f.write_all(b"fn bar() -> u32 { 0 }"));
+ t!(fs::write(
+ paths::root().join("index/bar/src/lib.rs"),
+ "fn bar() -> u32 { 0 }"
+ ));
let p = project()
.file(
"Cargo.toml",
r#"
- [package]
- name = "foo"
- version = "0.1.0"
- authors = []
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
- [dependencies]
- bar = "0.1.0"
- "#,
+ [dependencies]
+ bar = "0.1.0"
+ "#,
)
.file("src/lib.rs", "")
.build();
.run();
}
-#[test]
+#[cargo_test]
fn only_dot_files_ok() {
setup();
.file(
"Cargo.toml",
r#"
- [package]
- name = "foo"
- version = "0.1.0"
- authors = []
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
- [dependencies]
- bar = "0.1.0"
- "#,
+ [dependencies]
+ bar = "0.1.0"
+ "#,
)
.file("src/lib.rs", "")
.build();
p.cargo("build").run();
}
-#[test]
+#[cargo_test]
fn random_files_ok() {
setup();
.file(
"Cargo.toml",
r#"
- [package]
- name = "foo"
- version = "0.1.0"
- authors = []
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
- [dependencies]
- bar = "0.1.0"
- "#,
+ [dependencies]
+ bar = "0.1.0"
+ "#,
)
.file("src/lib.rs", "")
.build();
p.cargo("build").run();
}
-#[test]
+#[cargo_test]
fn git_lock_file_doesnt_change() {
let git = git::new("git", |p| {
p.file("Cargo.toml", &basic_manifest("git", "0.5.0"))
.file("src/lib.rs", "")
- })
- .unwrap();
+ });
VendorPackage::new("git")
.file("Cargo.toml", &basic_manifest("git", "0.5.0"))
"Cargo.toml",
&format!(
r#"
- [package]
- name = "foo"
- version = "0.0.1"
- authors = []
-
- [dependencies]
- git = {{ git = '{0}' }}
- "#,
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [dependencies]
+ git = {{ git = '{0}' }}
+ "#,
git.url()
),
)
p.cargo("build").run();
- let mut lock1 = String::new();
- t!(t!(File::open(p.root().join("Cargo.lock"))).read_to_string(&mut lock1));
+ let lock1 = p.read_lockfile();
let root = paths::root();
t!(fs::create_dir(&root.join(".cargo")));
- t!(t!(File::create(root.join(".cargo/config"))).write_all(
- &format!(
+ t!(fs::write(
+ root.join(".cargo/config"),
+ format!(
r#"
- [source.my-git-repo]
- git = '{}'
- replace-with = 'my-awesome-local-registry'
+ [source.my-git-repo]
+ git = '{}'
+ replace-with = 'my-awesome-local-registry'
- [source.my-awesome-local-registry]
- directory = 'index'
- "#,
+ [source.my-awesome-local-registry]
+ directory = 'index'
+ "#,
git.url()
)
- .as_bytes()
));
p.cargo("build")
)
.run();
- let mut lock2 = String::new();
- t!(t!(File::open(p.root().join("Cargo.lock"))).read_to_string(&mut lock2));
+ let lock2 = p.read_lockfile();
assert_eq!(lock1, lock2, "lock files changed");
}
-#[test]
+#[cargo_test]
fn git_override_requires_lockfile() {
VendorPackage::new("git")
.file("Cargo.toml", &basic_manifest("git", "0.5.0"))
.file(
"Cargo.toml",
r#"
- [package]
- name = "foo"
- version = "0.0.1"
- authors = []
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
- [dependencies]
- git = { git = 'https://example.com/' }
- "#,
+ [dependencies]
+ git = { git = 'https://example.com/' }
+ "#,
)
.file("src/lib.rs", "")
.build();
let root = paths::root();
t!(fs::create_dir(&root.join(".cargo")));
- t!(t!(File::create(root.join(".cargo/config"))).write_all(
- br#"
- [source.my-git-repo]
- git = 'https://example.com/'
- replace-with = 'my-awesome-local-registry'
-
- [source.my-awesome-local-registry]
- directory = 'index'
- "#
+ t!(fs::write(
+ root.join(".cargo/config"),
+ r#"
+ [source.my-git-repo]
+ git = 'https://example.com/'
+ replace-with = 'my-awesome-local-registry'
+
+ [source.my-awesome-local-registry]
+ directory = 'index'
+ "#
));
p.cargo("build")
.with_status(101)
.with_stderr(
"\
-error: failed to load source for a dependency on `git`
+[ERROR] failed to get `git` as a dependency of package `foo v0.0.1 ([..])`
+
+Caused by:
+ failed to load source for dependency `git`
Caused by:
Unable to update [..]
Caused by:
the source my-git-repo requires a lock file to be present first before it can be
-used against vendored source code
-
-remove the source replacement configuration, generate a lock file, and then
-restore the source replacement configuration to continue the build
+ used against vendored source code
+ remove the source replacement configuration, generate a lock file, and then
+ restore the source replacement configuration to continue the build
",
)
.run();
}
-#[test]
+#[cargo_test]
fn workspace_different_locations() {
let p = project()
.no_manifest()
)
.build();
- p.cargo("build").cwd(p.root().join("foo")).run();
+ p.cargo("build").cwd("foo").run();
p.cargo("build")
- .cwd(p.root().join("bar"))
- .with_status(0)
+ .cwd("bar")
.with_stderr(
"\
[COMPILING] bar [..]
.run();
}
-#[test]
+#[cargo_test]
fn version_missing() {
setup();
failed to select a version for the requirement `foo = \"^2\"`
candidate versions found which didn't match: 0.0.1
location searched: directory source `[..] (which is replacing registry `[..]`)
-required by package `bar v0.1.0`
-perhaps a crate was updated and forgotten to be re-vendored?
+ required by package `bar v0.1.0`
+ perhaps a crate was updated and forgotten to be re-vendored?
",
)
.with_status(101)