Repository: nushell/nushell
File: crates/nu-command/tests/commands/ucp.rs (Rust)

Code before:
        let actual = nu!(
        cwd: dirs.test(),
        "cp --force {} {}",
        "f",
        "f"
        );
        actual.err.contains("cp: 'f' and 'f' are the same file");
        assert!(!dirs.test().join("f~").exists());
    });
}

#[test]
fn test_cp_arg_no_clobber() {
    Playground::setup("ucp_test_28", |dirs, _| {
        let src = dirs.fixtures.join("cp").join(TEST_HELLO_WORLD_SOURCE);
        let target = dirs.fixtures.join("cp").join(TEST_HOW_ARE_YOU_SOURCE);
        let target_hash = get_file_hash(target.display());

        let actual = nu!(
        cwd: dirs.root(),
        "cp {} {} --no-clobber",
        src.display(),
        target.display()
        );
        let after_cp_hash = get_file_hash(target.display());
        assert!(actual.err.contains("not replacing"));
        // Check content was not clobbered
        assert_eq!(after_cp_hash, target_hash);
    });
}

#[test]
fn test_cp_arg_no_clobber_twice() {
    Playground::setup("ucp_test_29", |dirs, sandbox| {
        sandbox.with_files(&[
            EmptyFile("source.txt"),
            FileWithContent("source_with_body.txt", "some-body"),
        ]);
        nu!(
        cwd: dirs.root(),
        "cp --no-clobber ucp_test_29/{} ucp_test_29/{}",
        "source.txt",
        "dest.txt"
        );
        assert!(dirs.test().join("dest.txt").exists());

        nu!(
        cwd: dirs.root(),
        "cp --no-clobber ucp_test_29/{} ucp_test_29/{}",
        "source_with_body.txt",
        "dest.txt"

Review comment (bug):
Just checking that there is still an error here, but perhaps with a different message? If so, I think you can just update the expected string. Same for the other test.

Code after:
        let actual = nu!(
        cwd: dirs.test(),
        "cp --force {} {}",
        "f",
        "f"
        );
        actual.err.contains("cp: 'f' and 'f' are the same file");
        assert!(!dirs.test().join("f~").exists());
    });
}

#[test]
fn test_cp_arg_no_clobber() {
    Playground::setup("ucp_test_28", |dirs, _| {
        let src = dirs.fixtures.join("cp").join(TEST_HELLO_WORLD_SOURCE);
        let target = dirs.fixtures.join("cp").join(TEST_HOW_ARE_YOU_SOURCE);
        let target_hash = get_file_hash(target.display());

        let _ = nu!(
            cwd: dirs.root(),
            "cp {} {} --no-clobber",
            src.display(),
            target.display()
        );
        let after_cp_hash = get_file_hash(target.display());
        // Check content was not clobbered
        assert_eq!(after_cp_hash, target_hash);
    });
}

#[test]
fn test_cp_arg_no_clobber_twice() {
    Playground::setup("ucp_test_29", |dirs, sandbox| {
        sandbox.with_files(&[
            EmptyFile("source.txt"),
            FileWithContent("source_with_body.txt", "some-body"),
        ]);
        nu!(
        cwd: dirs.root(),
        "cp --no-clobber ucp_test_29/{} ucp_test_29/{}",
        "source.txt",
        "dest.txt"
        );
        assert!(dirs.test().join("dest.txt").exists());

        nu!(
        cwd: dirs.root(),
        "cp --no-clobber ucp_test_29/{} ucp_test_29/{}",
        "source_with_body.txt",
        "dest.txt"
        );