Skip to content

Commit c373867

Browse files
committed
Add tests for new rustdoc fingerprint behavior.
1 parent 6f75160 commit c373867

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

tests/testsuite/doc.rs

+59-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use cargo::core::compiler::RustDocFingerprint;
44
use cargo_test_support::paths::CargoPathExt;
55
use cargo_test_support::registry::Package;
66
use cargo_test_support::{basic_lib_manifest, basic_manifest, git, project};
7-
use cargo_test_support::{is_nightly, rustc_host};
7+
use cargo_test_support::{is_nightly, rustc_host, symlink_supported};
88
use std::fs;
99
use std::str;
1010

@@ -1889,3 +1889,61 @@ LLVM version: 9.0
18891889
(String::from_utf8_lossy(&output.stdout).as_ref())
18901890
);
18911891
}
1892+
1893+
#[cargo_test]
1894+
fn doc_fingerprint_unusual_behavior() {
1895+
// Checks for some unusual circumstances with clearing the doc directory.
1896+
if !symlink_supported() {
1897+
return;
1898+
}
1899+
let p = project().file("src/lib.rs", "").build();
1900+
p.build_dir().mkdir_p();
1901+
let real_doc = p.root().join("doc");
1902+
real_doc.mkdir_p();
1903+
let build_doc = p.build_dir().join("doc");
1904+
p.symlink(&real_doc, &build_doc);
1905+
fs::write(real_doc.join("somefile"), "test").unwrap();
1906+
fs::write(real_doc.join(".hidden"), "test").unwrap();
1907+
p.cargo("doc").run();
1908+
// Make sure for the first run, it does not delete any files and does not
1909+
// break the symlink.
1910+
assert!(build_doc.join("somefile").exists());
1911+
assert!(real_doc.join("somefile").exists());
1912+
assert!(real_doc.join(".hidden").exists());
1913+
assert!(real_doc.join("foo/index.html").exists());
1914+
// Pretend that the last build was generated by an older version.
1915+
p.change_file(
1916+
"target/.rustdoc_fingerprint.json",
1917+
"{\"rustc_vv\": \"I am old\"}",
1918+
);
1919+
// Change file to trigger a new build.
1920+
p.change_file("src/lib.rs", "// changed");
1921+
p.cargo("doc")
1922+
.with_stderr(
1923+
"[DOCUMENTING] foo [..]\n\
1924+
[FINISHED] [..]",
1925+
)
1926+
.run();
1927+
// This will delete somefile, but not .hidden.
1928+
assert!(!real_doc.join("somefile").exists());
1929+
assert!(real_doc.join(".hidden").exists());
1930+
assert!(real_doc.join("foo/index.html").exists());
1931+
// And also check the -Z flag behavior.
1932+
p.change_file(
1933+
"target/.rustdoc_fingerprint.json",
1934+
"{\"rustc_vv\": \"I am old\"}",
1935+
);
1936+
// Change file to trigger a new build.
1937+
p.change_file("src/lib.rs", "// changed2");
1938+
fs::write(real_doc.join("somefile"), "test").unwrap();
1939+
p.cargo("doc -Z skip-rustdoc-fingerprint")
1940+
.masquerade_as_nightly_cargo()
1941+
.with_stderr(
1942+
"[DOCUMENTING] foo [..]\n\
1943+
[FINISHED] [..]",
1944+
)
1945+
.run();
1946+
// Should not have deleted anything.
1947+
assert!(build_doc.join("somefile").exists());
1948+
assert!(real_doc.join("somefile").exists());
1949+
}

0 commit comments

Comments
 (0)