Skip to content

Commit

Permalink
Add tests for new rustdoc fingerprint behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Apr 24, 2021
1 parent 6f75160 commit c373867
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cargo::core::compiler::RustDocFingerprint;
use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::registry::Package;
use cargo_test_support::{basic_lib_manifest, basic_manifest, git, project};
use cargo_test_support::{is_nightly, rustc_host};
use cargo_test_support::{is_nightly, rustc_host, symlink_supported};
use std::fs;
use std::str;

Expand Down Expand Up @@ -1889,3 +1889,61 @@ LLVM version: 9.0
(String::from_utf8_lossy(&output.stdout).as_ref())
);
}

#[cargo_test]
fn doc_fingerprint_unusual_behavior() {
// Checks for some unusual circumstances with clearing the doc directory.
if !symlink_supported() {
return;
}
let p = project().file("src/lib.rs", "").build();
p.build_dir().mkdir_p();
let real_doc = p.root().join("doc");
real_doc.mkdir_p();
let build_doc = p.build_dir().join("doc");
p.symlink(&real_doc, &build_doc);
fs::write(real_doc.join("somefile"), "test").unwrap();
fs::write(real_doc.join(".hidden"), "test").unwrap();
p.cargo("doc").run();
// Make sure for the first run, it does not delete any files and does not
// break the symlink.
assert!(build_doc.join("somefile").exists());
assert!(real_doc.join("somefile").exists());
assert!(real_doc.join(".hidden").exists());
assert!(real_doc.join("foo/index.html").exists());
// Pretend that the last build was generated by an older version.
p.change_file(
"target/.rustdoc_fingerprint.json",
"{\"rustc_vv\": \"I am old\"}",
);
// Change file to trigger a new build.
p.change_file("src/lib.rs", "// changed");
p.cargo("doc")
.with_stderr(
"[DOCUMENTING] foo [..]\n\
[FINISHED] [..]",
)
.run();
// This will delete somefile, but not .hidden.
assert!(!real_doc.join("somefile").exists());
assert!(real_doc.join(".hidden").exists());
assert!(real_doc.join("foo/index.html").exists());
// And also check the -Z flag behavior.
p.change_file(
"target/.rustdoc_fingerprint.json",
"{\"rustc_vv\": \"I am old\"}",
);
// Change file to trigger a new build.
p.change_file("src/lib.rs", "// changed2");
fs::write(real_doc.join("somefile"), "test").unwrap();
p.cargo("doc -Z skip-rustdoc-fingerprint")
.masquerade_as_nightly_cargo()
.with_stderr(
"[DOCUMENTING] foo [..]\n\
[FINISHED] [..]",
)
.run();
// Should not have deleted anything.
assert!(build_doc.join("somefile").exists());
assert!(real_doc.join("somefile").exists());
}

0 comments on commit c373867

Please sign in to comment.