Sha256: 0186fbba1aa69f71d996595de577476f2a96f932decdd5baa1e88b5971ff7f32

Contents?: true

Size: 1.97 KB

Versions: 8

Compression:

Stored size: 1.97 KB

Contents

use error_code::{ErrorCode, defs};

#[test]
fn check_would_block() {
    let mut error = ErrorCode::new_posix(defs::EAGAIN);
    assert!(error.is_would_block());
    error = ErrorCode::new_posix(defs::EWOULDBLOCK);
    assert!(error.is_would_block());

    error = ErrorCode::new_system(defs::EAGAIN);
    assert!(error.is_would_block());
    error = ErrorCode::new_system(defs::EWOULDBLOCK);
    assert!(error.is_would_block());

    #[cfg(windows)]
    {
        error = ErrorCode::new_system(10035);
        assert!(error.is_would_block());
    }
}

#[cfg(target_pointer_width = "64")]
#[test]
fn size_check_64bit() {
    //On 64bit we suffer from alignment, but Rust optimizes enums quite well so ErrorCode benefits
    //of this optimization, letting its padding to be consumed by Result
    assert_eq!(core::mem::size_of::<ErrorCode>(), 16);
    //This optimization is enabled in latest rust compiler
    //assert_eq!(mem::size_of::<Result<bool, ErrorCode>>(), 16);
}

#[test]
fn it_works() {
    let error = ErrorCode::new_posix(11);
    eprintln!("{:?}", error.to_string());
    eprintln!("{:?}", error);

    let error = ErrorCode::last_posix();
    eprintln!("{}", error);

    let error = ErrorCode::new_system(11);
    eprintln!("{:?}", error.to_string());

    let error = ErrorCode::last_system();
    eprintln!("{}", error);
}

#[test]
fn check_error_code_range() {
    for code in 0..=15999 {
        let error = ErrorCode::new_posix(code);
        eprintln!("{:?}", error.to_string());

        let error = ErrorCode::new_system(code);
        eprintln!("{:?}", error.to_string());

        if code == defs::EWOULDBLOCK || code == defs::EAGAIN {
            assert!(error.is_would_block());
        } else {
            #[cfg(windows)]
            if code == 10035 {
                assert!(error.is_would_block());
            } else {
                assert!(!error.is_would_block());
            }

            #[cfg(not(windows))]
            assert!(!error.is_would_block());
        }
    }
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/error-code-3.3.1/tests/error_code.rs
wasmtime-28.0.0 ./ext/cargo-vendor/error-code-3.3.1/tests/error_code.rs
wasmtime-27.0.0 ./ext/cargo-vendor/error-code-3.3.1/tests/error_code.rs
wasmtime-26.0.0 ./ext/cargo-vendor/error-code-3.3.1/tests/error_code.rs
wasmtime-25.0.2 ./ext/cargo-vendor/error-code-3.2.0/tests/error_code.rs
wasmtime-25.0.1 ./ext/cargo-vendor/error-code-3.2.0/tests/error_code.rs
wasmtime-25.0.0 ./ext/cargo-vendor/error-code-3.2.0/tests/error_code.rs
wasmtime-24.0.0 ./ext/cargo-vendor/error-code-3.2.0/tests/error_code.rs