artifactize-tools 0.27.0

Portable scoped tools and safe file access for artifactize.
Documentation
use super::path_text;

// reason: only Unix allows '\' in file names.
#[cfg(unix)]
#[test]
fn literal_backslash_in_a_file_name_is_not_a_separator() {
    let root = crate::test_os::tempdir();
    let path = crate::test_os::file_with_backslash(root.path());
    assert_eq!(
        path_text(std::path::Path::new(path.file_name().unwrap())),
        r"input\name"
    );
}

// Windows supports prefixes and roots that are not absolute in Rust's Path grammar.
#[cfg(windows)]
#[test]
fn pinned_owners_refuse_drive_relative_and_rooted_paths() {
    use crate::scope::Target;
    for path in [r"C:owner", r"\owner"] {
        assert!(
            Target::try_from(path)
                .unwrap_err()
                .to_string()
                .contains("relative to its declared root")
        );
    }
}

// Only the Windows verbatim namespace preserves trailing dots in a file name.
#[cfg(windows)]
#[test]
fn a_pin_with_a_win32_alias_is_not_returned_as_an_ordinary_path() {
    use crate::scope::{open_scoped, scoped_path};
    let root = crate::test_os::tempdir();
    let root = crate::test_os::trailing_dot_alias(root.path());
    assert!(open_scoped(&root, "literal.").is_ok());
    assert!(
        scoped_path(&root, std::path::Path::new("literal."))
            .unwrap_err()
            .to_string()
            .contains("ordinary Windows path")
    );
}

// reason: Windows native paths use backslash separators.
#[cfg(windows)]
#[test]
fn native_separators_are_rendered_as_slashes() {
    assert_eq!(
        path_text(std::path::Path::new(r"C:\input\name")),
        "C:/input/name"
    );
}

// reason: Windows canonical paths can carry verbatim disk and UNC prefixes.
#[cfg(windows)]
#[test]
fn verbatim_paths_render_without_the_native_prefix() {
    assert_eq!(
        path_text(std::path::Path::new(r"\\?\C:\input\name")),
        "C:/input/name"
    );
    assert_eq!(
        path_text(std::path::Path::new(r"\\?\UNC\server\share\input")),
        "//server/share/input"
    );
}