Skip to content

Commit 361b110

Browse files
committed
Add test of git dependency on pull request
1 parent 256213a commit 361b110

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/testsuite/git.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,68 @@ fn cargo_compile_git_dep_tag() {
230230
project.cargo("build").run();
231231
}
232232

233+
#[cargo_test]
234+
fn cargo_compile_git_dep_pull_request() {
235+
let project = project();
236+
let git_project = git::new("dep1", |project| {
237+
project
238+
.file("Cargo.toml", &basic_lib_manifest("dep1"))
239+
.file(
240+
"src/dep1.rs",
241+
r#"
242+
pub fn hello() -> &'static str {
243+
"hello world"
244+
}
245+
"#,
246+
)
247+
});
248+
249+
// Make a reference in GitHub's pull request ref naming convention.
250+
let repo = git2::Repository::open(&git_project.root()).unwrap();
251+
let oid = repo.refname_to_id("HEAD").unwrap();
252+
let force = false;
253+
let log_message = "open pull request";
254+
repo.reference("refs/pull/330/head", oid, force, log_message)
255+
.unwrap();
256+
257+
let project = project
258+
.file(
259+
"Cargo.toml",
260+
&format!(
261+
r#"
262+
[project]
263+
name = "foo"
264+
version = "0.0.0"
265+
266+
[dependencies]
267+
dep1 = {{ git = "{}", rev = "refs/pull/330/head" }}
268+
"#,
269+
git_project.url()
270+
),
271+
)
272+
.file(
273+
"src/main.rs",
274+
&main_file(r#""{}", dep1::hello()"#, &["dep1"]),
275+
)
276+
.build();
277+
278+
let git_root = git_project.root();
279+
280+
project
281+
.cargo("build")
282+
.with_stderr(&format!(
283+
"[UPDATING] git repository `{}`\n\
284+
[COMPILING] dep1 v0.5.0 ({}?rev=refs/pull/330/head#[..])\n\
285+
[COMPILING] foo v0.0.0 ([CWD])\n\
286+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
287+
path2url(&git_root),
288+
path2url(&git_root),
289+
))
290+
.run();
291+
292+
assert!(project.bin("foo").is_file());
293+
}
294+
233295
#[cargo_test]
234296
fn cargo_compile_with_nested_paths() {
235297
let git_project = git::new("dep1", |project| {

0 commit comments

Comments
 (0)