Skip to content

Commit f2131e2

Browse files
committed
Fix tests on nightly
Nightly has richer IO error kinds
1 parent 9b164ce commit f2131e2

File tree

4 files changed

+77
-31
lines changed

4 files changed

+77
-31
lines changed

.github/workflows/rust.yml

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Rust
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66
pull_request:
7-
branches: [ master ]
7+
branches: [master]
88
jobs:
99
build-unix:
1010
runs-on: ${{ matrix.os }}-latest
@@ -13,10 +13,10 @@ jobs:
1313
channel: [stable, beta, nightly]
1414
os: [ubuntu, macos]
1515
steps:
16-
- uses: actions/checkout@v2
17-
- run: rustup default ${{ matrix.channel }}
18-
- run: cargo build --verbose --all-targets
19-
- run: cargo test
16+
- uses: actions/checkout@v2
17+
- run: rustup default ${{ matrix.channel }}
18+
- run: cargo build --verbose --all-targets
19+
- run: cargo test
2020
build-windows:
2121
runs-on: windows-latest
2222
strategy:
@@ -31,13 +31,16 @@ jobs:
3131
- arch: i686
3232
variant: gnu
3333
steps:
34-
- uses: actions/checkout@v2
35-
- run: choco install msys2
36-
if: matrix.variant == 'gnu'
37-
- run: rustup default ${{ matrix.channel }}
38-
- run: rustup target add ${{ matrix.arch }}-pc-windows-${{ matrix.variant }}
39-
- name: Build
40-
run: cargo build --verbose --target ${{ matrix.arch }}-pc-windows-${{ matrix.variant }}
41-
- name: Run tests
42-
if: matrix.arch != 'aarch64'
43-
run: cargo test --verbose --target ${{ matrix.arch }}-pc-windows-${{ matrix.variant }}
34+
- uses: actions/checkout@v2
35+
- run: choco install msys2
36+
if: matrix.variant == 'gnu'
37+
- run: rustup default ${{ matrix.channel }}
38+
- run: rustup target add ${{ matrix.arch }}-pc-windows-${{ matrix.variant }}
39+
- name: Build
40+
run: cargo build --verbose --target ${{ matrix.arch }}-pc-windows-${{ matrix.variant }}
41+
- name: Run tests (nightly)
42+
if: (matrix.arch != 'aarch64') && (matrix.channel == 'nightly')
43+
run: cargo test --verbose --target ${{ matrix.arch }}-pc-windows-${{ matrix.variant }} --features nightly
44+
- name: Run tests
45+
if: (matrix.arch != 'aarch64') && (matrix.channel != 'nightly')
46+
run: cargo test --verbose --target ${{ matrix.arch }}-pc-windows-${{ matrix.variant }}

Cargo.toml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
[package]
2-
authors = ["Erin P. <[email protected]>", "Robert C. <[email protected]>"]
2+
authors = [
3+
"Erin P. <[email protected]>",
4+
"Robert C. <[email protected]>",
5+
]
36
categories = ["filesystem"]
47
description = "A safe, reliable implementation of remove_dir_all for Windows"
58
edition = "2018"
@@ -17,11 +20,24 @@ readme = "README.md"
1720
repository = "https://github.com/XAMPPRocky/remove_dir_all.git"
1821
version = "0.7.1-alpha.0"
1922

23+
[features]
24+
default = []
25+
nightly = []
26+
27+
[dependencies]
28+
cfg-if = "1.0.0"
29+
2030
[target.'cfg(windows)'.dependencies]
2131
log = "0.4.11"
2232
num_cpus = "1.13"
2333
rayon = "1.4"
24-
winapi = {version = "0.3", features = ["std", "errhandlingapi", "winerror", "fileapi", "winbase"]}
34+
winapi = { version = "0.3", features = [
35+
"std",
36+
"errhandlingapi",
37+
"winerror",
38+
"fileapi",
39+
"winbase",
40+
] }
2541

2642
[target.'cfg(not(windows))'.dependencies]
2743
libc = "0.2"

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! It also provides `remove_dir_contents` and `ensure_empty_dir`
77
//! for both Unix and Windows.
88
9+
#![cfg_attr(feature = "nightly", feature(io_error_more))]
910
#![deny(missing_debug_implementations)]
1011
#![deny(missing_docs)]
1112
#![deny(rust_2018_idioms)]

src/portable.rs

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,24 @@ pub fn remove_dir_contents<P: AsRef<Path>>(path: P) -> io::Result<()> {
2828
/// a symlink to one).
2929
pub fn ensure_empty_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
3030
match std::fs::create_dir(&path) {
31-
Err(e) if e.kind() == io::ErrorKind::AlreadyExists
32-
=> remove_dir_contents(path),
31+
Err(e) if e.kind() == io::ErrorKind::AlreadyExists => remove_dir_contents(path),
3332
otherwise => otherwise,
3433
}
3534
}
3635

3736
#[cfg(test)]
3837
mod test {
39-
use tempfile::TempDir;
38+
use crate::ensure_empty_dir;
4039
use crate::remove_dir_all;
4140
use crate::remove_dir_contents;
42-
use crate::ensure_empty_dir;
4341
use std::fs::{self, File};
44-
use std::path::PathBuf;
4542
use std::io;
43+
use std::path::PathBuf;
44+
use tempfile::TempDir;
4645

47-
fn expect_failure<T>(k: io::ErrorKind, r: io::Result<T>) -> io::Result<()> {
46+
fn expect_failure<T>(k: &[io::ErrorKind], r: io::Result<T>) -> io::Result<()> {
4847
match r {
49-
Err(e) if e.kind() == k => Ok(()),
48+
Err(e) if k.contains(&e.kind()) => Ok(()),
5049
Err(e) => Err(e),
5150
Ok(_) => Err(io::Error::new(
5251
io::ErrorKind::Other,
@@ -61,39 +60,66 @@ mod test {
6160
file: PathBuf,
6261
}
6362

63+
/// Create test setup: t.mkdir/file all in a tempdir.
6464
fn prep() -> Result<Prep, io::Error> {
6565
let tmp = TempDir::new()?;
6666
let ours = tmp.path().join("t.mkdir");
6767
let file = ours.join("file");
6868
fs::create_dir(&ours)?;
6969
File::create(&file)?;
7070
File::open(&file)?;
71-
Ok(Prep { _tmp: tmp, ours, file })
71+
Ok(Prep {
72+
_tmp: tmp,
73+
ours,
74+
file,
75+
})
7276
}
7377

7478
#[test]
7579
fn mkdir_rm() -> Result<(), io::Error> {
7680
let p = prep()?;
7781

78-
expect_failure(io::ErrorKind::Other, remove_dir_contents(&p.file))?;
82+
expect_failure(
83+
{
84+
cfg_if::cfg_if! {
85+
if #[cfg(feature="nightly")] {
86+
&[io::ErrorKind::NotADirectory, io::ErrorKind::Other]
87+
} else {
88+
&[io::ErrorKind::Other]
89+
}
90+
}
91+
},
92+
remove_dir_contents(&p.file),
93+
)?;
7994

8095
remove_dir_contents(&p.ours)?;
81-
expect_failure(io::ErrorKind::NotFound, File::open(&p.file))?;
96+
expect_failure(&[io::ErrorKind::NotFound], File::open(&p.file))?;
8297

8398
remove_dir_contents(&p.ours)?;
8499
remove_dir_all(&p.ours)?;
85-
expect_failure(io::ErrorKind::NotFound, remove_dir_contents(&p.ours))?;
100+
expect_failure(&[io::ErrorKind::NotFound], remove_dir_contents(&p.ours))?;
86101
Ok(())
87102
}
88103

89104
#[test]
90105
fn ensure_rm() -> Result<(), io::Error> {
91106
let p = prep()?;
92107

93-
expect_failure(io::ErrorKind::Other, ensure_empty_dir(&p.file))?;
108+
expect_failure(
109+
{
110+
cfg_if::cfg_if! {
111+
if #[cfg(feature="nightly")] {
112+
&[io::ErrorKind::NotADirectory, io::ErrorKind::Other]
113+
} else {
114+
&[io::ErrorKind::Other]
115+
}
116+
}
117+
},
118+
ensure_empty_dir(&p.file),
119+
)?;
94120

95121
ensure_empty_dir(&p.ours)?;
96-
expect_failure(io::ErrorKind::NotFound, File::open(&p.file))?;
122+
expect_failure(&[io::ErrorKind::NotFound], File::open(&p.file))?;
97123
ensure_empty_dir(&p.ours)?;
98124

99125
remove_dir_all(&p.ours)?;

0 commit comments

Comments
 (0)