artifactize-tools 0.27.1

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

#[test]
fn target_is_one_literal_argument() {
    for target in [
        "notes with spaces.md",
        "https://example.invalid/?a=1&b=two words",
        "한글 문서.md",
    ] {
        let mut calls = Vec::new();
        handoff(OsStr::new(target), |argument| {
            calls.push(argument.to_vec());
            33 // ShellExecute's smallest successful handoff value.
        })
        .unwrap();
        assert_eq!(calls.len(), 1);
        assert_eq!(calls[0].last(), Some(&0));
        assert_eq!(
            String::from_utf16(&calls[0][..calls[0].len() - 1]).unwrap(),
            target
        );
    }
}

#[test]
fn invalid_target_never_reaches_the_desktop_and_native_errors_are_reported() {
    let invalid = handoff(OsStr::new("before\0after"), |_| {
        panic!("NUL reached ShellExecute")
    });
    assert_eq!(invalid.unwrap_err().kind(), io::ErrorKind::InvalidInput);
    assert!(
        handoff(OsStr::new("missing.md"), |_| 2)
            .unwrap_err()
            .to_string()
            .contains("code 2")
    );
}