forked from pjd/pjdfstest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): add eexist tests (#130)
- Loading branch information
1 parent
8df0b9a
commit bf1a04b
Showing
10 changed files
with
160 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub(super) mod eexist; | ||
pub(super) mod efault; | ||
pub(super) mod eloop; | ||
pub(super) mod enametoolong; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/// Create a test case which asserts that the sycall | ||
/// returns EEXIST if the named file exists. | ||
/// There are multiple forms for this macro: | ||
/// | ||
/// - A basic form which takes the syscall, and optionally a `~path` argument | ||
/// to indicate where the `path` argument should be substituted if the path | ||
/// is not the only argument taken by the syscall. | ||
/// | ||
/// ``` | ||
/// // `unlink` accepts only a path as argument. | ||
/// eloop_comp_test_case!(unlink); | ||
/// // `chflags` takes a path and the flags to set as arguments. | ||
/// // We need to add `~path` where the path argument should normally be taken. | ||
/// eloop_comp_test_case!(chflags(~path, FileFlags::empty())); | ||
/// ``` | ||
/// | ||
/// - A more complex form which takes multiple functions | ||
/// with the context and the path as arguments, for syscalls | ||
/// requiring to compute other arguments. | ||
/// | ||
/// ``` | ||
/// eloop_comp_test_case!(chown, |ctx: &mut TestContext, path: &Path| { | ||
/// let user = ctx.get_new_user(); | ||
/// chown(path, Some(user.uid), None) | ||
/// }) | ||
/// ```` | ||
macro_rules! eexist_file_exists_test_case { | ||
($syscall: ident, $($f: expr),+ $(; $attrs:tt )?) => { | ||
crate::test_case! { | ||
#[doc = concat!(stringify!($syscall), | ||
" returns EEXIST if the named file exists")] | ||
eexist_file_exists $(, $attrs )? => [Regular, Dir, Fifo, Block, Char, Socket, Symlink(None)] | ||
} | ||
fn eexist_file_exists(ctx: &mut crate::context::TestContext, | ||
ft: crate::context::FileType) { | ||
let path = ctx.create(ft).unwrap(); | ||
$( assert_eq!($f(ctx, &path), Err(nix::errno::Errno::EEXIST)); )+ | ||
} | ||
}; | ||
|
||
($syscall: ident $( ($( $($before:expr),* ,)? ~path $(, $($after:expr),*)?) )?) => { | ||
eexist_file_exists_test_case!($syscall, |_: &mut $crate::context::TestContext, | ||
path: &std::path::Path| { | ||
$syscall($( $($($before),* ,)? )? path $( $(, $($after),*)? )?) | ||
}); | ||
}; | ||
} | ||
|
||
pub(crate) use eexist_file_exists_test_case; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters