Make the compare functions async.

This commit is contained in:
Tom Alexander 2023-10-14 17:48:38 -04:00
parent c20e7b5f2f
commit 123da9cca3
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 16 additions and 16 deletions

View File

@ -39,14 +39,14 @@ async fn main_body() -> Result<(), Box<dyn std::error::Error>> {
let args = std::env::args().skip(1); let args = std::env::args().skip(1);
if args.is_empty() { if args.is_empty() {
let org_contents = read_stdin_to_string()?; let org_contents = read_stdin_to_string()?;
if let Ok(true) = run_anonymous_compare(org_contents) { if run_anonymous_compare(org_contents).await? {
} else { } else {
Err("Diff results do not match.")?; Err("Diff results do not match.")?;
} }
Ok(()) Ok(())
} else { } else {
for arg in args { for arg in args {
if run_compare_on_file(arg)? { if run_compare_on_file(arg).await? {
} else { } else {
Err("Diff results do not match.")?; Err("Diff results do not match.")?;
} }

View File

@ -222,7 +222,7 @@ impl TestConfig {
impl SingleFile { impl SingleFile {
async fn run_test(self) -> Result<SingleFileResult, JoinError> { async fn run_test(self) -> Result<SingleFileResult, JoinError> {
let _permit = TEST_PERMITS.acquire().await.unwrap(); let _permit = TEST_PERMITS.acquire().await.unwrap();
let result = silent_compare_on_file(&self.file_path); let result = silent_compare_on_file(&self.file_path).await;
Ok(SingleFileResult { Ok(SingleFileResult {
name: self.name, name: self.name,
file_path: self.file_path, file_path: self.file_path,

View File

@ -12,33 +12,33 @@ use crate::context::LocalFileAccessInterface;
use crate::parser::parse_file_with_settings; use crate::parser::parse_file_with_settings;
use crate::parser::parse_with_settings; use crate::parser::parse_with_settings;
pub fn run_anonymous_compare<P: AsRef<str>>( pub async fn run_anonymous_compare<P: AsRef<str>>(
org_contents: P, org_contents: P,
) -> Result<bool, Box<dyn std::error::Error>> { ) -> Result<bool, Box<dyn std::error::Error>> {
run_anonymous_compare_with_settings(org_contents, &GlobalSettings::default(), false) run_anonymous_compare_with_settings(org_contents, &GlobalSettings::default(), false).await
} }
pub fn run_compare_on_file<P: AsRef<Path>>( pub async fn run_compare_on_file<P: AsRef<Path>>(
org_path: P, org_path: P,
) -> Result<bool, Box<dyn std::error::Error>> { ) -> Result<bool, Box<dyn std::error::Error>> {
run_compare_on_file_with_settings(org_path, &GlobalSettings::default(), false) run_compare_on_file_with_settings(org_path, &GlobalSettings::default(), false).await
} }
pub fn silent_anonymous_compare<P: AsRef<str>>( pub async fn silent_anonymous_compare<P: AsRef<str>>(
org_contents: P, org_contents: P,
) -> Result<bool, Box<dyn std::error::Error>> { ) -> Result<bool, Box<dyn std::error::Error>> {
run_anonymous_compare_with_settings(org_contents, &GlobalSettings::default(), true) run_anonymous_compare_with_settings(org_contents, &GlobalSettings::default(), true).await
} }
pub fn silent_compare_on_file<P: AsRef<Path>>( pub async fn silent_compare_on_file<P: AsRef<Path>>(
org_path: P, org_path: P,
) -> Result<bool, Box<dyn std::error::Error>> { ) -> Result<bool, Box<dyn std::error::Error>> {
run_compare_on_file_with_settings(org_path, &GlobalSettings::default(), true) run_compare_on_file_with_settings(org_path, &GlobalSettings::default(), true).await
} }
pub fn run_anonymous_compare_with_settings<P: AsRef<str>>( pub async fn run_anonymous_compare_with_settings<'g, 's, P: AsRef<str>>(
org_contents: P, org_contents: P,
global_settings: &GlobalSettings, global_settings: &GlobalSettings<'g, 's>,
silent: bool, silent: bool,
) -> Result<bool, Box<dyn std::error::Error>> { ) -> Result<bool, Box<dyn std::error::Error>> {
// TODO: This is a work-around to pretend that dos line endings do not exist. It would be better to handle the difference in line endings. // TODO: This is a work-around to pretend that dos line endings do not exist. It would be better to handle the difference in line endings.
@ -76,9 +76,9 @@ pub fn run_anonymous_compare_with_settings<P: AsRef<str>>(
Ok(true) Ok(true)
} }
pub fn run_compare_on_file_with_settings<P: AsRef<Path>>( pub async fn run_compare_on_file_with_settings<'g, 's, P: AsRef<Path>>(
org_path: P, org_path: P,
global_settings: &GlobalSettings, global_settings: &GlobalSettings<'g, 's>,
silent: bool, silent: bool,
) -> Result<bool, Box<dyn std::error::Error>> { ) -> Result<bool, Box<dyn std::error::Error>> {
let org_path = org_path.as_ref(); let org_path = org_path.as_ref();

View File

@ -1,7 +1,7 @@
use std::fmt::Debug; use std::fmt::Debug;
use std::path::PathBuf; use std::path::PathBuf;
pub trait FileAccessInterface: Debug { pub trait FileAccessInterface: Sync + Debug {
fn read_file(&self, path: &str) -> Result<String, std::io::Error>; fn read_file(&self, path: &str) -> Result<String, std::io::Error>;
} }