Merge pull request #8 from haraldh/CI

CI update + Doc test fix
This commit is contained in:
Harald Hoyer 2023-07-27 14:07:21 +02:00 committed by GitHub
commit 06da605462
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 65 additions and 45 deletions

View file

@ -1,22 +1,43 @@
name: coverage
name: coverage
on:
# Trigger the workflow on push or pull request,
# but only for the master branch
push:
branches:
- master
pull_request:
branches:
- master
release:
types:
- created
on: [ "push" , "pull_request" ]
jobs:
test:
name: coverage
runs-on: ubuntu-latest
container:
image: xd009642/tarpaulin
options: --security-opt seccomp=unconfined
name: coverage
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Generate code coverage
run: |
cargo tarpaulin --verbose --workspace --timeout 120 --out Lcov --output-dir coverage
- name: Upload to coveralls
uses: coverallsapp/github-action@master
- uses: actions/checkout@v1
- uses: dtolnay/rust-toolchain@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
target: x86_64-unknown-linux-gnu
toolchain: nightly
components: llvm-tools-preview
- name: Install cargo-llvm-cov
run: >
curl -LsSf 'https://github.com/taiki-e/cargo-llvm-cov/releases/download/v0.5.23/cargo-llvm-cov-x86_64-unknown-linux-musl.tar.gz'
| tar xzf -
&& mv cargo-llvm-cov $HOME/.cargo/bin
- name: Run cargo-llvm-cov
run: cargo llvm-cov --doctests --all --all-features --lcov --output-path lcov.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
directory: ./
fail_ci_if_error: false
files: ./lcov.info
verbose: true

View file

@ -26,10 +26,9 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Install toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.version }}
default: true
profile: minimal
- name: Build
run: cargo build --verbose
@ -45,7 +44,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
components: rustfmt
toolchain: stable
@ -61,7 +60,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
components: clippy
toolchain: stable
@ -77,7 +76,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
profile: minimal

View file

@ -18,7 +18,7 @@ fn func3() -> Result<(), Box<dyn Error + Send + Sync>> {
derive_str_context!(Func2Error);
fn func2() -> ChainResult<(), Func2Error> {
func3().context(Func2Error(format!("func2 error: calling func3")))?;
func3().context(Func2Error("func2 error: calling func3".to_string()))?;
Ok(())
}

View file

@ -84,7 +84,7 @@ pub mod mycrate {
let filename = "bar.txt";
do_some_io(filename).map_context(|e| ErrorKind::from_io_error(&e, filename.into()))?;
do_some_io(filename).map_context(|e| ErrorKind::from_io_error(e, filename.into()))?;
do_some_io(filename).map_context(|_| ErrorKind::IO(filename.into()))?;
do_some_io(filename).map_context(|e| ErrorKind::from(e))?;

View file

@ -15,7 +15,7 @@ fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
}
fn func1() -> Result<(), Box<dyn Error + Send + Sync>> {
func2().context(format!("func1 error"))?;
func2().context("func1 error")?;
Ok(())
}

View file

@ -19,7 +19,7 @@ fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
derive_str_context!(Func1Error);
fn func1() -> Result<(), Box<dyn Error + Send + Sync>> {
func2().context(Func1Error(format!("func1 error")))?;
func2().context(Func1Error("func1 error".to_string()))?;
Ok(())
}

View file

@ -20,7 +20,7 @@ derive_str_context!(Func1ErrorFunc2);
derive_str_context!(Func1ErrorIO);
fn func1() -> Result<(), Box<dyn Error + Send + Sync>> {
func2().context(Func1ErrorFunc2(format!("func1 error calling func2")))?;
func2().context(Func1ErrorFunc2("func1 error calling func2".to_string()))?;
let filename = "bar.txt";
do_some_io().context(Func1ErrorIO(format!("Error reading '{}'", filename)))?;
Ok(())

View file

@ -60,17 +60,16 @@
//! fn main() {
//! if let Err(e) = process_config_file() {
//! eprintln!("Error:\n{:?}", e);
//! # assert_eq!(
//! # format!("{:?}\n", e),
//! # "\
//! # src/lib.rs:16:51: read the config file\n\
//! # Caused by:\n\
//! # src/lib.rs:9:47: Reading file: \"foo.txt\"\n\
//! # Caused by:\n\
//! # Os { code: 2, kind: NotFound, message: \"No such file or directory\" }\n\
//! # ",
//! # );
//! # let s = format!("{:?}", e);
//! # let lines = s.lines().collect::<Vec<_>>();
//! # assert_eq!(lines.len(), 5);
//! # assert!(lines[0].starts_with("src/lib.rs:"));
//! # assert_eq!(lines[1], "Caused by:");
//! # assert!(lines[2].starts_with("src/lib.rs:"));
//! # assert_eq!(lines[3], "Caused by:");
//! # assert_eq!(lines[4], "Os { code: 2, kind: NotFound, message: \"No such file or directory\" }");
//! }
//! # else { panic!(); }
//! }
//! ```
//!
@ -103,7 +102,6 @@
//! Read the [Tutorial](https://haraldh.github.io/chainerror/tutorial1.html)
#![deny(clippy::all)]
#![deny(clippy::integer_arithmetic)]
#![allow(clippy::needless_doctest_main)]
#![deny(missing_docs)]
@ -198,7 +196,9 @@ impl<T: 'static + Display + Debug> ChainError<T> {
/// ```
#[inline]
pub fn find_cause<U: Error + 'static>(&self) -> Option<&U> {
self.iter().filter_map(Error::downcast_ref::<U>).next()
self.iter()
.filter_map(<dyn Error>::downcast_ref::<U>)
.next()
}
/// Find the first error cause of type `ChainError<U>`, if any exists
@ -220,7 +220,7 @@ impl<T: 'static + Display + Debug> ChainError<T> {
#[inline]
pub fn find_chain_cause<U: Error + 'static>(&self) -> Option<&ChainError<U>> {
self.iter()
.filter_map(Error::downcast_ref::<ChainError<U>>)
.filter_map(<dyn Error>::downcast_ref::<ChainError<U>>)
.next()
}
@ -428,7 +428,7 @@ impl<U: 'static + Display + Debug> ChainErrorDown for ChainError<U> {
#[allow(clippy::cast_ptr_alignment)]
unsafe {
#[allow(trivial_casts)]
Some(&*(self as *const dyn Error as *const &ChainError<T>))
Some(*(self as *const dyn Error as *const &ChainError<T>))
}
} else {
None

View file

@ -18,13 +18,13 @@ fn test_iter() -> Result<(), Box<dyn Error + Send + Sync>> {
let mut res = String::new();
for e in err.iter() {
write!(res, "{}", e.to_string())?;
write!(res, "{}", e)?;
}
assert_eq!(res, "654321entity not found");
let io_error: Option<&io::Error> = err
.iter()
.filter_map(Error::downcast_ref::<io::Error>)
.filter_map(<dyn Error>::downcast_ref::<io::Error>)
.next();
assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound);
@ -50,7 +50,7 @@ fn test_iter() -> Result<(), Box<dyn Error + Send + Sync>> {
let io_error: Option<&io::Error> = err
.iter()
.filter_map(Error::downcast_ref::<io::Error>)
.filter_map(<dyn Error>::downcast_ref::<io::Error>)
.next();
assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound);
@ -88,7 +88,7 @@ fn test_root_cause() -> Result<(), Box<dyn Error + Send + Sync>> {
let err = err.err().unwrap();
let err: Option<&(dyn std::error::Error + 'static)> = err.root_cause();
let io_error: Option<&io::Error> = err.and_then(Error::downcast_ref::<io::Error>);
let io_error: Option<&io::Error> = err.and_then(<dyn Error>::downcast_ref::<io::Error>);
assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound);