-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge #130 into openSUSE/libpathrs:main
Aleksa Sarai (4): errors: document and export ErrorKind errors: hide internal error types from ErrorKind capi: error: map pure-Rust errors into equivalent errno values tests: unify error checking for operations LGTMs: cyphar
- Loading branch information
Showing
12 changed files
with
326 additions
and
163 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* libpathrs: safe path resolution on Linux | ||
* Copyright (C) 2019-2024 Aleksa Sarai <[email protected]> | ||
* Copyright (C) 2019-2024 SUSE LLC | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at your | ||
* option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
use crate::{error::ErrorKind, tests::traits::ErrorImpl}; | ||
|
||
use std::fmt::Debug; | ||
|
||
use anyhow::Error; | ||
|
||
pub(in crate::tests) fn check_err<T1, Err1, T2>( | ||
result: &Result<T1, Err1>, | ||
expected: &Result<T2, ErrorKind>, | ||
) -> Result<(), Error> | ||
where | ||
T1: Debug, | ||
Err1: ErrorImpl, | ||
T2: Debug, | ||
{ | ||
let result = result.as_ref(); | ||
let expected = expected.as_ref(); | ||
|
||
match (result, expected) { | ||
(Err(error), Err(expected_kind)) => { | ||
let kind = error.kind(); | ||
let (result_errno, expected_errno) = (kind.errno(), expected_kind.errno()); | ||
|
||
if kind != *expected_kind && result_errno != expected_errno { | ||
anyhow::bail!( | ||
"expected error {expected_kind:?} (errno: {expected_errno:?}) but got {error:?} (kind: {kind:?}, errno: {result_errno:?})" | ||
); | ||
} | ||
} | ||
(Ok(_), Ok(_)) => (), | ||
(result, expected) => anyhow::bail!("expected {expected:?} but got {result:?}"), | ||
} | ||
Ok(()) | ||
} |
Oops, something went wrong.