Skip to content

Commit d1f1233

Browse files
authored
Merge pull request #33 from rbtcollins/nightly
Fix tests on nightly
2 parents 9b164ce + 8ccdc7c commit d1f1233

File tree

4 files changed

+86
-38
lines changed

4 files changed

+86
-38
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: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use std::io;
22
use std::path::Path;
33

4-
#[cfg(windows)]
5-
use crate::fs::_remove_dir_contents;
6-
7-
#[cfg(not(windows))]
8-
use crate::unix::_remove_dir_contents;
4+
cfg_if::cfg_if! {
5+
if #[cfg(windows)] {
6+
use crate::fs::_remove_dir_contents;
7+
} else {
8+
use crate::unix::_remove_dir_contents;
9+
}
10+
}
911

1012
/// Deletes the contents of `path`, but not the directory iteself.
1113
///
@@ -28,26 +30,47 @@ pub fn remove_dir_contents<P: AsRef<Path>>(path: P) -> io::Result<()> {
2830
/// a symlink to one).
2931
pub fn ensure_empty_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
3032
match std::fs::create_dir(&path) {
31-
Err(e) if e.kind() == io::ErrorKind::AlreadyExists
32-
=> remove_dir_contents(path),
33+
Err(e) if e.kind() == io::ErrorKind::AlreadyExists => remove_dir_contents(path),
3334
otherwise => otherwise,
3435
}
3536
}
3637

3738
#[cfg(test)]
3839
mod test {
40+
use std::fs::{self, File};
41+
use std::io;
42+
use std::path::PathBuf;
43+
3944
use tempfile::TempDir;
45+
46+
use crate::ensure_empty_dir;
4047
use crate::remove_dir_all;
4148
use crate::remove_dir_contents;
42-
use crate::ensure_empty_dir;
43-
use std::fs::{self, File};
44-
use std::path::PathBuf;
45-
use std::io;
4649

47-
fn expect_failure<T>(k: io::ErrorKind, r: io::Result<T>) -> io::Result<()> {
50+
cfg_if::cfg_if! {
51+
if #[cfg(windows)] {
52+
const ENOTDIR:i32 = winapi::shared::winerror::ERROR_DIRECTORY as i32;
53+
const ENOENT:i32 = winapi::shared::winerror::ERROR_FILE_NOT_FOUND as i32;
54+
} else {
55+
const ENOTDIR:i32 = libc::ENOTDIR;
56+
const ENOENT:i32 = libc::ENOENT;
57+
}
58+
}
59+
60+
/// Expect a particular sort of failure
61+
fn expect_failure<T>(n: &[i32], r: io::Result<T>) -> io::Result<()> {
4862
match r {
49-
Err(e) if e.kind() == k => Ok(()),
50-
Err(e) => Err(e),
63+
Err(e)
64+
if n.iter()
65+
.map(|n| Option::Some(*n))
66+
.any(|n| n == e.raw_os_error()) =>
67+
{
68+
Ok(())
69+
}
70+
Err(e) => {
71+
println!("{e} {:?}, {:?}, {:?}", e.raw_os_error(), e.kind(), n);
72+
Err(e)
73+
}
5174
Ok(_) => Err(io::Error::new(
5275
io::ErrorKind::Other,
5376
"unexpected success".to_string(),
@@ -61,39 +84,44 @@ mod test {
6184
file: PathBuf,
6285
}
6386

87+
/// Create test setup: t.mkdir/file all in a tempdir.
6488
fn prep() -> Result<Prep, io::Error> {
6589
let tmp = TempDir::new()?;
6690
let ours = tmp.path().join("t.mkdir");
6791
let file = ours.join("file");
6892
fs::create_dir(&ours)?;
6993
File::create(&file)?;
7094
File::open(&file)?;
71-
Ok(Prep { _tmp: tmp, ours, file })
95+
Ok(Prep {
96+
_tmp: tmp,
97+
ours,
98+
file,
99+
})
72100
}
73101

74102
#[test]
75103
fn mkdir_rm() -> Result<(), io::Error> {
76104
let p = prep()?;
77105

78-
expect_failure(io::ErrorKind::Other, remove_dir_contents(&p.file))?;
106+
expect_failure(&[ENOTDIR], remove_dir_contents(&p.file))?;
79107

80108
remove_dir_contents(&p.ours)?;
81-
expect_failure(io::ErrorKind::NotFound, File::open(&p.file))?;
109+
expect_failure(&[ENOENT], File::open(&p.file))?;
82110

83111
remove_dir_contents(&p.ours)?;
84112
remove_dir_all(&p.ours)?;
85-
expect_failure(io::ErrorKind::NotFound, remove_dir_contents(&p.ours))?;
113+
expect_failure(&[ENOENT], remove_dir_contents(&p.ours))?;
86114
Ok(())
87115
}
88116

89117
#[test]
90118
fn ensure_rm() -> Result<(), io::Error> {
91119
let p = prep()?;
92120

93-
expect_failure(io::ErrorKind::Other, ensure_empty_dir(&p.file))?;
121+
expect_failure(&[ENOTDIR], ensure_empty_dir(&p.file))?;
94122

95123
ensure_empty_dir(&p.ours)?;
96-
expect_failure(io::ErrorKind::NotFound, File::open(&p.file))?;
124+
expect_failure(&[ENOENT], File::open(&p.file))?;
97125
ensure_empty_dir(&p.ours)?;
98126

99127
remove_dir_all(&p.ours)?;

0 commit comments

Comments
 (0)