message: Add tests for new rustdoc fingerprint behavior.
diff: @@ -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;
  @@ -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());
  +}
  