Skip to content

Commit cb0bd4c

Browse files
committed
make main return unit, not u8
1 parent a2253d7 commit cb0bd4c

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

cpp-linter/src/main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#![cfg(not(test))]
22
/// This crate is the binary executable's entrypoint.
3-
use std::{env, process::ExitCode};
3+
use std::env;
44

55
use ::cpp_linter::run::run_main;
66
use anyhow::Result;
77

88
/// This function simply forwards CLI args to [`run_main()`].
99
#[tokio::main]
10-
pub async fn main() -> Result<ExitCode> {
11-
Ok(ExitCode::from(
12-
run_main(env::args().collect::<Vec<String>>()).await?,
13-
))
10+
pub async fn main() -> Result<()> {
11+
run_main(env::args().collect::<Vec<String>>()).await
1412
}

cpp-linter/src/run.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::path::Path;
88
use std::sync::{Arc, Mutex};
99

1010
// non-std crates
11-
use anyhow::Result;
11+
use anyhow::{anyhow, Result};
1212
use log::{set_max_level, LevelFilter};
1313
#[cfg(feature = "openssl-vendored")]
1414
use openssl_probe;
@@ -41,7 +41,7 @@ fn probe_ssl_certs() {
4141
/// is used instead of python's `sys.argv`, then the list of strings includes the entry point
4242
/// alias ("path/to/cpp-linter.exe"). Thus, the parser in [`crate::cli`] will halt on an error
4343
/// because it is not configured to handle positional arguments.
44-
pub async fn run_main(args: Vec<String>) -> Result<u8> {
44+
pub async fn run_main(args: Vec<String>) -> Result<()> {
4545
probe_ssl_certs();
4646

4747
let arg_parser = get_arg_parser();
@@ -50,15 +50,15 @@ pub async fn run_main(args: Vec<String>) -> Result<u8> {
5050

5151
if args.subcommand_matches("version").is_some() {
5252
println!("cpp-linter v{}", VERSION);
53-
return Ok(0);
53+
return Ok(());
5454
}
5555

5656
logger::init().unwrap();
5757

5858
if cli.version == "NO-VERSION" {
5959
log::error!("The `--version` arg is used to specify which version of clang to use.");
6060
log::error!("To get the cpp-linter version, use `cpp-linter version` sub-command.");
61-
return Ok(1);
61+
return Err(anyhow!("Clang version not specified."));
6262
}
6363

6464
if cli.repo_root != "." {
@@ -135,9 +135,13 @@ pub async fn run_main(args: Vec<String>) -> Result<u8> {
135135
.await?;
136136
end_log_group();
137137
if env::var("PRE_COMMIT").is_ok_and(|v| v == "1") {
138-
return Ok((checks_failed > 1) as u8);
138+
if checks_failed > 1 {
139+
return Err(anyhow!("Some checks did not pass"));
140+
} else {
141+
return Ok(());
142+
}
139143
}
140-
Ok(0)
144+
Ok(())
141145
}
142146

143147
#[cfg(test)]
@@ -157,14 +161,14 @@ mod test {
157161
"demo/demo.cpp".to_string(),
158162
])
159163
.await;
160-
assert!(result.is_ok_and(|v| v == 0));
164+
assert!(result.is_ok());
161165
}
162166

163167
#[tokio::test]
164168
async fn version_command() {
165169
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
166170
let result = run_main(vec!["cpp-linter".to_string(), "version".to_string()]).await;
167-
assert!(result.is_ok_and(|v| v == 0));
171+
assert!(result.is_ok());
168172
}
169173

170174
#[tokio::test]
@@ -178,7 +182,7 @@ mod test {
178182
"debug".to_string(),
179183
])
180184
.await;
181-
assert!(result.is_ok_and(|v| v == 0));
185+
assert!(result.is_ok());
182186
}
183187

184188
#[tokio::test]
@@ -191,7 +195,7 @@ mod test {
191195
"-V".to_string(),
192196
])
193197
.await;
194-
assert!(result.is_ok_and(|v| v == 1));
198+
assert!(result.is_err());
195199
}
196200

197201
#[tokio::test]
@@ -204,6 +208,6 @@ mod test {
204208
"false".to_string(),
205209
])
206210
.await;
207-
assert!(result.is_ok_and(|v| v == 1));
211+
assert!(result.is_err());
208212
}
209213
}

cpp-linter/tests/comments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ async fn setup(lib_root: &Path, test_params: &TestParams) {
242242
args.push("-e=c".to_string());
243243
}
244244
let result = run_main(args).await;
245-
assert!(result.is_ok_and(|v| v == 0));
245+
assert!(result.is_ok());
246246
for mock in mocks {
247247
mock.assert();
248248
}

cpp-linter/tests/reviews.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ async fn setup(lib_root: &Path, test_params: &TestParams) {
222222
args.push("-e=c".to_string());
223223
}
224224
let result = run_main(args).await;
225-
assert!(result.is_ok_and(|v| v == 0));
225+
assert!(result.is_ok());
226226
for mock in mocks {
227227
mock.assert();
228228
}

node-binding/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ::cpp_linter::run::run_main;
44
use napi::bindgen_prelude::*;
55

66
#[napi]
7-
pub async fn main(args: Vec<String>) -> Result<u8> {
7+
pub async fn main(args: Vec<String>) -> Result<()> {
88
run_main(args)
99
.await
1010
.map_err(|e| Error::new(Status::GenericFailure, e.to_string()))

py-binding/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ::cpp_linter::run::run_main;
55

66
/// A wrapper for the ``::cpp_linter::run::run_main()```
77
#[pyfunction]
8-
fn main(args: Vec<String>) -> PyResult<u8> {
8+
fn main(args: Vec<String>) -> PyResult<()> {
99
Builder::new_multi_thread()
1010
.enable_all()
1111
.build()

0 commit comments

Comments
 (0)