diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1dbc5e4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,59 @@ +language: rust + +os: linux + +rust: + - 1.36.0 + - 1.37.0 + - 1.38.0 + - 1.39.0 + - stable + - beta + - nightly + +env: + - WORKER_LIBRARY_FILE=$TRAVIS_BUILD_DIR/libworker.so + +jobs: + allow_failures: + - rust: nightly + include: + # Rustfmt + - rust: stable + install: + - rustup component add rustfmt-preview + before_script: + - cargo fmt --version + script: + - cargo fmt -- --check + + # Clippy + - rust: stable + install: + - rustup component add clippy-preview + script: + # Fail if clippy output contains "error:" or "warning:" + - cargo clippy 2>&1 | tee ./clippy.out && ! grep -qe "error:\|warning:" ./clippy.out + + # Test coverage (with Tarpaulin) + - rust: stable + install: + - RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install cargo-tarpaulin --force + script: + - gcc -c -Wall -Werror -fpic worker.cpp && gcc -shared -o libworker.so worker.o + - cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID + +script: + - gcc -c -Wall -Werror -fpic worker.cpp && gcc -shared -o libworker.so worker.o + - cargo test +cache: + cargo: true +before_cache: + # Travis can't cache files that are not readable by "others" + - chmod -R a+r $HOME/.cargo + +addons: + apt: + packages: + - libssl-dev # Required for tarpaulin + - gcc diff --git a/README.md b/README.md index ac6bb4c..8d90c39 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # C/C++ binding for Rust AMQP Worker Based on [rs_amqp_worker](https://github.com/media-cloud-ai/rs_amqp_worker). +[![Build Status](https://travis-ci.org/media-cloud-ai/c_amqp_worker.svg?branch=master)](https://travis-ci.org/media-cloud-ai/c_amqp_worker) +[![Coverage Status](https://coveralls.io/repos/github/media-cloud-ai/c_amqp_worker/badge.svg?branch=master)](https://coveralls.io/github/media-cloud-ai/c_amqp_worker?branch=master) + ## Build To build the rust application ```bash diff --git a/src/main.rs b/src/main.rs index 490f0e4..583dd00 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,10 +32,12 @@ impl MessageEvent for CWorkerEvent { fn get_version(&self) -> Version { let version = get_worker_function_string_value(GET_VERSION_FUNCTION); - Version::parse(&version).expect(&format!( - "unable to parse version {} (please use SemVer format)", - version - )) + Version::parse(&version).unwrap_or_else(|_| { + panic!( + "unable to parse version {} (please use SemVer format)", + version + ) + }) } fn get_git_version(&self) -> Version { diff --git a/src/worker.rs b/src/worker.rs index 10458d3..8761c81 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -55,13 +55,13 @@ type ProcessFunc = unsafe fn( type CheckLastError = extern "C" fn() -> c_int; -pub static GET_NAME_FUNCTION: &'static str = "get_name"; -pub static GET_SHORT_DESCRIPTION_FUNCTION: &'static str = "get_short_description"; -pub static GET_DESCRIPTION_FUNCTION: &'static str = "get_description"; -pub static GET_VERSION_FUNCTION: &'static str = "get_version"; -pub static GET_PARAMETERS_SIZE_FUNCTION: &'static str = "get_parameters_size"; -pub static GET_PARAMETERS_FUNCTION: &'static str = "get_parameters"; -pub static PROCESS_FUNCTION: &'static str = "process"; +pub static GET_NAME_FUNCTION: &str = "get_name"; +pub static GET_SHORT_DESCRIPTION_FUNCTION: &str = "get_short_description"; +pub static GET_DESCRIPTION_FUNCTION: &str = "get_description"; +pub static GET_VERSION_FUNCTION: &str = "get_version"; +pub static GET_PARAMETERS_SIZE_FUNCTION: &str = "get_parameters_size"; +pub static GET_PARAMETERS_FUNCTION: &str = "get_parameters"; +pub static PROCESS_FUNCTION: &str = "process"; extern "C" fn check_error() -> c_int { let last_error = LAST_ERROR.with(|last_error| last_error.replace(None)); @@ -144,7 +144,7 @@ unsafe fn get_parameter_from_worker_parameter(worker_parameter: &WorkerParameter } fn get_library_file_path() -> String { - std::env::var("WORKER_LIBRARY_FILE").unwrap_or("libworker.so".to_string()) + std::env::var("WORKER_LIBRARY_FILE").unwrap_or_else(|_| "libworker.so".to_string()) } unsafe fn get_library_function<'a, T>(