Skip to content

Commit

Permalink
test_local_working_copy: enable symlink tests on windows, but ignore …
Browse files Browse the repository at this point in the history
…failures due to disabled developer mode
  • Loading branch information
gulbanana committed Feb 4, 2024
1 parent 37a43a3 commit 9a439e3
Showing 1 changed file with 50 additions and 24 deletions.
74 changes: 50 additions & 24 deletions lib/tests/test_local_working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::sync::Arc;

use itertools::Itertools;
use jj_lib::backend::{MergedTreeId, TreeId, TreeValue};
use jj_lib::file_util::{try_symlink, SymlinkError};
use jj_lib::fsmonitor::FsmonitorKind;
use jj_lib::local_working_copy::LocalWorkingCopy;
use jj_lib::merge::Merge;
Expand All @@ -35,7 +36,7 @@ use jj_lib::op_store::{OperationId, WorkspaceId};
use jj_lib::repo::{ReadonlyRepo, Repo};
use jj_lib::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent};
use jj_lib::settings::UserSettings;
use jj_lib::working_copy::{CheckoutStats, SnapshotError, SnapshotOptions};
use jj_lib::working_copy::{CheckoutError, CheckoutStats, SnapshotError, SnapshotOptions};
use jj_lib::workspace::LockedWorkspace;
use test_case::test_case;
use testutils::{
Expand Down Expand Up @@ -86,7 +87,6 @@ fn test_checkout_file_transitions(backend: TestRepoBackend) {
// Executable, but same content as Normal, to test transition where only the bit changed
ExecutableNormalContent,
Conflict,
#[cfg_attr(windows, allow(dead_code))]
Symlink,
Tree,
GitSubmodule,
Expand Down Expand Up @@ -176,7 +176,6 @@ fn test_checkout_file_transitions(backend: TestRepoBackend) {
Kind::Conflict,
Kind::Tree,
];
#[cfg(unix)]
kinds.push(Kind::Symlink);
if backend == TestRepoBackend::Git {
kinds.push(Kind::GitSubmodule);
Expand All @@ -198,10 +197,32 @@ fn test_checkout_file_transitions(backend: TestRepoBackend) {
let right_commit = commit_with_tree(&store, right_tree_id.clone());

let ws = &mut test_workspace.workspace;
ws.check_out(repo.op_id().clone(), None, &left_commit)
.unwrap();
ws.check_out(repo.op_id().clone(), None, &right_commit)
.unwrap();
match ws.check_out(repo.op_id().clone(), None, &left_commit) {
Err(CheckoutError::Other { err: outer_err, .. }) => {
match outer_err.downcast::<SymlinkError>() {
Ok(inner_err)
if matches!(*inner_err, SymlinkError::DeveloperModeNotEnabledError) =>
{
return
}
result => assert!(result.is_ok(), "{}", result.unwrap_err()),
}
}
result => assert!(result.is_ok(), "{}", result.unwrap_err()),
}
match ws.check_out(repo.op_id().clone(), None, &right_commit) {
Err(CheckoutError::Other { err: outer_err, .. }) => {
match outer_err.downcast::<SymlinkError>() {
Ok(inner_err)
if matches!(*inner_err, SymlinkError::DeveloperModeNotEnabledError) =>
{
return
}
result => assert!(result.is_ok(), "{}", result.unwrap_err()),
}
}
result => assert!(result.is_ok(), "{}", result.unwrap_err()),
}

// Check that the working copy is clean.
let new_tree = test_workspace.snapshot().unwrap();
Expand Down Expand Up @@ -768,11 +789,7 @@ fn test_gitignores_ignored_directory_already_tracked() {
testutils::write_executable_file(&mut tree_builder, path, contents);
}
Kind::Symlink => {
if cfg!(unix) {
testutils::write_symlink(&mut tree_builder, path, contents);
} else {
testutils::write_normal_file(&mut tree_builder, path, contents);
}
testutils::write_symlink(&mut tree_builder, path, contents);
}
}
}
Expand Down Expand Up @@ -806,7 +823,19 @@ fn test_gitignores_ignored_directory_already_tracked() {

// Check out the tree with the files in `ignored/`
let ws = &mut test_workspace.workspace;
ws.check_out(repo.op_id().clone(), None, &commit).unwrap();
match ws.check_out(repo.op_id().clone(), None, &commit) {
Err(CheckoutError::Other { err: outer_err, .. }) => {
match outer_err.downcast::<SymlinkError>() {
Ok(inner_err)
if matches!(*inner_err, SymlinkError::DeveloperModeNotEnabledError) =>
{
return
}
result => assert!(result.is_ok(), "{}", result.unwrap_err()),
}
}
result => assert!(result.is_ok(), "{}", result.unwrap_err()),
}

// Make some changes inside the ignored directory and check that they are
// detected when we snapshot. The files that are still there should not be
Expand All @@ -819,15 +848,9 @@ fn test_gitignores_ignored_directory_already_tracked() {
)
.unwrap();
std::fs::remove_file(deleted_executable_path.to_fs_path(&workspace_root)).unwrap();
if cfg!(unix) {
let fs_path = modified_symlink_path.to_fs_path(&workspace_root);
std::fs::remove_file(&fs_path).unwrap();
#[cfg(unix)]
std::os::unix::fs::symlink("modified", &fs_path).unwrap();
} else {
let fs_path = modified_symlink_path.to_fs_path(&workspace_root);
std::fs::write(fs_path, "modified").unwrap();
}
let fs_path = modified_symlink_path.to_fs_path(&workspace_root);
std::fs::remove_file(&fs_path).unwrap();
try_symlink("modified", &fs_path).unwrap();
std::fs::remove_file(deleted_symlink_path.to_fs_path(&workspace_root)).unwrap();
let new_tree = test_workspace.snapshot().unwrap();
let expected_tree = create_tree_with_kind(&[
Expand Down Expand Up @@ -939,7 +962,6 @@ fn test_gitsubmodule() {
);
}

#[cfg(unix)]
#[test]
fn test_existing_directory_symlink() {
let settings = testutils::user_settings();
Expand All @@ -949,7 +971,11 @@ fn test_existing_directory_symlink() {

// Creates a symlink in working directory, and a tree that will add a file under
// the symlinked directory.
std::os::unix::fs::symlink("..", workspace_root.join("parent")).unwrap();
match try_symlink("..", workspace_root.join("parent")) {
Err(SymlinkError::DeveloperModeNotEnabledError) => return,
result => assert!(result.is_ok(), "{}", result.unwrap_err()),
};

let file_path = RepoPath::from_internal_string("parent/escaped");
let tree = create_tree(repo, &[(file_path, "contents")]);
let commit = commit_with_tree(repo.store(), tree.id());
Expand Down

0 comments on commit 9a439e3

Please sign in to comment.