2016-05-26 00:06:25 +00:00
|
|
|
extern crate cargo;
|
|
|
|
extern crate cargotest;
|
|
|
|
extern crate git2;
|
|
|
|
extern crate hamcrest;
|
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io::prelude::*;
|
2017-12-19 15:34:14 +00:00
|
|
|
use std::net::TcpListener;
|
2015-02-27 01:04:25 +00:00
|
|
|
use std::path::Path;
|
2017-12-19 15:34:14 +00:00
|
|
|
use std::thread;
|
2014-06-19 07:55:17 +00:00
|
|
|
|
2015-06-01 21:38:30 +00:00
|
|
|
use cargo::util::process;
|
2017-03-17 13:52:31 +00:00
|
|
|
use cargotest::sleep_ms;
|
2016-05-26 00:06:25 +00:00
|
|
|
use cargotest::support::paths::{self, CargoPathExt};
|
|
|
|
use cargotest::support::{git, project, execs, main_file, path2url};
|
|
|
|
use hamcrest::{assert_that,existing_file};
|
2014-08-15 22:12:14 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_simple_git_dep() {
|
2014-06-12 22:51:16 +00:00
|
|
|
let project = project("foo");
|
2015-06-01 21:38:30 +00:00
|
|
|
let git_project = git::new("dep1", |project| {
|
2014-06-12 22:51:16 +00:00
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-06-12 22:51:16 +00:00
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
"#)
|
|
|
|
.file("src/dep1.rs", r#"
|
|
|
|
pub fn hello() -> &'static str {
|
|
|
|
"hello world"
|
|
|
|
}
|
|
|
|
"#)
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-06-12 22:51:16 +00:00
|
|
|
|
|
|
|
let project = project
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-06-12 22:51:16 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
|
2014-08-06 16:21:10 +00:00
|
|
|
git = '{}'
|
|
|
|
"#, git_project.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", &main_file(r#""{}", dep1::hello()"#, &["dep1"]))
|
|
|
|
.build();
|
2014-06-12 22:51:16 +00:00
|
|
|
|
|
|
|
let root = project.root();
|
|
|
|
let git_root = git_project.root();
|
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(project.cargo("build"),
|
2014-06-12 22:51:16 +00:00
|
|
|
execs()
|
2016-05-20 01:07:54 +00:00
|
|
|
.with_stderr(&format!("[UPDATING] git repository `{}`\n\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] dep1 v0.5.0 ({}#[..])\n\
|
2016-07-25 23:30:03 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({})\n\
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
|
2016-05-11 16:55:43 +00:00
|
|
|
path2url(git_root.clone()),
|
|
|
|
path2url(git_root),
|
2016-05-20 13:39:58 +00:00
|
|
|
path2url(root))));
|
2014-06-12 22:51:16 +00:00
|
|
|
|
2014-06-25 05:06:11 +00:00
|
|
|
assert_that(&project.bin("foo"), existing_file());
|
2014-06-12 22:51:16 +00:00
|
|
|
|
|
|
|
assert_that(
|
2015-10-28 09:20:00 +00:00
|
|
|
process(&project.bin("foo")),
|
2014-06-12 22:51:16 +00:00
|
|
|
execs().with_stdout("hello world\n"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-06-18 00:40:22 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_git_dep_branch() {
|
2014-06-24 22:23:03 +00:00
|
|
|
let project = project("foo");
|
2015-06-01 21:38:30 +00:00
|
|
|
let git_project = git::new("dep1", |project| {
|
2014-06-24 22:23:03 +00:00
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-06-24 22:23:03 +00:00
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
"#)
|
|
|
|
.file("src/dep1.rs", r#"
|
|
|
|
pub fn hello() -> &'static str {
|
|
|
|
"hello world"
|
|
|
|
}
|
|
|
|
"#)
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-06-24 22:23:03 +00:00
|
|
|
|
2014-09-12 15:02:14 +00:00
|
|
|
// Make a new branch based on the current HEAD commit
|
|
|
|
let repo = git2::Repository::open(&git_project.root()).unwrap();
|
|
|
|
let head = repo.head().unwrap().target().unwrap();
|
|
|
|
let head = repo.find_commit(head).unwrap();
|
2015-03-16 13:27:58 +00:00
|
|
|
repo.branch("branchy", &head, true).unwrap();
|
2014-06-24 22:23:03 +00:00
|
|
|
|
|
|
|
let project = project
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-06-24 22:23:03 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
|
2014-08-06 16:21:10 +00:00
|
|
|
git = '{}'
|
2014-06-24 22:23:03 +00:00
|
|
|
branch = "branchy"
|
|
|
|
|
2014-08-06 16:21:10 +00:00
|
|
|
"#, git_project.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", &main_file(r#""{}", dep1::hello()"#, &["dep1"]))
|
|
|
|
.build();
|
2014-06-24 22:23:03 +00:00
|
|
|
|
|
|
|
let root = project.root();
|
|
|
|
let git_root = git_project.root();
|
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(project.cargo("build"),
|
2014-06-24 22:23:03 +00:00
|
|
|
execs()
|
2016-05-20 01:07:54 +00:00
|
|
|
.with_stderr(&format!("[UPDATING] git repository `{}`\n\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] dep1 v0.5.0 ({}?branch=branchy#[..])\n\
|
2016-07-25 23:30:03 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({})\n\
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
|
2016-05-11 16:55:43 +00:00
|
|
|
path2url(git_root.clone()),
|
|
|
|
path2url(git_root),
|
2016-05-20 13:39:58 +00:00
|
|
|
path2url(root))));
|
2014-06-24 22:23:03 +00:00
|
|
|
|
2014-06-25 05:06:11 +00:00
|
|
|
assert_that(&project.bin("foo"), existing_file());
|
2014-06-24 22:23:03 +00:00
|
|
|
|
|
|
|
assert_that(
|
2015-10-28 09:20:00 +00:00
|
|
|
process(&project.bin("foo")),
|
2014-06-24 22:23:03 +00:00
|
|
|
execs().with_stdout("hello world\n"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-06-24 22:23:03 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_git_dep_tag() {
|
2014-06-24 22:23:03 +00:00
|
|
|
let project = project("foo");
|
2015-06-01 21:38:30 +00:00
|
|
|
let git_project = git::new("dep1", |project| {
|
2014-06-24 22:23:03 +00:00
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-06-24 22:23:03 +00:00
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
"#)
|
|
|
|
.file("src/dep1.rs", r#"
|
|
|
|
pub fn hello() -> &'static str {
|
|
|
|
"hello world"
|
|
|
|
}
|
|
|
|
"#)
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-06-24 22:23:03 +00:00
|
|
|
|
2015-05-06 00:05:41 +00:00
|
|
|
// Make a tag corresponding to the current HEAD
|
2014-09-12 15:02:14 +00:00
|
|
|
let repo = git2::Repository::open(&git_project.root()).unwrap();
|
|
|
|
let head = repo.head().unwrap().target().unwrap();
|
|
|
|
repo.tag("v0.1.0",
|
|
|
|
&repo.find_object(head, None).unwrap(),
|
|
|
|
&repo.signature().unwrap(),
|
|
|
|
"make a new tag",
|
|
|
|
false).unwrap();
|
2014-06-24 22:23:03 +00:00
|
|
|
|
|
|
|
let project = project
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-06-24 22:23:03 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
|
2014-08-06 16:21:10 +00:00
|
|
|
git = '{}'
|
2014-06-24 22:23:03 +00:00
|
|
|
tag = "v0.1.0"
|
2014-08-06 16:21:10 +00:00
|
|
|
"#, git_project.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", &main_file(r#""{}", dep1::hello()"#, &["dep1"]))
|
|
|
|
.build();
|
2014-06-24 22:23:03 +00:00
|
|
|
|
|
|
|
let root = project.root();
|
|
|
|
let git_root = git_project.root();
|
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(project.cargo("build"),
|
2014-06-24 22:23:03 +00:00
|
|
|
execs()
|
2016-05-20 01:07:54 +00:00
|
|
|
.with_stderr(&format!("[UPDATING] git repository `{}`\n\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] dep1 v0.5.0 ({}?tag=v0.1.0#[..])\n\
|
2016-07-25 23:30:03 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({})\n\
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
|
2016-05-11 16:55:43 +00:00
|
|
|
path2url(git_root.clone()),
|
|
|
|
path2url(git_root),
|
|
|
|
path2url(root))));
|
2014-06-24 22:23:03 +00:00
|
|
|
|
2014-06-25 05:06:11 +00:00
|
|
|
assert_that(&project.bin("foo"), existing_file());
|
2014-06-24 22:23:03 +00:00
|
|
|
|
2015-10-28 09:20:00 +00:00
|
|
|
assert_that(process(&project.bin("foo")),
|
2014-12-08 18:46:07 +00:00
|
|
|
execs().with_stdout("hello world\n"));
|
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(project.cargo("build"),
|
2014-12-08 18:46:07 +00:00
|
|
|
execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-01 01:36:27 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_nested_paths() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let git_project = git::new("dep1", |project| {
|
2014-06-18 00:40:22 +00:00
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep2]
|
|
|
|
|
|
|
|
version = "0.5.0"
|
|
|
|
path = "vendor/dep2"
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-06-18 00:40:22 +00:00
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
"#)
|
|
|
|
.file("src/dep1.rs", r#"
|
|
|
|
extern crate dep2;
|
|
|
|
|
|
|
|
pub fn hello() -> &'static str {
|
|
|
|
dep2::hello()
|
|
|
|
}
|
|
|
|
"#)
|
|
|
|
.file("vendor/dep2/Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "dep2"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-06-18 00:40:22 +00:00
|
|
|
|
|
|
|
name = "dep2"
|
|
|
|
"#)
|
|
|
|
.file("vendor/dep2/src/dep2.rs", r#"
|
|
|
|
pub fn hello() -> &'static str {
|
|
|
|
"hello world"
|
|
|
|
}
|
|
|
|
"#)
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-06-18 00:40:22 +00:00
|
|
|
|
|
|
|
let p = project("parent")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-06-18 00:40:22 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "parent"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
|
|
|
|
version = "0.5.0"
|
2014-08-06 16:21:10 +00:00
|
|
|
git = '{}'
|
2014-06-18 00:40:22 +00:00
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
|
|
|
|
name = "parent"
|
2014-08-06 16:21:10 +00:00
|
|
|
"#, git_project.url()))
|
2014-06-19 23:45:19 +00:00
|
|
|
.file("src/parent.rs",
|
2017-07-22 03:12:21 +00:00
|
|
|
&main_file(r#""{}", dep1::hello()"#, &["dep1"]))
|
|
|
|
.build();
|
2014-06-18 00:40:22 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
p.cargo("build")
|
2014-06-18 00:40:22 +00:00
|
|
|
.exec_with_output()
|
2014-12-21 23:19:44 +00:00
|
|
|
.unwrap();
|
2014-06-18 00:40:22 +00:00
|
|
|
|
2014-06-25 05:06:11 +00:00
|
|
|
assert_that(&p.bin("parent"), existing_file());
|
2014-06-18 00:40:22 +00:00
|
|
|
|
2017-05-06 12:44:41 +00:00
|
|
|
assert_that(process(&p.bin("parent")),
|
|
|
|
execs().with_stdout("hello world\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_malformed_nested_paths() {
|
|
|
|
let git_project = git::new("dep1", |project| {
|
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
"#)
|
|
|
|
.file("src/dep1.rs", r#"
|
|
|
|
pub fn hello() -> &'static str {
|
|
|
|
"hello world"
|
|
|
|
}
|
|
|
|
"#)
|
|
|
|
.file("vendor/dep2/Cargo.toml", r#"
|
|
|
|
!INVALID!
|
|
|
|
"#)
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
let p = project("parent")
|
|
|
|
.file("Cargo.toml", &format!(r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "parent"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
|
|
|
|
version = "0.5.0"
|
|
|
|
git = '{}'
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
|
|
|
|
name = "parent"
|
|
|
|
"#, git_project.url()))
|
|
|
|
.file("src/parent.rs",
|
2017-07-22 03:12:21 +00:00
|
|
|
&main_file(r#""{}", dep1::hello()"#, &["dep1"]))
|
|
|
|
.build();
|
2017-05-06 12:44:41 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
p.cargo("build")
|
2017-05-06 12:44:41 +00:00
|
|
|
.exec_with_output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_that(&p.bin("parent"), existing_file());
|
|
|
|
|
2015-10-28 09:20:00 +00:00
|
|
|
assert_that(process(&p.bin("parent")),
|
2015-02-27 01:04:25 +00:00
|
|
|
execs().with_stdout("hello world\n"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-06-20 01:53:18 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_meta_package() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let git_project = git::new("meta-dep", |project| {
|
2014-07-01 01:36:27 +00:00
|
|
|
project
|
|
|
|
.file("dep1/Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-07-01 01:36:27 +00:00
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
"#)
|
|
|
|
.file("dep1/src/dep1.rs", r#"
|
|
|
|
pub fn hello() -> &'static str {
|
|
|
|
"this is dep1"
|
|
|
|
}
|
|
|
|
"#)
|
|
|
|
.file("dep2/Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "dep2"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-07-01 01:36:27 +00:00
|
|
|
|
|
|
|
name = "dep2"
|
|
|
|
"#)
|
|
|
|
.file("dep2/src/dep2.rs", r#"
|
|
|
|
pub fn hello() -> &'static str {
|
|
|
|
"this is dep2"
|
|
|
|
}
|
|
|
|
"#)
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-07-01 01:36:27 +00:00
|
|
|
|
|
|
|
let p = project("parent")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-07-01 01:36:27 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "parent"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
|
|
|
|
version = "0.5.0"
|
2014-08-06 16:21:10 +00:00
|
|
|
git = '{}'
|
2014-07-01 01:36:27 +00:00
|
|
|
|
|
|
|
[dependencies.dep2]
|
|
|
|
|
|
|
|
version = "0.5.0"
|
2014-08-06 16:21:10 +00:00
|
|
|
git = '{}'
|
2014-07-01 01:36:27 +00:00
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
|
|
|
|
name = "parent"
|
2014-08-06 16:21:10 +00:00
|
|
|
"#, git_project.url(), git_project.url()))
|
2014-07-01 01:36:27 +00:00
|
|
|
.file("src/parent.rs",
|
2017-07-22 03:12:21 +00:00
|
|
|
&main_file(r#""{} {}", dep1::hello(), dep2::hello()"#, &["dep1", "dep2"]))
|
|
|
|
.build();
|
2014-07-01 01:36:27 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
p.cargo("build")
|
2014-07-01 01:36:27 +00:00
|
|
|
.exec_with_output()
|
2014-12-21 23:19:44 +00:00
|
|
|
.unwrap();
|
2014-07-01 01:36:27 +00:00
|
|
|
|
|
|
|
assert_that(&p.bin("parent"), existing_file());
|
|
|
|
|
2015-10-28 09:20:00 +00:00
|
|
|
assert_that(process(&p.bin("parent")),
|
2015-02-27 01:04:25 +00:00
|
|
|
execs().with_stdout("this is dep1 this is dep2\n"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-01 01:36:27 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_compile_with_short_ssh_git() {
|
2014-06-27 03:51:25 +00:00
|
|
|
let url = "git@github.com:a/dep";
|
|
|
|
|
|
|
|
let project = project("project")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-06-27 03:51:25 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep]
|
|
|
|
|
|
|
|
git = "{}"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
"#, url))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""{}", dep1::hello()"#, &["dep1"]))
|
|
|
|
.build();
|
2014-06-27 03:51:25 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(project.cargo("build"),
|
2014-06-27 03:51:25 +00:00
|
|
|
execs()
|
|
|
|
.with_stdout("")
|
2015-03-26 18:17:44 +00:00
|
|
|
.with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
2015-01-14 02:43:33 +00:00
|
|
|
|
2015-01-16 17:43:28 +00:00
|
|
|
Caused by:
|
|
|
|
invalid url `{}`: relative URL without a base
|
2016-05-11 16:55:43 +00:00
|
|
|
", url)));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-06-27 03:51:25 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn two_revs_same_deps() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let bar = git::new("meta-dep", |project| {
|
2014-07-11 20:32:27 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
2015-02-13 04:10:07 +00:00
|
|
|
.file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-07-11 20:32:27 +00:00
|
|
|
|
2014-09-12 15:02:14 +00:00
|
|
|
let repo = git2::Repository::open(&bar.root()).unwrap();
|
2014-09-17 15:27:41 +00:00
|
|
|
let rev1 = repo.revparse_single("HEAD").unwrap().id();
|
2014-09-12 15:02:14 +00:00
|
|
|
|
2014-07-11 20:32:27 +00:00
|
|
|
// Commit the changes and make sure we trigger a recompile
|
2015-02-27 01:04:25 +00:00
|
|
|
File::create(&bar.root().join("src/lib.rs")).unwrap().write_all(br#"
|
2015-02-13 04:10:07 +00:00
|
|
|
pub fn bar() -> i32 { 2 }
|
2014-12-21 23:19:44 +00:00
|
|
|
"#).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
git::add(&repo);
|
|
|
|
let rev2 = git::commit(&repo);
|
2014-07-11 20:32:27 +00:00
|
|
|
|
|
|
|
let foo = project("foo")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-07-11 20:32:27 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
2014-08-06 16:21:10 +00:00
|
|
|
git = '{}'
|
2014-07-11 20:32:27 +00:00
|
|
|
rev = "{}"
|
|
|
|
|
|
|
|
[dependencies.baz]
|
|
|
|
path = "../baz"
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, bar.url(), rev1))
|
2014-07-11 20:32:27 +00:00
|
|
|
.file("src/main.rs", r#"
|
|
|
|
extern crate bar;
|
|
|
|
extern crate baz;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
assert_eq!(bar::bar(), 1);
|
|
|
|
assert_eq!(baz::baz(), 2);
|
|
|
|
}
|
2017-07-22 03:12:21 +00:00
|
|
|
"#)
|
|
|
|
.build();
|
2014-07-11 20:32:27 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let _baz = project("baz")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-07-11 20:32:27 +00:00
|
|
|
[package]
|
|
|
|
name = "baz"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
2014-08-06 16:21:10 +00:00
|
|
|
git = '{}'
|
2014-07-11 20:32:27 +00:00
|
|
|
rev = "{}"
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, bar.url(), rev2))
|
2014-07-11 20:32:27 +00:00
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
extern crate bar;
|
2015-02-13 04:10:07 +00:00
|
|
|
pub fn baz() -> i32 { bar::bar() }
|
2017-07-22 03:12:21 +00:00
|
|
|
"#)
|
|
|
|
.build();
|
2014-07-11 20:32:27 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(foo.cargo("build").arg("-v"),
|
2014-07-11 20:32:27 +00:00
|
|
|
execs().with_status(0));
|
2014-07-17 01:44:30 +00:00
|
|
|
assert_that(&foo.bin("foo"), existing_file());
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(foo.process(&foo.bin("foo")), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-11 20:32:27 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn recompilation() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let git_project = git::new("bar", |project| {
|
2014-06-20 01:53:18 +00:00
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-06-23 15:39:50 +00:00
|
|
|
name = "bar"
|
2014-06-20 01:53:18 +00:00
|
|
|
"#)
|
|
|
|
.file("src/bar.rs", r#"
|
|
|
|
pub fn bar() {}
|
|
|
|
"#)
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-06-20 01:53:18 +00:00
|
|
|
|
|
|
|
let p = project("foo")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-06-20 01:53:18 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
|
|
|
|
version = "0.5.0"
|
2014-08-06 16:21:10 +00:00
|
|
|
git = '{}'
|
|
|
|
"#, git_project.url()))
|
2017-07-09 12:57:25 +00:00
|
|
|
.file("src/main.rs",
|
2017-07-22 03:12:21 +00:00
|
|
|
&main_file(r#""{:?}", bar::bar()"#, &["bar"]))
|
|
|
|
.build();
|
2014-06-20 01:53:18 +00:00
|
|
|
|
|
|
|
// First time around we should compile both foo and bar
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2016-05-20 01:07:54 +00:00
|
|
|
execs().with_stderr(&format!("[UPDATING] git repository `{}`\n\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] bar v0.5.0 ({}#[..])\n\
|
2016-07-25 23:30:03 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({})\n\
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) \
|
2016-07-25 23:30:03 +00:00
|
|
|
in [..]\n",
|
2016-05-11 16:55:43 +00:00
|
|
|
git_project.url(),
|
|
|
|
git_project.url(),
|
|
|
|
p.url())));
|
2014-06-24 01:54:13 +00:00
|
|
|
|
2014-06-20 01:53:18 +00:00
|
|
|
// Don't recompile the second time
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2014-09-05 17:15:10 +00:00
|
|
|
execs().with_stdout(""));
|
2014-06-24 01:54:13 +00:00
|
|
|
|
2014-06-20 01:53:18 +00:00
|
|
|
// Modify a file manually, shouldn't trigger a recompile
|
2015-02-27 01:04:25 +00:00
|
|
|
File::create(&git_project.root().join("src/bar.rs")).unwrap().write_all(br#"
|
2014-06-20 01:53:18 +00:00
|
|
|
pub fn bar() { println!("hello!"); }
|
2014-12-21 23:19:44 +00:00
|
|
|
"#).unwrap();
|
2014-06-24 01:54:13 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2014-09-05 17:15:10 +00:00
|
|
|
execs().with_stdout(""));
|
2014-06-24 01:54:13 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("update"),
|
2016-05-20 01:07:54 +00:00
|
|
|
execs().with_stderr(&format!("[UPDATING] git repository `{}`",
|
2014-08-06 16:21:10 +00:00
|
|
|
git_project.url())));
|
2014-07-31 22:19:20 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2014-09-05 17:15:10 +00:00
|
|
|
execs().with_stdout(""));
|
2014-06-24 01:54:13 +00:00
|
|
|
|
2014-07-31 19:18:09 +00:00
|
|
|
// Commit the changes and make sure we don't trigger a recompile because the
|
|
|
|
// lockfile says not to change
|
2014-09-12 15:02:14 +00:00
|
|
|
let repo = git2::Repository::open(&git_project.root()).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
git::add(&repo);
|
|
|
|
git::commit(&repo);
|
2014-06-24 01:54:13 +00:00
|
|
|
|
2014-07-31 22:19:20 +00:00
|
|
|
println!("compile after commit");
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2014-09-05 17:15:10 +00:00
|
|
|
execs().with_stdout(""));
|
2016-05-26 00:06:25 +00:00
|
|
|
p.root().move_into_the_past();
|
2014-07-31 19:18:09 +00:00
|
|
|
|
2014-07-31 22:19:20 +00:00
|
|
|
// Update the dependency and carry on!
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("update"),
|
2016-05-20 01:07:54 +00:00
|
|
|
execs().with_stderr(&format!("[UPDATING] git repository `{}`\n\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] bar v0.5.0 ([..]) -> #[..]\n\
|
2015-05-17 16:45:55 +00:00
|
|
|
",
|
2016-05-11 16:55:43 +00:00
|
|
|
git_project.url())));
|
2014-07-31 22:19:20 +00:00
|
|
|
println!("going for the last compile");
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2016-05-20 01:07:54 +00:00
|
|
|
execs().with_stderr(&format!("[COMPILING] bar v0.5.0 ({}#[..])\n\
|
2016-07-25 23:30:03 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({})\n\
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) \
|
2016-07-25 23:30:03 +00:00
|
|
|
in [..]\n",
|
2016-05-11 16:55:43 +00:00
|
|
|
git_project.url(),
|
|
|
|
p.url())));
|
2014-09-23 16:03:34 +00:00
|
|
|
|
|
|
|
// Make sure clean only cleans one dep
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("clean")
|
2014-09-24 01:10:27 +00:00
|
|
|
.arg("-p").arg("foo"),
|
2014-09-23 16:03:34 +00:00
|
|
|
execs().with_stdout(""));
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2016-07-25 23:30:03 +00:00
|
|
|
execs().with_stderr(&format!("[COMPILING] foo v0.5.0 ({})\n\
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) \
|
2016-07-25 23:30:03 +00:00
|
|
|
in [..]\n",
|
2016-05-11 16:55:43 +00:00
|
|
|
p.url())));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-01 17:39:11 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn update_with_shared_deps() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let git_project = git::new("bar", |project| {
|
2014-08-01 17:39:11 +00:00
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-08-01 17:39:11 +00:00
|
|
|
name = "bar"
|
|
|
|
"#)
|
|
|
|
.file("src/bar.rs", r#"
|
|
|
|
pub fn bar() {}
|
|
|
|
"#)
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-08-01 17:39:11 +00:00
|
|
|
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
path = "dep1"
|
|
|
|
[dependencies.dep2]
|
|
|
|
path = "dep2"
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
2017-08-27 07:31:16 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
2014-08-01 17:39:11 +00:00
|
|
|
extern crate dep1;
|
2017-08-27 07:31:16 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
2014-08-01 17:39:11 +00:00
|
|
|
extern crate dep2;
|
|
|
|
fn main() {}
|
|
|
|
"#)
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("dep1/Cargo.toml", &format!(r#"
|
2014-08-01 17:39:11 +00:00
|
|
|
[package]
|
|
|
|
name = "dep1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
version = "0.5.0"
|
2014-08-06 16:21:10 +00:00
|
|
|
git = '{}'
|
|
|
|
"#, git_project.url()))
|
2014-08-01 17:39:11 +00:00
|
|
|
.file("dep1/src/lib.rs", "")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("dep2/Cargo.toml", &format!(r#"
|
2014-08-01 17:39:11 +00:00
|
|
|
[package]
|
|
|
|
name = "dep2"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
version = "0.5.0"
|
2014-08-06 16:21:10 +00:00
|
|
|
git = '{}'
|
|
|
|
"#, git_project.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("dep2/src/lib.rs", "")
|
|
|
|
.build();
|
2014-08-01 17:39:11 +00:00
|
|
|
|
|
|
|
// First time around we should compile both foo and bar
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2016-05-19 00:51:07 +00:00
|
|
|
execs().with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `{git}`
|
|
|
|
[COMPILING] bar v0.5.0 ({git}#[..])
|
|
|
|
[COMPILING] [..] v0.5.0 ([..])
|
|
|
|
[COMPILING] [..] v0.5.0 ([..])
|
2016-07-25 23:30:03 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
|
2016-07-25 23:30:03 +00:00
|
|
|
git = git_project.url(), dir = p.url())));
|
2014-08-01 17:39:11 +00:00
|
|
|
|
|
|
|
// Modify a file manually, and commit it
|
2015-02-27 01:04:25 +00:00
|
|
|
File::create(&git_project.root().join("src/bar.rs")).unwrap().write_all(br#"
|
2014-08-01 17:39:11 +00:00
|
|
|
pub fn bar() { println!("hello!"); }
|
2014-12-21 23:19:44 +00:00
|
|
|
"#).unwrap();
|
2014-09-12 15:02:14 +00:00
|
|
|
let repo = git2::Repository::open(&git_project.root()).unwrap();
|
2014-09-23 14:30:16 +00:00
|
|
|
let old_head = repo.head().unwrap().target().unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
git::add(&repo);
|
|
|
|
git::commit(&repo);
|
2014-08-15 00:05:01 +00:00
|
|
|
|
2016-05-26 00:06:25 +00:00
|
|
|
sleep_ms(1000);
|
2014-08-15 00:05:01 +00:00
|
|
|
|
2014-09-23 14:30:16 +00:00
|
|
|
// By default, not transitive updates
|
2014-10-23 19:12:03 +00:00
|
|
|
println!("dep1 update");
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("update")
|
2015-01-14 08:19:27 +00:00
|
|
|
.arg("-p").arg("dep1"),
|
2014-09-21 21:27:30 +00:00
|
|
|
execs().with_stdout(""));
|
2014-09-23 14:30:16 +00:00
|
|
|
|
2015-10-31 17:03:18 +00:00
|
|
|
// Don't do anything bad on a weird --precise argument
|
|
|
|
println!("bar bad precise update");
|
|
|
|
assert_that(p.cargo("update")
|
|
|
|
.arg("-p").arg("bar")
|
|
|
|
.arg("--precise").arg("0.1.2"),
|
2016-05-12 17:06:36 +00:00
|
|
|
execs().with_status(101).with_stderr("\
|
2016-05-20 13:39:58 +00:00
|
|
|
[UPDATING] git repository [..]
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] Unable to update [..]
|
2015-10-31 17:03:18 +00:00
|
|
|
|
|
|
|
To learn more, run the command again with --verbose.
|
2016-05-12 17:06:36 +00:00
|
|
|
"));
|
2015-10-31 17:03:18 +00:00
|
|
|
|
2014-09-23 14:30:16 +00:00
|
|
|
// Specifying a precise rev to the old rev shouldn't actually update
|
|
|
|
// anything because we already have the rev in the db.
|
2014-10-23 19:12:03 +00:00
|
|
|
println!("bar precise update");
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("update")
|
2015-01-14 08:19:27 +00:00
|
|
|
.arg("-p").arg("bar")
|
2015-02-27 01:04:25 +00:00
|
|
|
.arg("--precise").arg(&old_head.to_string()),
|
2014-09-23 14:30:16 +00:00
|
|
|
execs().with_stdout(""));
|
|
|
|
|
|
|
|
// Updating aggressively should, however, update the repo.
|
2014-10-23 19:12:03 +00:00
|
|
|
println!("dep1 aggressive update");
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("update")
|
2015-01-14 08:19:27 +00:00
|
|
|
.arg("-p").arg("dep1")
|
2014-09-21 21:27:30 +00:00
|
|
|
.arg("--aggressive"),
|
2016-05-20 01:07:54 +00:00
|
|
|
execs().with_stderr(&format!("[UPDATING] git repository `{}`\n\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] bar v0.5.0 ([..]) -> #[..]\n\
|
|
|
|
", git_project.url())));
|
2014-08-01 17:39:11 +00:00
|
|
|
|
|
|
|
// Make sure we still only compile one version of the git repo
|
2014-10-23 19:12:03 +00:00
|
|
|
println!("build");
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2016-05-19 00:51:07 +00:00
|
|
|
execs().with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] bar v0.5.0 ({git}#[..])
|
|
|
|
[COMPILING] [..] v0.5.0 ({dir}[..]dep[..])
|
|
|
|
[COMPILING] [..] v0.5.0 ({dir}[..]dep[..])
|
2016-07-25 23:30:03 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
|
2016-05-11 16:55:43 +00:00
|
|
|
git = git_project.url(), dir = p.url())));
|
2014-08-16 01:25:12 +00:00
|
|
|
|
|
|
|
// We should be able to update transitive deps
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("update").arg("-p").arg("bar"),
|
2016-05-20 01:07:54 +00:00
|
|
|
execs().with_stderr(&format!("[UPDATING] git repository `{}`",
|
2014-08-16 01:25:12 +00:00
|
|
|
git_project.url())));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-06 05:26:38 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dep_with_submodule() {
|
2014-08-06 05:26:38 +00:00
|
|
|
let project = project("foo");
|
2015-06-01 21:38:30 +00:00
|
|
|
let git_project = git::new("dep1", |project| {
|
2014-08-06 05:26:38 +00:00
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "dep1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
"#)
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
let git_project2 = git::new("dep2", |project| {
|
2015-02-27 01:04:25 +00:00
|
|
|
project.file("lib.rs", "pub fn dep() {}")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-08-06 05:26:38 +00:00
|
|
|
|
2014-09-12 15:02:14 +00:00
|
|
|
let repo = git2::Repository::open(&git_project.root()).unwrap();
|
|
|
|
let url = path2url(git_project2.root()).to_string();
|
2015-06-01 21:38:30 +00:00
|
|
|
git::add_submodule(&repo, &url, Path::new("src"));
|
|
|
|
git::commit(&repo);
|
2014-08-06 05:26:38 +00:00
|
|
|
|
|
|
|
let project = project
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-08-06 05:26:38 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
|
2014-08-06 16:21:10 +00:00
|
|
|
git = '{}'
|
|
|
|
"#, git_project.url()))
|
2014-08-06 05:26:38 +00:00
|
|
|
.file("src/lib.rs", "
|
|
|
|
extern crate dep1;
|
|
|
|
pub fn foo() { dep1::dep() }
|
2017-07-22 03:12:21 +00:00
|
|
|
")
|
|
|
|
.build();
|
2014-08-06 05:26:38 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(project.cargo("build"),
|
2016-05-20 13:39:58 +00:00
|
|
|
execs().with_stderr("\
|
|
|
|
[UPDATING] git repository [..]
|
|
|
|
[COMPILING] dep1 [..]
|
2016-07-25 23:30:03 +00:00
|
|
|
[COMPILING] foo [..]
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n").with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-06 20:54:24 +00:00
|
|
|
|
2017-04-14 03:58:02 +00:00
|
|
|
#[test]
|
|
|
|
fn dep_with_bad_submodule() {
|
|
|
|
let project = project("foo");
|
|
|
|
let git_project = git::new("dep1", |project| {
|
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "dep1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
"#)
|
|
|
|
}).unwrap();
|
|
|
|
let git_project2 = git::new("dep2", |project| {
|
|
|
|
project.file("lib.rs", "pub fn dep() {}")
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
let repo = git2::Repository::open(&git_project.root()).unwrap();
|
|
|
|
let url = path2url(git_project2.root()).to_string();
|
|
|
|
git::add_submodule(&repo, &url, Path::new("src"));
|
|
|
|
git::commit(&repo);
|
|
|
|
|
|
|
|
// now amend the first commit on git_project2 to make submodule ref point to not-found
|
|
|
|
// commit
|
|
|
|
let repo = git2::Repository::open(&git_project2.root()).unwrap();
|
|
|
|
let original_submodule_ref = repo.refname_to_id("refs/heads/master").unwrap();
|
|
|
|
let commit = repo.find_commit(original_submodule_ref).unwrap();
|
2017-04-14 07:55:26 +00:00
|
|
|
commit.amend(
|
|
|
|
Some("refs/heads/master"),
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
Some("something something"),
|
|
|
|
None).unwrap();
|
2017-04-14 03:58:02 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project
|
2017-04-14 03:58:02 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
|
|
|
|
git = '{}'
|
|
|
|
"#, git_project.url()))
|
|
|
|
.file("src/lib.rs", "
|
|
|
|
extern crate dep1;
|
|
|
|
pub fn foo() { dep1::dep() }
|
2017-07-22 03:12:21 +00:00
|
|
|
")
|
|
|
|
.build();
|
2017-04-14 03:58:02 +00:00
|
|
|
|
2017-04-14 07:55:26 +00:00
|
|
|
let expected = format!("\
|
2017-04-14 03:58:02 +00:00
|
|
|
[UPDATING] git repository [..]
|
|
|
|
[ERROR] failed to load source for a dependency on `dep1`
|
|
|
|
|
|
|
|
Caused by:
|
2017-04-14 05:38:55 +00:00
|
|
|
Unable to update {}
|
2017-04-14 03:58:02 +00:00
|
|
|
|
|
|
|
Caused by:
|
2017-04-17 12:08:51 +00:00
|
|
|
failed to update submodule `src`
|
2017-04-14 05:38:55 +00:00
|
|
|
|
2017-12-19 15:34:14 +00:00
|
|
|
Caused by:
|
|
|
|
object not found - no match for id [..]
|
|
|
|
", path2url(git_project.root()));
|
2017-04-14 07:55:26 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2017-04-14 07:55:26 +00:00
|
|
|
execs().with_stderr(expected).with_status(101));
|
2017-04-14 03:58:02 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn two_deps_only_update_one() {
|
2014-08-06 20:54:24 +00:00
|
|
|
let project = project("foo");
|
2015-06-01 21:38:30 +00:00
|
|
|
let git1 = git::new("dep1", |project| {
|
2014-08-06 20:54:24 +00:00
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "dep1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
let git2 = git::new("dep2", |project| {
|
2014-08-06 20:54:24 +00:00
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "dep2"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-08-06 20:54:24 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-08-06 20:54:24 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
git = '{}'
|
|
|
|
[dependencies.dep2]
|
|
|
|
git = '{}'
|
|
|
|
"#, git1.url(), git2.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2014-08-06 20:54:24 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2014-08-06 20:54:24 +00:00
|
|
|
execs()
|
2016-05-20 01:07:54 +00:00
|
|
|
.with_stderr(&format!("[UPDATING] git repository `[..]`\n\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `[..]`\n\
|
|
|
|
[COMPILING] [..] v0.5.0 ([..])\n\
|
|
|
|
[COMPILING] [..] v0.5.0 ([..])\n\
|
2016-07-25 23:30:03 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({})\n\
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
|
2017-07-22 03:12:21 +00:00
|
|
|
p.url())));
|
2014-08-06 20:54:24 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
File::create(&git1.root().join("src/lib.rs")).unwrap().write_all(br#"
|
2014-08-06 20:54:24 +00:00
|
|
|
pub fn foo() {}
|
2014-12-21 23:19:44 +00:00
|
|
|
"#).unwrap();
|
2014-09-12 15:02:14 +00:00
|
|
|
let repo = git2::Repository::open(&git1.root()).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
git::add(&repo);
|
|
|
|
git::commit(&repo);
|
2014-08-06 20:54:24 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("update")
|
2014-09-27 04:24:31 +00:00
|
|
|
.arg("-p").arg("dep1"),
|
2014-08-06 20:54:24 +00:00
|
|
|
execs()
|
2016-05-20 01:07:54 +00:00
|
|
|
.with_stderr(&format!("[UPDATING] git repository `{}`\n\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]\n\
|
2016-05-20 13:39:58 +00:00
|
|
|
", git1.url())));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-10 05:53:25 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn stale_cached_version() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let bar = git::new("meta-dep", |project| {
|
2014-08-10 05:53:25 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
2015-02-13 04:10:07 +00:00
|
|
|
.file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-08-10 05:53:25 +00:00
|
|
|
|
|
|
|
// Update the git database in the cache with the current state of the git
|
|
|
|
// repo
|
|
|
|
let foo = project("foo")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-08-10 05:53:25 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
git = '{}'
|
|
|
|
"#, bar.url()))
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
extern crate bar;
|
|
|
|
|
|
|
|
fn main() { assert_eq!(bar::bar(), 1) }
|
2017-07-22 03:12:21 +00:00
|
|
|
"#)
|
|
|
|
.build();
|
2014-08-10 05:53:25 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(foo.cargo("build"), execs().with_status(0));
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(foo.process(&foo.bin("foo")), execs().with_status(0));
|
2014-08-10 05:53:25 +00:00
|
|
|
|
|
|
|
// Update the repo, and simulate someone else updating the lockfile and then
|
|
|
|
// us pulling it down.
|
2015-02-27 01:04:25 +00:00
|
|
|
File::create(&bar.root().join("src/lib.rs")).unwrap().write_all(br#"
|
2015-02-13 04:10:07 +00:00
|
|
|
pub fn bar() -> i32 { 1 + 0 }
|
2014-12-21 23:19:44 +00:00
|
|
|
"#).unwrap();
|
2014-09-12 15:02:14 +00:00
|
|
|
let repo = git2::Repository::open(&bar.root()).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
git::add(&repo);
|
|
|
|
git::commit(&repo);
|
2014-08-15 00:05:01 +00:00
|
|
|
|
2016-05-26 00:06:25 +00:00
|
|
|
sleep_ms(1000);
|
2014-08-15 00:05:01 +00:00
|
|
|
|
2014-09-12 15:02:14 +00:00
|
|
|
let rev = repo.revparse_single("HEAD").unwrap().id();
|
2014-08-10 05:53:25 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
File::create(&foo.root().join("Cargo.lock")).unwrap().write_all(format!(r#"
|
2017-10-03 12:18:08 +00:00
|
|
|
[[package]]
|
2014-08-10 05:53:25 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
dependencies = [
|
|
|
|
'bar 0.0.0 (git+{url}#{hash})'
|
|
|
|
]
|
|
|
|
|
|
|
|
[[package]]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.0"
|
|
|
|
source = 'git+{url}#{hash}'
|
2015-02-27 01:04:25 +00:00
|
|
|
"#, url = bar.url(), hash = rev).as_bytes()).unwrap();
|
2014-08-10 05:53:25 +00:00
|
|
|
|
|
|
|
// Now build!
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(foo.cargo("build"),
|
2014-08-10 05:53:25 +00:00
|
|
|
execs().with_status(0)
|
2016-05-14 21:44:18 +00:00
|
|
|
.with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `{bar}`
|
|
|
|
[COMPILING] bar v0.0.0 ({bar}#[..])
|
|
|
|
[COMPILING] foo v0.0.0 ({foo})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-11 16:55:43 +00:00
|
|
|
", bar = bar.url(), foo = foo.url())));
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(foo.process(&foo.bin("foo")), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-16 18:20:47 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dep_with_changed_submodule() {
|
2014-08-16 18:20:47 +00:00
|
|
|
let project = project("foo");
|
2015-06-01 21:38:30 +00:00
|
|
|
let git_project = git::new("dep1", |project| {
|
2014-08-16 18:20:47 +00:00
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "dep1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
"#)
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-08-16 18:20:47 +00:00
|
|
|
|
2015-06-01 21:38:30 +00:00
|
|
|
let git_project2 = git::new("dep2", |project| {
|
2014-08-16 18:20:47 +00:00
|
|
|
project
|
|
|
|
.file("lib.rs", "pub fn dep() -> &'static str { \"project2\" }")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-08-16 18:20:47 +00:00
|
|
|
|
2015-06-01 21:38:30 +00:00
|
|
|
let git_project3 = git::new("dep3", |project| {
|
2014-08-16 18:20:47 +00:00
|
|
|
project
|
|
|
|
.file("lib.rs", "pub fn dep() -> &'static str { \"project3\" }")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-08-16 18:20:47 +00:00
|
|
|
|
2014-09-12 15:02:14 +00:00
|
|
|
let repo = git2::Repository::open(&git_project.root()).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
let mut sub = git::add_submodule(&repo, &git_project2.url().to_string(),
|
2017-02-18 12:01:10 +00:00
|
|
|
Path::new("src"));
|
2015-06-01 21:38:30 +00:00
|
|
|
git::commit(&repo);
|
2014-08-16 18:20:47 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-08-16 18:20:47 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
[dependencies.dep1]
|
|
|
|
git = '{}'
|
|
|
|
"#, git_project.url()))
|
|
|
|
.file("src/main.rs", "
|
|
|
|
extern crate dep1;
|
|
|
|
pub fn main() { println!(\"{}\", dep1::dep()) }
|
2017-07-22 03:12:21 +00:00
|
|
|
")
|
|
|
|
.build();
|
2014-08-16 18:20:47 +00:00
|
|
|
|
2014-08-27 05:23:01 +00:00
|
|
|
println!("first run");
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("run"), execs()
|
2016-05-20 13:39:58 +00:00
|
|
|
.with_stderr("[UPDATING] git repository `[..]`\n\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] dep1 v0.5.0 ([..])\n\
|
|
|
|
[COMPILING] foo v0.5.0 ([..])\n\
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in \
|
2016-07-25 23:30:03 +00:00
|
|
|
[..]\n\
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] `target[/]debug[/]foo[EXE]`\n")
|
2016-05-20 13:39:58 +00:00
|
|
|
.with_stdout("project2\n")
|
2014-08-16 18:20:47 +00:00
|
|
|
.with_status(0));
|
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
File::create(&git_project.root().join(".gitmodules")).unwrap()
|
|
|
|
.write_all(format!("[submodule \"src\"]\n\tpath = src\n\turl={}",
|
|
|
|
git_project3.url()).as_bytes()).unwrap();
|
2014-08-16 18:20:47 +00:00
|
|
|
|
2014-09-12 15:02:14 +00:00
|
|
|
// Sync the submodule and reset it to the new remote.
|
|
|
|
sub.sync().unwrap();
|
|
|
|
{
|
|
|
|
let subrepo = sub.open().unwrap();
|
2015-10-07 18:26:14 +00:00
|
|
|
subrepo.remote_add_fetch("origin",
|
|
|
|
"refs/heads/*:refs/heads/*").unwrap();
|
|
|
|
subrepo.remote_set_url("origin",
|
|
|
|
&git_project3.url().to_string()).unwrap();
|
2014-09-12 15:02:14 +00:00
|
|
|
let mut origin = subrepo.find_remote("origin").unwrap();
|
2015-10-07 18:26:14 +00:00
|
|
|
origin.fetch(&[], None, None).unwrap();
|
2014-09-12 15:02:14 +00:00
|
|
|
let id = subrepo.refname_to_id("refs/remotes/origin/master").unwrap();
|
|
|
|
let obj = subrepo.find_object(id, None).unwrap();
|
2015-03-16 13:27:58 +00:00
|
|
|
subrepo.reset(&obj, git2::ResetType::Hard, None).unwrap();
|
2014-09-12 15:02:14 +00:00
|
|
|
}
|
|
|
|
sub.add_to_index(true).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
git::add(&repo);
|
|
|
|
git::commit(&repo);
|
2014-08-16 18:20:47 +00:00
|
|
|
|
2016-05-26 00:06:25 +00:00
|
|
|
sleep_ms(1000);
|
2014-08-16 18:20:47 +00:00
|
|
|
// Update the dependency and carry on!
|
2014-08-27 05:23:01 +00:00
|
|
|
println!("update");
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("update").arg("-v"),
|
2014-08-27 05:23:01 +00:00
|
|
|
execs()
|
2014-08-16 18:20:47 +00:00
|
|
|
.with_stderr("")
|
2016-05-20 01:07:54 +00:00
|
|
|
.with_stderr(&format!("[UPDATING] git repository `{}`\n\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]\n\
|
|
|
|
", git_project.url())));
|
2014-08-16 18:20:47 +00:00
|
|
|
|
2014-08-27 05:23:01 +00:00
|
|
|
println!("last run");
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("run"), execs()
|
2016-05-20 13:39:58 +00:00
|
|
|
.with_stderr("[COMPILING] dep1 v0.5.0 ([..])\n\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.5.0 ([..])\n\
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in \
|
2016-07-25 23:30:03 +00:00
|
|
|
[..]\n\
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] `target[/]debug[/]foo[EXE]`\n")
|
2016-05-20 13:39:58 +00:00
|
|
|
.with_stdout("project3\n")
|
2014-08-16 18:20:47 +00:00
|
|
|
.with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-17 05:38:32 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dev_deps_with_testing() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let p2 = git::new("bar", |project| {
|
2014-08-17 05:38:32 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
pub fn gimme() -> &'static str { "zoidberg" }
|
|
|
|
"#)
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-08-17 05:38:32 +00:00
|
|
|
|
|
|
|
let p = project("foo")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-08-17 05:38:32 +00:00
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dev-dependencies.bar]
|
|
|
|
version = "0.5.0"
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, p2.url()))
|
2014-08-17 05:38:32 +00:00
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
extern crate bar;
|
|
|
|
#[test] fn foo() { bar::gimme(); }
|
|
|
|
}
|
2017-07-22 03:12:21 +00:00
|
|
|
"#)
|
|
|
|
.build();
|
2014-08-17 05:38:32 +00:00
|
|
|
|
|
|
|
// Generate a lockfile which did not use `bar` to compile, but had to update
|
|
|
|
// `bar` to generate the lockfile
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2016-05-14 21:44:18 +00:00
|
|
|
execs().with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `{bar}`
|
|
|
|
[COMPILING] foo v0.5.0 ({url})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-11 16:55:43 +00:00
|
|
|
", url = p.url(), bar = p2.url())));
|
2014-08-17 05:38:32 +00:00
|
|
|
|
|
|
|
// Make sure we use the previous resolution of `bar` instead of updating it
|
|
|
|
// a second time.
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test"),
|
2016-05-19 00:51:07 +00:00
|
|
|
execs().with_stderr("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] [..] v0.5.0 ([..])
|
|
|
|
[COMPILING] [..] v0.5.0 ([..]
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-10-04 23:16:30 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]")
|
2017-05-16 02:13:43 +00:00
|
|
|
.with_stdout_contains("test tests::foo ... ok"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-16 00:40:08 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn git_build_cmd_freshness() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let foo = git::new("foo", |project| {
|
2014-08-16 00:40:08 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.0"
|
|
|
|
authors = []
|
2015-01-19 22:27:51 +00:00
|
|
|
build = "build.rs"
|
2014-08-16 00:40:08 +00:00
|
|
|
"#)
|
2015-01-19 22:27:51 +00:00
|
|
|
.file("build.rs", "fn main() {}")
|
2015-02-13 04:10:07 +00:00
|
|
|
.file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
|
2014-08-16 00:40:08 +00:00
|
|
|
.file(".gitignore", "
|
|
|
|
src/bar.rs
|
|
|
|
")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2016-05-26 00:06:25 +00:00
|
|
|
foo.root().move_into_the_past();
|
2014-08-16 00:40:08 +00:00
|
|
|
|
2016-05-26 00:06:25 +00:00
|
|
|
sleep_ms(1000);
|
2014-08-19 05:51:14 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(foo.cargo("build"),
|
2014-08-16 00:40:08 +00:00
|
|
|
execs().with_status(0)
|
2016-05-14 21:44:18 +00:00
|
|
|
.with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.0 ({url})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-11 16:55:43 +00:00
|
|
|
", url = foo.url())));
|
2014-08-16 00:40:08 +00:00
|
|
|
|
|
|
|
// Smoke test to make sure it doesn't compile again
|
|
|
|
println!("first pass");
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(foo.cargo("build"),
|
2014-08-16 00:40:08 +00:00
|
|
|
execs().with_status(0)
|
2014-09-05 17:15:10 +00:00
|
|
|
.with_stdout(""));
|
2014-08-16 00:40:08 +00:00
|
|
|
|
|
|
|
// Modify an ignored file and make sure we don't rebuild
|
|
|
|
println!("second pass");
|
2014-12-21 23:19:44 +00:00
|
|
|
File::create(&foo.root().join("src/bar.rs")).unwrap();
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(foo.cargo("build"),
|
2014-08-16 00:40:08 +00:00
|
|
|
execs().with_status(0)
|
2014-09-05 17:15:10 +00:00
|
|
|
.with_stdout(""));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-28 18:10:10 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn git_name_not_always_needed() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let p2 = git::new("bar", |project| {
|
2014-08-28 18:10:10 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
pub fn gimme() -> &'static str { "zoidberg" }
|
|
|
|
"#)
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-08-28 18:10:10 +00:00
|
|
|
|
2014-09-12 15:02:14 +00:00
|
|
|
let repo = git2::Repository::open(&p2.root()).unwrap();
|
|
|
|
let mut cfg = repo.config().unwrap();
|
|
|
|
let _ = cfg.remove("user.name");
|
|
|
|
let _ = cfg.remove("user.email");
|
2014-08-28 18:10:10 +00:00
|
|
|
|
|
|
|
let p = project("foo")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-08-28 18:10:10 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dev-dependencies.bar]
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, p2.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2014-08-28 18:10:10 +00:00
|
|
|
|
|
|
|
// Generate a lockfile which did not use `bar` to compile, but had to update
|
|
|
|
// `bar` to generate the lockfile
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2016-05-14 21:44:18 +00:00
|
|
|
execs().with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `{bar}`
|
|
|
|
[COMPILING] foo v0.5.0 ({url})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-11 16:55:43 +00:00
|
|
|
", url = p.url(), bar = p2.url())));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-09-10 14:26:42 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn git_repo_changing_no_rebuild() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let bar = git::new("bar", |project| {
|
2014-09-10 14:26:42 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
"#)
|
2015-02-13 04:10:07 +00:00
|
|
|
.file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-09-10 14:26:42 +00:00
|
|
|
|
|
|
|
// Lock p1 to the first rev in the git repo
|
|
|
|
let p1 = project("p1")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-09-10 14:26:42 +00:00
|
|
|
[project]
|
|
|
|
name = "p1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
2015-01-19 22:27:51 +00:00
|
|
|
build = 'build.rs'
|
2014-09-10 14:26:42 +00:00
|
|
|
[dependencies.bar]
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, bar.url()))
|
2015-01-19 22:27:51 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("build.rs", "fn main() {}")
|
|
|
|
.build();
|
2016-05-26 00:06:25 +00:00
|
|
|
p1.root().move_into_the_past();
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p1.cargo("build"),
|
2016-05-14 21:44:18 +00:00
|
|
|
execs().with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `{bar}`
|
|
|
|
[COMPILING] [..]
|
|
|
|
[COMPILING] [..]
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-11 16:55:43 +00:00
|
|
|
", bar = bar.url())));
|
2014-09-10 14:26:42 +00:00
|
|
|
|
|
|
|
// Make a commit to lock p2 to a different rev
|
2015-02-27 01:04:25 +00:00
|
|
|
File::create(&bar.root().join("src/lib.rs")).unwrap().write_all(br#"
|
2015-02-13 04:10:07 +00:00
|
|
|
pub fn bar() -> i32 { 2 }
|
2014-12-21 23:19:44 +00:00
|
|
|
"#).unwrap();
|
2014-09-12 15:02:14 +00:00
|
|
|
let repo = git2::Repository::open(&bar.root()).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
git::add(&repo);
|
|
|
|
git::commit(&repo);
|
2014-09-10 14:26:42 +00:00
|
|
|
|
|
|
|
// Lock p2 to the second rev
|
|
|
|
let p2 = project("p2")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-09-10 14:26:42 +00:00
|
|
|
[project]
|
|
|
|
name = "p2"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
[dependencies.bar]
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, bar.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
assert_that(p2.cargo("build"),
|
2016-05-14 21:44:18 +00:00
|
|
|
execs().with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `{bar}`
|
|
|
|
[COMPILING] [..]
|
|
|
|
[COMPILING] [..]
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-11 16:55:43 +00:00
|
|
|
", bar = bar.url())));
|
2014-09-10 14:26:42 +00:00
|
|
|
|
|
|
|
// And now for the real test! Make sure that p1 doesn't get rebuilt
|
|
|
|
// even though the git repo has changed.
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p1.cargo("build"),
|
2014-09-10 14:26:42 +00:00
|
|
|
execs().with_stdout(""));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-09-12 22:21:23 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn git_dep_build_cmd() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let p = git::new("foo", |project| {
|
2014-09-12 22:21:23 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
|
|
|
|
version = "0.5.0"
|
|
|
|
path = "bar"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
"#)
|
|
|
|
.file("src/foo.rs",
|
2015-03-26 18:17:44 +00:00
|
|
|
&main_file(r#""{}", bar::gimme()"#, &["bar"]))
|
2014-09-12 22:21:23 +00:00
|
|
|
.file("bar/Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
2015-01-19 22:27:51 +00:00
|
|
|
build = "build.rs"
|
2014-09-12 22:21:23 +00:00
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "bar"
|
2017-07-09 10:31:42 +00:00
|
|
|
path = "src/bar.rs"
|
2014-09-12 22:21:23 +00:00
|
|
|
"#)
|
|
|
|
.file("bar/src/bar.rs.in", r#"
|
2015-02-13 04:10:07 +00:00
|
|
|
pub fn gimme() -> i32 { 0 }
|
2014-09-12 22:21:23 +00:00
|
|
|
"#)
|
2015-01-19 22:27:51 +00:00
|
|
|
.file("bar/build.rs", r#"
|
2015-03-26 18:17:44 +00:00
|
|
|
use std::fs;
|
2015-01-19 22:27:51 +00:00
|
|
|
fn main() {
|
2015-03-26 18:17:44 +00:00
|
|
|
fs::copy("src/bar.rs.in", "src/bar.rs").unwrap();
|
2015-01-19 22:27:51 +00:00
|
|
|
}
|
|
|
|
"#)
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-09-12 22:21:23 +00:00
|
|
|
|
2016-05-26 00:06:25 +00:00
|
|
|
p.root().join("bar").move_into_the_past();
|
2014-09-13 04:49:35 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
|
|
|
execs().with_status(0));
|
2014-09-12 22:21:23 +00:00
|
|
|
|
2015-10-28 09:20:00 +00:00
|
|
|
assert_that(process(&p.bin("foo")),
|
2015-02-27 01:04:25 +00:00
|
|
|
execs().with_stdout("0\n"));
|
2014-09-12 22:21:23 +00:00
|
|
|
|
|
|
|
// Touching bar.rs.in should cause the `build` command to run again.
|
2015-02-27 01:04:25 +00:00
|
|
|
fs::File::create(&p.root().join("bar/src/bar.rs.in")).unwrap()
|
|
|
|
.write_all(b"pub fn gimme() -> i32 { 1 }").unwrap();
|
2014-09-12 22:21:23 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
|
|
|
execs().with_status(0));
|
2014-09-12 22:21:23 +00:00
|
|
|
|
2015-10-28 09:20:00 +00:00
|
|
|
assert_that(process(&p.bin("foo")),
|
2015-02-27 01:04:25 +00:00
|
|
|
execs().with_stdout("1\n"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-09-12 22:21:23 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn fetch_downloads() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let bar = git::new("bar", |project| {
|
2014-09-11 18:50:57 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
"#)
|
2015-02-13 04:10:07 +00:00
|
|
|
.file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-09-11 18:50:57 +00:00
|
|
|
|
|
|
|
let p = project("p1")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-09-11 18:50:57 +00:00
|
|
|
[project]
|
|
|
|
name = "p1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
[dependencies.bar]
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, bar.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
assert_that(p.cargo("fetch"),
|
2016-05-14 21:44:18 +00:00
|
|
|
execs().with_status(0).with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `{url}`
|
|
|
|
", url = bar.url())));
|
2014-09-11 18:50:57 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("fetch"),
|
2014-09-11 18:50:57 +00:00
|
|
|
execs().with_status(0).with_stdout(""));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-09-21 17:22:46 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn warnings_in_git_dep() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let bar = git::new("bar", |project| {
|
2014-09-21 17:22:46 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "fn unused() {}")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-09-21 17:22:46 +00:00
|
|
|
|
|
|
|
let p = project("foo")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-09-21 17:22:46 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
[dependencies.bar]
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, bar.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2014-09-21 17:22:46 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2014-09-21 17:22:46 +00:00
|
|
|
execs()
|
2016-05-20 01:07:54 +00:00
|
|
|
.with_stderr(&format!("[UPDATING] git repository `{}`\n\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] bar v0.5.0 ({}#[..])\n\
|
2016-07-25 23:30:03 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({})\n\
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
|
2016-05-11 16:55:43 +00:00
|
|
|
bar.url(),
|
|
|
|
bar.url(),
|
2016-05-20 13:39:58 +00:00
|
|
|
p.url())));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-09-27 04:45:51 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn update_ambiguous() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let foo1 = git::new("foo1", |project| {
|
2014-09-27 04:45:51 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
let foo2 = git::new("foo2", |project| {
|
2014-09-27 04:45:51 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.6.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
let bar = git::new("bar", |project| {
|
2015-02-27 01:04:25 +00:00
|
|
|
project.file("Cargo.toml", &format!(r#"
|
2014-09-27 04:45:51 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.foo]
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, foo2.url()))
|
2014-09-27 04:45:51 +00:00
|
|
|
.file("src/lib.rs", "")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-09-27 04:45:51 +00:00
|
|
|
|
|
|
|
let p = project("project")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-09-27 04:45:51 +00:00
|
|
|
[project]
|
|
|
|
name = "project"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
[dependencies.foo]
|
|
|
|
git = '{}'
|
|
|
|
[dependencies.bar]
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, foo1.url(), bar.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2014-09-27 04:45:51 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("generate-lockfile"), execs().with_status(0));
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("update")
|
2014-09-27 04:45:51 +00:00
|
|
|
.arg("-p").arg("foo"),
|
|
|
|
execs().with_status(101)
|
2016-05-12 17:06:36 +00:00
|
|
|
.with_stderr("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] There are multiple `foo` packages in your project, and the specification `foo` \
|
2014-09-27 04:45:51 +00:00
|
|
|
is ambiguous.
|
|
|
|
Please re-run this command with `-p <spec>` where `<spec>` is one of the \
|
|
|
|
following:
|
|
|
|
foo:0.[..].0
|
|
|
|
foo:0.[..].0
|
2016-05-12 17:06:36 +00:00
|
|
|
"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-13 16:54:08 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn update_one_dep_in_repo_with_many_deps() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let foo = git::new("foo", |project| {
|
2014-10-13 16:54:08 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("a/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
"#)
|
|
|
|
.file("a/src/lib.rs", "")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-10-13 16:54:08 +00:00
|
|
|
|
|
|
|
let p = project("project")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-10-13 16:54:08 +00:00
|
|
|
[project]
|
|
|
|
name = "project"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
[dependencies.foo]
|
|
|
|
git = '{}'
|
|
|
|
[dependencies.a]
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, foo.url(), foo.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2014-10-13 16:54:08 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("generate-lockfile"), execs().with_status(0));
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("update")
|
2014-10-13 16:54:08 +00:00
|
|
|
.arg("-p").arg("foo"),
|
|
|
|
execs().with_status(0)
|
2016-05-14 21:44:18 +00:00
|
|
|
.with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `{}`
|
|
|
|
", foo.url())));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-22 22:05:49 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn switch_deps_does_not_update_transitive() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let transitive = git::new("transitive", |project| {
|
2014-10-22 22:05:49 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "transitive"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
let dep1 = git::new("dep1", |project| {
|
2015-02-27 01:04:25 +00:00
|
|
|
project.file("Cargo.toml", &format!(r#"
|
2014-10-22 22:05:49 +00:00
|
|
|
[package]
|
|
|
|
name = "dep"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.transitive]
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, transitive.url()))
|
2014-10-22 22:05:49 +00:00
|
|
|
.file("src/lib.rs", "")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
let dep2 = git::new("dep2", |project| {
|
2015-02-27 01:04:25 +00:00
|
|
|
project.file("Cargo.toml", &format!(r#"
|
2014-10-22 22:05:49 +00:00
|
|
|
[package]
|
|
|
|
name = "dep"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.transitive]
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, transitive.url()))
|
2014-10-22 22:05:49 +00:00
|
|
|
.file("src/lib.rs", "")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-10-22 22:05:49 +00:00
|
|
|
|
|
|
|
let p = project("project")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-10-22 22:05:49 +00:00
|
|
|
[project]
|
|
|
|
name = "project"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
[dependencies.dep]
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, dep1.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2014-10-22 22:05:49 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2014-10-22 22:05:49 +00:00
|
|
|
execs().with_status(0)
|
2016-05-14 21:44:18 +00:00
|
|
|
.with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `{}`
|
|
|
|
[UPDATING] git repository `{}`
|
|
|
|
[COMPILING] transitive [..]
|
|
|
|
[COMPILING] dep [..]
|
|
|
|
[COMPILING] project [..]
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-11 16:55:43 +00:00
|
|
|
", dep1.url(), transitive.url())));
|
2014-10-22 22:05:49 +00:00
|
|
|
|
|
|
|
// Update the dependency to point to the second repository, but this
|
|
|
|
// shouldn't update the transitive dependency which is the same.
|
2015-02-27 01:04:25 +00:00
|
|
|
File::create(&p.root().join("Cargo.toml")).unwrap().write_all(format!(r#"
|
2014-10-22 22:05:49 +00:00
|
|
|
[project]
|
|
|
|
name = "project"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
[dependencies.dep]
|
|
|
|
git = '{}'
|
2015-02-27 01:04:25 +00:00
|
|
|
"#, dep2.url()).as_bytes()).unwrap();
|
2014-10-22 22:05:49 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2014-10-22 22:05:49 +00:00
|
|
|
execs().with_status(0)
|
2016-05-14 21:44:18 +00:00
|
|
|
.with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `{}`
|
|
|
|
[COMPILING] dep [..]
|
|
|
|
[COMPILING] project [..]
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-11 16:55:43 +00:00
|
|
|
", dep2.url())));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-29 18:42:45 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn update_one_source_updates_all_packages_in_that_git_source() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let dep = git::new("dep", |project| {
|
2014-10-29 18:42:45 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "dep"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.a]
|
|
|
|
path = "a"
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("a/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("a/src/lib.rs", "")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-10-29 18:42:45 +00:00
|
|
|
|
|
|
|
let p = project("project")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-10-29 18:42:45 +00:00
|
|
|
[project]
|
|
|
|
name = "project"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
[dependencies.dep]
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, dep.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2014-10-29 18:42:45 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2014-10-29 18:42:45 +00:00
|
|
|
execs().with_status(0));
|
|
|
|
|
|
|
|
let repo = git2::Repository::open(&dep.root()).unwrap();
|
|
|
|
let rev1 = repo.revparse_single("HEAD").unwrap().id();
|
|
|
|
|
|
|
|
// Just be sure to change a file
|
2015-02-27 01:04:25 +00:00
|
|
|
File::create(&dep.root().join("src/lib.rs")).unwrap().write_all(br#"
|
2015-02-13 04:10:07 +00:00
|
|
|
pub fn bar() -> i32 { 2 }
|
2014-12-21 23:19:44 +00:00
|
|
|
"#).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
git::add(&repo);
|
|
|
|
git::commit(&repo);
|
2014-10-29 18:42:45 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("update").arg("-p").arg("dep"),
|
2014-10-29 18:42:45 +00:00
|
|
|
execs().with_status(0));
|
2015-02-27 01:04:25 +00:00
|
|
|
let mut lockfile = String::new();
|
|
|
|
File::open(&p.root().join("Cargo.lock")).unwrap()
|
|
|
|
.read_to_string(&mut lockfile).unwrap();
|
2015-03-26 18:17:44 +00:00
|
|
|
assert!(!lockfile.contains(&rev1.to_string()),
|
2014-10-29 18:42:45 +00:00
|
|
|
"{} in {}", rev1, lockfile);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-11-24 01:46:04 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn switch_sources() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let a1 = git::new("a1", |project| {
|
2014-11-24 01:46:04 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
let a2 = git::new("a2", |project| {
|
2014-11-24 01:46:04 +00:00
|
|
|
project.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.5.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
2014-12-21 23:19:44 +00:00
|
|
|
}).unwrap();
|
2014-11-24 01:46:04 +00:00
|
|
|
|
|
|
|
let p = project("project")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "project"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
[dependencies.b]
|
|
|
|
path = "b"
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("b/Cargo.toml", &format!(r#"
|
2014-11-24 01:46:04 +00:00
|
|
|
[project]
|
|
|
|
name = "b"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
[dependencies.a]
|
|
|
|
git = '{}'
|
2015-03-26 18:17:44 +00:00
|
|
|
"#, a1.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("b/src/lib.rs", "pub fn main() {}")
|
|
|
|
.build();
|
2014-11-24 01:46:04 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2014-11-24 01:46:04 +00:00
|
|
|
execs().with_status(0)
|
2016-05-14 21:15:22 +00:00
|
|
|
.with_stderr("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `file://[..]a1`
|
|
|
|
[COMPILING] a v0.5.0 ([..]a1#[..]
|
|
|
|
[COMPILING] b v0.5.0 ([..])
|
|
|
|
[COMPILING] project v0.5.0 ([..])
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-12 17:06:36 +00:00
|
|
|
"));
|
2014-11-24 01:46:04 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
File::create(&p.root().join("b/Cargo.toml")).unwrap().write_all(format!(r#"
|
2014-11-24 01:46:04 +00:00
|
|
|
[project]
|
|
|
|
name = "b"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
[dependencies.a]
|
|
|
|
git = '{}'
|
2015-02-27 01:04:25 +00:00
|
|
|
"#, a2.url()).as_bytes()).unwrap();
|
2014-11-24 01:46:04 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2014-11-24 01:46:04 +00:00
|
|
|
execs().with_status(0)
|
2016-05-14 21:15:22 +00:00
|
|
|
.with_stderr("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `file://[..]a2`
|
|
|
|
[COMPILING] a v0.5.1 ([..]a2#[..]
|
|
|
|
[COMPILING] b v0.5.0 ([..])
|
|
|
|
[COMPILING] project v0.5.0 ([..])
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-12 17:06:36 +00:00
|
|
|
"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-01-29 19:41:00 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dont_require_submodules_are_checked_out() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo").build();
|
2015-06-01 21:38:30 +00:00
|
|
|
let git1 = git::new("dep1", |p| {
|
2015-01-29 19:41:00 +00:00
|
|
|
p.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
build = "build.rs"
|
|
|
|
"#)
|
|
|
|
.file("build.rs", "fn main() {}")
|
|
|
|
.file("src/lib.rs", "")
|
2015-02-16 04:23:09 +00:00
|
|
|
.file("a/foo", "")
|
2015-01-29 19:41:00 +00:00
|
|
|
}).unwrap();
|
2015-06-01 21:38:30 +00:00
|
|
|
let git2 = git::new("dep2", |p| p).unwrap();
|
2015-01-29 19:41:00 +00:00
|
|
|
|
|
|
|
let repo = git2::Repository::open(&git1.root()).unwrap();
|
|
|
|
let url = path2url(git2.root()).to_string();
|
2017-02-18 12:01:10 +00:00
|
|
|
git::add_submodule(&repo, &url, Path::new("a/submodule"));
|
2015-06-01 21:38:30 +00:00
|
|
|
git::commit(&repo);
|
2015-01-29 19:41:00 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
git2::Repository::init(&p.root()).unwrap();
|
2015-01-29 19:41:00 +00:00
|
|
|
let url = path2url(git1.root()).to_string();
|
|
|
|
let dst = paths::home().join("foo");
|
2015-02-22 23:06:12 +00:00
|
|
|
git2::Repository::clone(&url, &dst).unwrap();
|
2015-01-29 19:41:00 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(git1.cargo("build").arg("-v").cwd(&dst),
|
2015-01-29 19:41:00 +00:00
|
|
|
execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-03-25 19:46:21 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_same_name() {
|
2015-06-01 21:38:30 +00:00
|
|
|
let a2 = git::new("a2", |p| {
|
2015-03-25 19:46:21 +00:00
|
|
|
p.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "a"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "pub fn a2() {}")
|
|
|
|
}).unwrap();
|
|
|
|
|
2015-06-01 21:38:30 +00:00
|
|
|
let a1 = git::new("a1", |p| {
|
2015-03-25 19:46:21 +00:00
|
|
|
p.file("Cargo.toml", &format!(r#"
|
|
|
|
[project]
|
|
|
|
name = "a"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
[dependencies]
|
|
|
|
a = {{ git = '{}' }}
|
|
|
|
"#, a2.url()))
|
|
|
|
.file("src/lib.rs", "extern crate a; pub fn a1() {}")
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &format!(r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = {{ git = '{}' }}
|
|
|
|
"#, a1.url()))
|
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
#[macro_use]
|
|
|
|
extern crate a;
|
2017-07-22 03:12:21 +00:00
|
|
|
"#)
|
|
|
|
.build();
|
2015-03-25 19:46:21 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("test").arg("-v"),
|
2015-03-25 19:46:21 +00:00
|
|
|
execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-07-24 18:49:19 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn lints_are_suppressed() {
|
2015-07-24 18:49:19 +00:00
|
|
|
let a = git::new("a", |p| {
|
|
|
|
p.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "a"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "
|
|
|
|
use std::option;
|
|
|
|
")
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &format!(r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = {{ git = '{}' }}
|
|
|
|
"#, a.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2015-07-24 18:49:19 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2016-05-14 21:15:22 +00:00
|
|
|
execs().with_status(0).with_stderr("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `[..]`
|
|
|
|
[COMPILING] a v0.5.0 ([..])
|
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-12 17:06:36 +00:00
|
|
|
"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-07-24 18:49:19 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn denied_lints_are_allowed() {
|
2015-07-24 18:49:19 +00:00
|
|
|
let a = git::new("a", |p| {
|
|
|
|
p.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "a"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "
|
|
|
|
#![deny(warnings)]
|
|
|
|
use std::option;
|
|
|
|
")
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &format!(r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = {{ git = '{}' }}
|
|
|
|
"#, a.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2015-07-24 18:49:19 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2016-05-14 21:15:22 +00:00
|
|
|
execs().with_status(0).with_stderr("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] git repository `[..]`
|
|
|
|
[COMPILING] a v0.5.0 ([..])
|
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-12 17:06:36 +00:00
|
|
|
"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-03-30 17:39:24 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn add_a_git_dep() {
|
2016-03-30 17:39:24 +00:00
|
|
|
let git = git::new("git", |p| {
|
|
|
|
p.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "git"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &format!(r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = {{ path = 'a' }}
|
|
|
|
git = {{ git = '{}' }}
|
|
|
|
"#, git.url()))
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("a/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("a/src/lib.rs", "")
|
|
|
|
.build();
|
2016-03-30 17:39:24 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2016-03-30 17:39:24 +00:00
|
|
|
|
|
|
|
File::create(p.root().join("a/Cargo.toml")).unwrap().write_all(format!(r#"
|
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
git = {{ git = '{}' }}
|
|
|
|
"#, git.url()).as_bytes()).unwrap();
|
|
|
|
|
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2017-01-23 17:25:14 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn two_at_rev_instead_of_tag() {
|
|
|
|
let git = git::new("git", |p| {
|
|
|
|
p.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "git1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("a/Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "git2"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("a/src/lib.rs", "")
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
// Make a tag corresponding to the current HEAD
|
|
|
|
let repo = git2::Repository::open(&git.root()).unwrap();
|
|
|
|
let head = repo.head().unwrap().target().unwrap();
|
|
|
|
repo.tag("v0.1.0",
|
|
|
|
&repo.find_object(head, None).unwrap(),
|
|
|
|
&repo.signature().unwrap(),
|
|
|
|
"make a new tag",
|
|
|
|
false).unwrap();
|
|
|
|
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &format!(r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
git1 = {{ git = '{0}', rev = 'v0.1.0' }}
|
|
|
|
git2 = {{ git = '{0}', rev = 'v0.1.0' }}
|
|
|
|
"#, git.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2017-01-23 17:25:14 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("generate-lockfile"), execs().with_status(0));
|
2017-01-23 17:25:14 +00:00
|
|
|
assert_that(p.cargo("build").arg("-v"), execs().with_status(0));
|
|
|
|
}
|
2017-06-16 15:54:59 +00:00
|
|
|
|
|
|
|
#[test]
|
2017-06-25 05:43:45 +00:00
|
|
|
#[ignore] // accesses crates.io
|
2017-06-16 15:54:59 +00:00
|
|
|
fn include_overrides_gitignore() {
|
|
|
|
let p = git::new("reduction", |repo| {
|
|
|
|
repo.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "reduction"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["pnkfelix"]
|
|
|
|
build = "tango-build.rs"
|
|
|
|
include = ["src/lib.rs", "src/incl.rs", "src/mod.md", "tango-build.rs", "Cargo.toml"]
|
|
|
|
|
|
|
|
[build-dependencies]
|
|
|
|
filetime = "0.1"
|
|
|
|
"#)
|
|
|
|
.file(".gitignore", r#"
|
|
|
|
target
|
|
|
|
Cargo.lock
|
|
|
|
# Below files represent generated code, thus not managed by `git`
|
|
|
|
src/incl.rs
|
|
|
|
src/not_incl.rs
|
|
|
|
"#)
|
|
|
|
.file("tango-build.rs", r#"
|
|
|
|
extern crate filetime;
|
|
|
|
use filetime::FileTime;
|
|
|
|
use std::fs::{self, File};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// generate files, or bring their timestamps into sync.
|
|
|
|
let source = "src/mod.md";
|
|
|
|
|
|
|
|
let metadata = fs::metadata(source).unwrap();
|
|
|
|
let mtime = FileTime::from_last_modification_time(&metadata);
|
|
|
|
let atime = FileTime::from_last_access_time(&metadata);
|
|
|
|
|
|
|
|
// sync time stamps for generated files with time stamp of source file.
|
|
|
|
|
|
|
|
let files = ["src/not_incl.rs", "src/incl.rs"];
|
|
|
|
for file in files.iter() {
|
|
|
|
File::create(file).unwrap();
|
|
|
|
filetime::set_file_times(file, atime, mtime).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
mod not_incl;
|
|
|
|
mod incl;
|
|
|
|
"#)
|
|
|
|
.file("src/mod.md", r#"
|
|
|
|
(The content of this file does not matter since we are not doing real codegen.)
|
|
|
|
"#)
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
println!("build 1: all is new");
|
|
|
|
assert_that(p.cargo("build").arg("-v"),
|
|
|
|
execs().with_status(0)
|
|
|
|
.with_stderr("\
|
|
|
|
[UPDATING] registry `[..]`
|
|
|
|
[DOWNLOADING] filetime [..]
|
|
|
|
[DOWNLOADING] libc [..]
|
|
|
|
[COMPILING] libc [..]
|
|
|
|
[RUNNING] `rustc --crate-name libc [..]`
|
|
|
|
[COMPILING] filetime [..]
|
|
|
|
[RUNNING] `rustc --crate-name filetime [..]`
|
|
|
|
[COMPILING] reduction [..]
|
|
|
|
[RUNNING] `rustc --crate-name build_script_tango_build tango-build.rs --crate-type bin [..]`
|
|
|
|
[RUNNING] `[..][/]build-script-tango-build`
|
|
|
|
[RUNNING] `rustc --crate-name reduction src[/]lib.rs --crate-type lib [..]`
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
"));
|
|
|
|
|
|
|
|
println!("build 2: nothing changed; file timestamps reset by build script");
|
|
|
|
assert_that(p.cargo("build").arg("-v"),
|
|
|
|
execs().with_status(0)
|
|
|
|
.with_stderr("\
|
|
|
|
[FRESH] libc [..]
|
|
|
|
[FRESH] filetime [..]
|
|
|
|
[FRESH] reduction [..]
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
"));
|
|
|
|
|
|
|
|
println!("build 3: touch `src/not_incl.rs`; expect build script *not* re-run");
|
|
|
|
sleep_ms(1000);
|
|
|
|
File::create(p.root().join("src").join("not_incl.rs")).unwrap();
|
|
|
|
|
|
|
|
assert_that(p.cargo("build").arg("-v"),
|
|
|
|
execs().with_status(0)
|
|
|
|
.with_stderr("\
|
|
|
|
[FRESH] libc [..]
|
|
|
|
[FRESH] filetime [..]
|
|
|
|
[COMPILING] reduction [..]
|
|
|
|
[RUNNING] `rustc --crate-name reduction src[/]lib.rs --crate-type lib [..]`
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
"));
|
|
|
|
|
|
|
|
// This final case models the bug from rust-lang/cargo#4135: an
|
|
|
|
// explicitly included file should cause a build-script re-run,
|
|
|
|
// even if that same file is matched by `.gitignore`.
|
|
|
|
println!("build 4: touch `src/incl.rs`; expect build script re-run");
|
|
|
|
sleep_ms(1000);
|
|
|
|
File::create(p.root().join("src").join("incl.rs")).unwrap();
|
|
|
|
|
|
|
|
assert_that(p.cargo("build").arg("-v"),
|
|
|
|
execs().with_status(0)
|
|
|
|
.with_stderr("\
|
|
|
|
[FRESH] libc [..]
|
|
|
|
[FRESH] filetime [..]
|
|
|
|
[COMPILING] reduction [..]
|
|
|
|
[RUNNING] `[..][/]build-script-tango-build`
|
|
|
|
[RUNNING] `rustc --crate-name reduction src[/]lib.rs --crate-type lib [..]`
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
"));
|
|
|
|
}
|
2017-07-30 14:12:18 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_git_dependency_manifest() {
|
|
|
|
let project = project("foo");
|
|
|
|
let git_project = git::new("dep1", |project| {
|
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["carlhuda@example.com"]
|
|
|
|
categories = ["algorithms"]
|
|
|
|
categories = ["algorithms"]
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
|
|
|
|
name = "dep1"
|
|
|
|
"#)
|
|
|
|
.file("src/dep1.rs", r#"
|
|
|
|
pub fn hello() -> &'static str {
|
|
|
|
"hello world"
|
|
|
|
}
|
|
|
|
"#)
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
let project = project
|
|
|
|
.file("Cargo.toml", &format!(r#"
|
|
|
|
[project]
|
|
|
|
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = ["wycats@example.com"]
|
|
|
|
|
|
|
|
[dependencies.dep1]
|
|
|
|
|
|
|
|
git = '{}'
|
|
|
|
"#, git_project.url()))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", &main_file(r#""{}", dep1::hello()"#, &["dep1"]))
|
|
|
|
.build();
|
2017-07-30 14:12:18 +00:00
|
|
|
|
|
|
|
let git_root = git_project.root();
|
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(project.cargo("build"),
|
2017-07-30 14:12:18 +00:00
|
|
|
execs()
|
|
|
|
.with_stderr(&format!("[UPDATING] git repository `{}`\n\
|
|
|
|
error: failed to load source for a dependency on `dep1`\n\
|
|
|
|
\n\
|
|
|
|
Caused by:\n \
|
|
|
|
Unable to update {}\n\
|
|
|
|
\n\
|
|
|
|
Caused by:\n \
|
|
|
|
failed to parse manifest at `[..]`\n\
|
|
|
|
\n\
|
|
|
|
Caused by:\n \
|
|
|
|
could not parse input as TOML\n\
|
|
|
|
\n\
|
|
|
|
Caused by:\n \
|
|
|
|
duplicate key: `categories` for key `project`",
|
|
|
|
path2url(git_root.clone()),
|
|
|
|
path2url(git_root),
|
|
|
|
)));
|
|
|
|
}
|
2017-12-19 15:34:14 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn failed_submodule_checkout() {
|
|
|
|
let project = project("foo");
|
|
|
|
let git_project = git::new("dep1", |project| {
|
|
|
|
project
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "dep1"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = [""]
|
|
|
|
"#)
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
let git_project2 = git::new("dep2", |project| {
|
|
|
|
project.file("lib.rs", "")
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
|
|
|
|
let addr = listener.local_addr().unwrap();
|
|
|
|
|
|
|
|
let t = thread::spawn(move || {
|
|
|
|
let a = listener.accept().unwrap();
|
|
|
|
drop(a);
|
|
|
|
let a = listener.accept().unwrap();
|
|
|
|
drop(a);
|
|
|
|
});
|
|
|
|
|
|
|
|
let repo = git2::Repository::open(&git_project2.root()).unwrap();
|
|
|
|
let url = format!("http://{}:{}/", addr.ip(), addr.port());
|
|
|
|
{
|
|
|
|
let mut s = repo.submodule(&url, Path::new("bar"), false).unwrap();
|
|
|
|
let subrepo = s.open().unwrap();
|
|
|
|
let mut cfg = subrepo.config().unwrap();
|
|
|
|
cfg.set_str("user.email", "foo@bar.com").unwrap();
|
|
|
|
cfg.set_str("user.name", "Foo Bar").unwrap();
|
|
|
|
git::commit(&subrepo);
|
|
|
|
s.add_finalize().unwrap();
|
|
|
|
}
|
|
|
|
git::commit(&repo);
|
|
|
|
drop((repo, url));
|
|
|
|
|
|
|
|
let repo = git2::Repository::open(&git_project.root()).unwrap();
|
|
|
|
let url = path2url(git_project2.root()).to_string();
|
|
|
|
git::add_submodule(&repo, &url, Path::new("src"));
|
|
|
|
git::commit(&repo);
|
|
|
|
drop(repo);
|
|
|
|
|
|
|
|
let project = project
|
|
|
|
.file("Cargo.toml", &format!(r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
dep1 = {{ git = '{}' }}
|
|
|
|
"#, git_project.url()))
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(project.cargo("build"),
|
|
|
|
execs().with_status(101)
|
|
|
|
.with_stderr_contains(" failed to update submodule `src`")
|
|
|
|
.with_stderr_contains(" failed to update submodule `bar`"));
|
|
|
|
assert_that(project.cargo("build"),
|
|
|
|
execs().with_status(101)
|
|
|
|
.with_stderr_contains(" failed to update submodule `src`")
|
|
|
|
.with_stderr_contains(" failed to update submodule `bar`"));
|
|
|
|
|
|
|
|
t.join().unwrap();
|
|
|
|
}
|