Skip to content

Commit

Permalink
Run clippy in binding tests
Browse files Browse the repository at this point in the history
Signed-off-by: Anand Krishnamoorthi <[email protected]>
  • Loading branch information
anakrish committed May 25, 2024
1 parent 862dbc8 commit 925044c
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 9 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/test-ffi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: bindings/c-cpp

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Test FFI
run: |
cargo build -r
cargo clippy --all-targets --no-deps -- -Dwarnings
working-directory: ./bindings/ffi
4 changes: 3 additions & 1 deletion .github/workflows/test-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jobs:
- uses: dtolnay/rust-toolchain@stable

- name: Building binding
run: cargo build --release --manifest-path bindings/java/Cargo.toml
run: |
cargo clippy --all-targets --no-deps -- -Dwarnings
cargo build --release --manifest-path bindings/java/Cargo.toml
- name: Build jar
run: mvn package
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ jobs:
run: |
pip3 install dist/regorus-*.whl
cd bindings/python
cargo clippy --all-targets --no-deps -- -Dwarnings
python3 test.py
1 change: 1 addition & 0 deletions .github/workflows/test-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ jobs:
- name: Run ruby tests
run: |
cd bindings/ruby
cargo clippy --all-targets --no-deps -- -Dwarnings
bundle exec rake
1 change: 1 addition & 0 deletions .github/workflows/test-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- name: Test wasm binding
run: |
cd bindings/wasm
cargo clippy --all-targets --no-deps -- -Dwarnings
wasm-pack build --target nodejs --release
wasm-pack test --release --node
node test.js
3 changes: 2 additions & 1 deletion bindings/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ regorus = { path = "../..", default-features = false }
serde_json = "1.0.113"

[features]
default = ["std", "regorus/arc", "regorus/full-opa"]
default = ["std", "coverage", "regorus/arc", "regorus/full-opa"]
std = ["regorus/std"]
coverage = ["regorus/coverage"]
custom_allocator = []

[build-dependencies]
Expand Down
6 changes: 5 additions & 1 deletion bindings/ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub extern "C" fn regorus_engine_clone(engine: *mut RegorusEngine) -> *mut Regor

#[no_mangle]
pub extern "C" fn regorus_engine_drop(engine: *mut RegorusEngine) {
if let Ok(ref mut e) = to_ref(&engine) {
if let Ok(e) = to_ref(&engine) {
unsafe {
let _ = Box::from_raw(e);
}
Expand Down Expand Up @@ -308,6 +308,7 @@ pub extern "C" fn regorus_engine_eval_rule(
/// See https://docs.rs/regorus/0.1.0-alpha.2/regorus/struct.Engine.html#method.set_enable_coverage
/// * `enable`: Whether to enable or disable coverage.
#[no_mangle]
#[cfg(feature = "coverage")]
pub extern "C" fn regorus_engine_set_enable_coverage(
engine: *mut RegorusEngine,
enable: bool,
Expand All @@ -322,6 +323,7 @@ pub extern "C" fn regorus_engine_set_enable_coverage(
///
/// See https://docs.rs/regorus/0.1.0-alpha.2/regorus/struct.Engine.html#method.get_coverage_report
#[no_mangle]
#[cfg(feature = "coverage")]
pub extern "C" fn regorus_engine_get_coverage_report(engine: *mut RegorusEngine) -> RegorusResult {
let output = || -> Result<String> {
Ok(serde_json::to_string_pretty(
Expand All @@ -342,6 +344,7 @@ pub extern "C" fn regorus_engine_get_coverage_report(engine: *mut RegorusEngine)
///
/// See https://docs.rs/regorus/latest/regorus/coverage/struct.Report.html#method.to_string_pretty
#[no_mangle]
#[cfg(feature = "coverage")]
pub extern "C" fn regorus_engine_get_coverage_report_pretty(
engine: *mut RegorusEngine,
) -> RegorusResult {
Expand All @@ -365,6 +368,7 @@ pub extern "C" fn regorus_engine_get_coverage_report_pretty(
///
/// See https://docs.rs/regorus/0.1.0-alpha.2/regorus/struct.Engine.html#method.clear_coverage_data
#[no_mangle]
#[cfg(feature = "coverage")]
pub extern "C" fn regorus_engine_clear_coverage_data(engine: *mut RegorusEngine) -> RegorusResult {
to_regorus_result(|| -> Result<()> {
to_ref(&engine)?.engine.clear_coverage_data();
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl Engine {
serde_json::to_string_pretty(&report).map_err(|e| anyhow!("{e}"))
}

// Get coverage report as pretty printable string.
/// Get coverage report as pretty printable string.
///
pub fn get_coverage_report_pretty(&self) -> Result<String> {
self.engine.get_coverage_report()?.to_string_pretty()
Expand Down
13 changes: 8 additions & 5 deletions bindings/ruby/ext/regorusrb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Engine {
}

fn add_data_from_json_file(&self, path: String) -> Result<(), Error> {
let json_data = regorus::Value::from_json_file(&path).map_err(|e| {
let json_data = regorus::Value::from_json_file(path).map_err(|e| {
Error::new(
runtime_error(),
format!("Failed to parse JSON data file: {}", e),
Expand Down Expand Up @@ -112,7 +112,7 @@ impl Engine {
}

fn add_input_from_json_file(&self, path: String) -> Result<(), Error> {
let json_data = regorus::Value::from_json_file(&path).map_err(|e| {
let json_data = regorus::Value::from_json_file(path).map_err(|e| {
Error::new(
runtime_error(),
format!("Failed to parse JSON input file: {}", e),
Expand Down Expand Up @@ -193,7 +193,8 @@ impl Engine {
}

fn set_enable_coverage(&self, enable: bool) -> Result<(), Error> {
Ok(self.engine.borrow_mut().set_enable_coverage(enable))
self.engine.borrow_mut().set_enable_coverage(enable);
Ok(())
}

fn get_coverage_report_as_json(&self) -> Result<String, Error> {
Expand Down Expand Up @@ -237,12 +238,14 @@ impl Engine {
}

fn clear_coverage_data(&self) -> Result<(), Error> {
Ok(self.engine.borrow_mut().clear_coverage_data())
self.engine.borrow_mut().clear_coverage_data();
Ok(())
}

// Print statements can be gathered async instead of printing to stderr
fn set_gather_prints(&self, enable: bool) -> Result<(), Error> {
Ok(self.engine.borrow_mut().set_gather_prints(enable))
self.engine.borrow_mut().set_gather_prints(enable);
Ok(())
}

fn take_prints(&self) -> Result<Vec<String>, Error> {
Expand Down

0 comments on commit 925044c

Please sign in to comment.