From deed38f441ebef7643ecdaf6ad04b89de74bc0ce Mon Sep 17 00:00:00 2001 From: Martin Bammer Date: Fri, 25 Oct 2024 22:24:12 +0200 Subject: [PATCH] Fix tests on Windows --- .github/workflows/ci.yml | 109 --------------------------------------- scandir/tests/common.rs | 4 +- scandir/tests/count.rs | 20 ++++--- scandir/tests/scandir.rs | 46 +++++++++++++++++ scandir/tests/walk.rs | 30 +++++++++-- 5 files changed, 88 insertions(+), 121 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1bbd73a..bbba916 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,34 +4,6 @@ name: Continuous Integration jobs: - check: - name: Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - - uses: actions-rs/cargo@v1 - with: - command: check - - clippy_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - components: clippy - override: true - - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-features --all-targets -- -A clippy::unnecessary_wraps - test: name: Run cargo test on ${{ matrix.os }} runs-on: ${{ matrix.os }} @@ -51,84 +23,3 @@ jobs: run: | cd scandir cargo test - - build_wheels: - name: Build wheels on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [windows-latest, ubuntu-latest, macos-14] - - env: - CIBW_BUILD_VERBOSITY: 1 - CIBW_BEFORE_ALL_LINUX: "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly -y && yum install -y openssl-devel" - CIBW_SKIP: "cp36-* cp37-* pp* *-win32 *-pypy* *-musllinux*" - CIBW_TEST_SKIP: "cp38-macosx_*:arm64" - # Build separate wheels for macOS's different architectures. - CIBW_ARCHS_MACOS: "arm64" - # Build only on Linux architectures that don't need qemu emulation. - CIBW_ARCHS_LINUX: "x86_64" - # Run the test suite after each build. - CIBW_ENVIRONMENT: 'PATH="$PATH:$HOME/.cargo/bin"' - CIBW_TEST_REQUIRES: "pytest" - CIBW_TEST_COMMAND: pytest {package}/tests - - steps: - - uses: actions/checkout@v4 - - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - - - if: runner.os == 'Windows' - run: | - echo 'PATH=/c/Python38:/c/Python38/Scripts:$PATH' >> $GITHUB_ENV - echo 'RUSTFLAGS=-Ctarget-feature=+crt-static' >> $GITHUB_ENV - echo 'RUSTFLAGS=-Ctarget-feature=+crt-static' >> $GITHUB_ENV - echo 'CIBW_BEFORE_BUILD=python -m pip install --upgrade pip' >> $GITHUB_ENV - - - if: runner.os != 'Linux' - name: Setup env when not using docker - run: | - python -m pip install --upgrade wheel setuptools setuptools-rust - - - uses: PyO3/maturin-action@v1 - with: - working-directory: ./pyscandir - command: build - args: --release - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.x" - cache: pip - cache-dependency-path: ".github/workflows/wheels.yml" - - - name: Install dependencies - run: | - python -m pip install cibuildwheel - python -m pip install -U twine - - - name: Build wheels - run: | - cd pyscandir - maturin build --sdist --interpreter - python -m cibuildwheel --output-dir wheelhouse - - - name: Upload as build artifacts - uses: actions/upload-artifact@v3 - with: - name: wheels - path: target/wheels/*.whl - if-no-files-found: error - - - name: Publish package to TestPyPI - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }} - run: | - twine upload --repository-url https://test.pypi.org/legacy/ --skip-existing target/wheels/* diff --git a/scandir/tests/common.rs b/scandir/tests/common.rs index cf674b5..763fb53 100644 --- a/scandir/tests/common.rs +++ b/scandir/tests/common.rs @@ -30,8 +30,8 @@ pub fn create_temp_file_tree( dircnt: u32, filecnt: u32, hlinkcnt: u32, - slinkcnt: u32, - pipecnt: u32, + #[cfg(unix)] slinkcnt: u32, + #[cfg(unix)] pipecnt: u32, ) -> Result { let temp_dir = setup(); for i in 1..=dircnt { diff --git a/scandir/tests/count.rs b/scandir/tests/count.rs index 5457dc9..8ac61cb 100644 --- a/scandir/tests/count.rs +++ b/scandir/tests/count.rs @@ -6,7 +6,10 @@ mod common; #[test] fn test_count() -> Result<(), Error> { + #[cfg(unix)] let temp_dir = common::create_temp_file_tree(3, 3, 4, 5, 6, 7)?; + #[cfg(windows)] + let temp_dir = common::create_temp_file_tree(3, 3, 4, 5)?; let count = Count::new(temp_dir.path())?.collect()?; assert!(count.errors.is_empty()); assert!(count.duration > 0.0); @@ -14,16 +17,20 @@ fn test_count() -> Result<(), Error> { assert_eq!(63, count.files); assert_eq!(0, count.devices); #[cfg(unix)] - assert_eq!(54, count.slinks); + { + assert_eq!(54, count.slinks); + assert_eq!(0, count.pipes); + } assert_eq!(0, count.hlinks); - #[cfg(unix)] - assert_eq!(0, count.pipes); common::cleanup(temp_dir) } #[test] fn test_count_extended() -> Result<(), Error> { + #[cfg(unix)] let temp_dir = common::create_temp_file_tree(3, 3, 4, 5, 6, 7)?; + #[cfg(windows)] + let temp_dir = common::create_temp_file_tree(3, 3, 4, 5)?; let count = Count::new(temp_dir.path())?.extended(true).collect()?; assert!(count.errors.is_empty()); assert!(count.duration > 0.0); @@ -31,9 +38,10 @@ fn test_count_extended() -> Result<(), Error> { assert_eq!(36, count.files); assert_eq!(0, count.devices); #[cfg(unix)] - assert_eq!(54, count.slinks); + { + assert_eq!(54, count.slinks); + assert_eq!(63, count.pipes); + } assert_eq!(27, count.hlinks); - #[cfg(unix)] - assert_eq!(63, count.pipes); common::cleanup(temp_dir) } diff --git a/scandir/tests/scandir.rs b/scandir/tests/scandir.rs index 61bff48..05a22a6 100644 --- a/scandir/tests/scandir.rs +++ b/scandir/tests/scandir.rs @@ -6,15 +6,52 @@ mod common; #[test] fn test_scandir() -> Result<(), Error> { + #[cfg(unix)] let temp_dir = common::create_temp_file_tree(3, 3, 4, 5, 6, 7)?; + #[cfg(windows)] + let temp_dir = common::create_temp_file_tree(3, 3, 4, 5)?; + let scandir = Scandir::new(temp_dir.path(), Some(true))?; + let mut scandir = scandir.skip_hidden(false); + let entries = scandir.collect()?; + #[cfg(unix)] + assert_eq!(210, entries.results.len()); + #[cfg(windows)] + assert_eq!(93, entries.results.len()); + assert_eq!(0, entries.errors.len()); + match entries.results.first().unwrap() { + ScandirResult::DirEntry(d) => { + assert_eq!("dir1", &d.path); + assert!(d.is_dir); + #[cfg(unix)] + assert_eq!(4096, d.st_size); + #[cfg(windows)] + assert_eq!(0, d.st_size); + } + _ => panic!("Wrong type"), + } + common::cleanup(temp_dir) +} + +#[test] +fn test_scandir_skip_hidden() -> Result<(), Error> { + #[cfg(unix)] + let temp_dir = common::create_temp_file_tree(3, 3, 4, 5, 6, 7)?; + #[cfg(windows)] + let temp_dir = common::create_temp_file_tree(3, 3, 4, 5)?; let entries = Scandir::new(temp_dir.path(), Some(true))?.collect()?; + #[cfg(unix)] assert_eq!(192, entries.results.len()); + #[cfg(windows)] + assert_eq!(75, entries.results.len()); assert_eq!(0, entries.errors.len()); match entries.results.first().unwrap() { ScandirResult::DirEntry(d) => { assert_eq!("dir1", &d.path); assert!(d.is_dir); + #[cfg(unix)] assert_eq!(4096, d.st_size); + #[cfg(windows)] + assert_eq!(0, d.st_size); } _ => panic!("Wrong type"), } @@ -23,17 +60,26 @@ fn test_scandir() -> Result<(), Error> { #[test] fn test_scandir_extended() -> Result<(), Error> { + #[cfg(unix)] let temp_dir = common::create_temp_file_tree(3, 3, 4, 5, 6, 7)?; + #[cfg(windows)] + let temp_dir = common::create_temp_file_tree(3, 3, 4, 5)?; let entries = Scandir::new(temp_dir.path(), Some(true))? .return_type(ReturnType::Ext) .collect()?; + #[cfg(unix)] assert_eq!(192, entries.results.len()); + #[cfg(windows)] + assert_eq!(75, entries.results.len()); assert_eq!(0, entries.errors.len()); match entries.results.first().unwrap() { ScandirResult::DirEntryExt(d) => { assert_eq!("dir1", &d.path); assert!(d.is_dir); + #[cfg(unix)] assert_eq!(4096, d.st_size); + #[cfg(windows)] + assert_eq!(0, d.st_size); } _ => panic!("Wrong type"), } diff --git a/scandir/tests/walk.rs b/scandir/tests/walk.rs index 9824dce..db48e47 100644 --- a/scandir/tests/walk.rs +++ b/scandir/tests/walk.rs @@ -6,26 +6,48 @@ mod common; #[test] fn test_walk() -> Result<(), Error> { + #[cfg(unix)] let temp_dir = common::create_temp_file_tree(3, 3, 4, 5, 6, 7)?; + #[cfg(windows)] + let temp_dir = common::create_temp_file_tree(3, 3, 4, 5)?; let toc = Walk::new(temp_dir.path(), Some(true))?.collect()?; assert_eq!(12, toc.dirs.len()); assert_eq!(63, toc.files.len()); - assert_eq!(54, toc.symlinks.len()); - assert_eq!(63, toc.other.len()); + #[cfg(unix)] + { + assert_eq!(54, toc.symlinks.len()); + assert_eq!(63, toc.other.len()); + } + #[cfg(windows)] + { + assert_eq!(0, toc.symlinks.len()); + assert_eq!(0, toc.other.len()); + } assert_eq!(0, toc.errors.len()); common::cleanup(temp_dir) } #[test] fn test_walk_not_skip_hidden() -> Result<(), Error> { + #[cfg(unix)] let temp_dir = common::create_temp_file_tree(3, 3, 4, 5, 6, 7)?; + #[cfg(windows)] + let temp_dir = common::create_temp_file_tree(3, 3, 4, 5)?; let toc = Walk::new(temp_dir.path(), Some(true))? .skip_hidden(false) .collect()?; assert_eq!(12, toc.dirs.len()); assert_eq!(81, toc.files.len()); - assert_eq!(54, toc.symlinks.len()); - assert_eq!(63, toc.other.len()); + #[cfg(unix)] + { + assert_eq!(54, toc.symlinks.len()); + assert_eq!(63, toc.other.len()); + } + #[cfg(windows)] + { + assert_eq!(0, toc.symlinks.len()); + assert_eq!(0, toc.other.len()); + } assert_eq!(0, toc.errors.len()); common::cleanup(temp_dir) }