Apply more suggestions.

This commit is contained in:
Tom Alexander 2023-10-16 19:12:25 -04:00
parent acd24d6198
commit 9a4d290cf8
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
6 changed files with 28 additions and 43 deletions

View File

@ -15,23 +15,21 @@ mod init_tracing;
#[cfg(not(feature = "tracing"))] #[cfg(not(feature = "tracing"))]
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let rt = tokio::runtime::Runtime::new()?; let rt = tokio::runtime::Runtime::new()?;
let result = rt.block_on(async { rt.block_on(async {
let main_body_result = main_body().await; let main_body_result = main_body().await;
main_body_result main_body_result
}); })
result
} }
#[cfg(feature = "tracing")] #[cfg(feature = "tracing")]
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let rt = tokio::runtime::Runtime::new()?; let rt = tokio::runtime::Runtime::new()?;
let result = rt.block_on(async { rt.block_on(async {
init_telemetry()?; init_telemetry()?;
let main_body_result = main_body().await; let main_body_result = main_body().await;
shutdown_telemetry()?; shutdown_telemetry()?;
main_body_result main_body_result
}); })
result
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]

View File

@ -21,23 +21,21 @@ mod init_tracing;
#[cfg(not(feature = "tracing"))] #[cfg(not(feature = "tracing"))]
fn main() -> Result<ExitCode, Box<dyn std::error::Error>> { fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
let rt = tokio::runtime::Runtime::new()?; let rt = tokio::runtime::Runtime::new()?;
let result = rt.block_on(async { rt.block_on(async {
let main_body_result = main_body().await; let main_body_result = main_body().await;
main_body_result main_body_result
}); })
result
} }
#[cfg(feature = "tracing")] #[cfg(feature = "tracing")]
fn main() -> Result<ExitCode, Box<dyn std::error::Error>> { fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
let rt = tokio::runtime::Runtime::new()?; let rt = tokio::runtime::Runtime::new()?;
let result = rt.block_on(async { rt.block_on(async {
init_telemetry()?; init_telemetry()?;
let main_body_result = main_body().await; let main_body_result = main_body().await;
shutdown_telemetry()?; shutdown_telemetry()?;
main_body_result main_body_result
}); })
result
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
@ -108,10 +106,9 @@ fn compare_howard_abrams() -> impl Iterator<Item = TestConfig> {
let layer = layer.chain(compare_group("clojure-yesql-xp", || { let layer = layer.chain(compare_group("clojure-yesql-xp", || {
compare_all_org_document("/foreign_documents/howardabrams/clojure-yesql-xp") compare_all_org_document("/foreign_documents/howardabrams/clojure-yesql-xp")
})); }));
let layer = layer.chain(compare_group("veep", || { layer.chain(compare_group("veep", || {
compare_all_org_document("/foreign_documents/howardabrams/veep") compare_all_org_document("/foreign_documents/howardabrams/veep")
})); }))
layer
} }
fn compare_group<N: Into<String>, F: Fn() -> I, I: Iterator<Item = TestConfig>>( fn compare_group<N: Into<String>, F: Fn() -> I, I: Iterator<Item = TestConfig>>(
@ -195,7 +192,6 @@ struct ResultLayer {
#[derive(Debug)] #[derive(Debug)]
struct SingleFileResult { struct SingleFileResult {
name: String, name: String,
file_path: PathBuf,
status: TestStatus, status: TestStatus,
} }
@ -225,7 +221,6 @@ impl SingleFile {
let result = silent_compare_on_file(&self.file_path).await; 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,
status: if let Ok(true) = result { status: if let Ok(true) = result {
TestStatus::Pass TestStatus::Pass
} else { } else {

View File

@ -5,7 +5,7 @@ use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
#[cfg(feature = "tracing")] #[cfg(feature = "tracing")]
use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::util::SubscriberInitExt;
const SERVICE_NAME: &'static str = "organic"; const SERVICE_NAME: &str = "organic";
// Despite the obvious verbosity that fully-qualifying everything causes, in these functions I am fully-qualifying everything relating to tracing. This is because the tracing feature involves multiple libraries working together and so I think it is beneficial to see which libraries contribute which bits. // Despite the obvious verbosity that fully-qualifying everything causes, in these functions I am fully-qualifying everything relating to tracing. This is because the tracing feature involves multiple libraries working together and so I think it is beneficial to see which libraries contribute which bits.

View File

@ -23,13 +23,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "tracing")] #[cfg(feature = "tracing")]
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let rt = tokio::runtime::Runtime::new()?; let rt = tokio::runtime::Runtime::new()?;
let result = rt.block_on(async { rt.block_on(async {
init_telemetry()?; init_telemetry()?;
let main_body_result = main_body(); let main_body_result = main_body();
shutdown_telemetry()?; shutdown_telemetry()?;
main_body_result main_body_result
}); })
result
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
@ -70,10 +69,9 @@ fn run_parse_on_file<P: AsRef<Path>>(org_path: P) -> Result<(), Box<dyn std::err
let file_access_interface = LocalFileAccessInterface { let file_access_interface = LocalFileAccessInterface {
working_directory: Some(parent_directory.to_path_buf()), working_directory: Some(parent_directory.to_path_buf()),
}; };
let global_settings = { let global_settings = GlobalSettings {
let mut global_settings = GlobalSettings::default(); file_access: &file_access_interface,
global_settings.file_access = &file_access_interface; ..Default::default()
global_settings
}; };
let rust_parsed = parse_with_settings(org_contents, &global_settings)?; let rust_parsed = parse_with_settings(org_contents, &global_settings)?;
println!("{:#?}", rust_parsed); println!("{:#?}", rust_parsed);

View File

@ -1,5 +1,3 @@
#![cfg(feature = "compare")] #![cfg(feature = "compare")]
#[feature(exit_status_error)]
include!(concat!(env!("OUT_DIR"), "/tests.rs")); include!(concat!(env!("OUT_DIR"), "/tests.rs"));

View File

@ -14,10 +14,9 @@ async fn autogen_default_{name}() -> Result<(), Box<dyn std::error::Error>> {{
async fn autogen_la_{name}() -> Result<(), Box<dyn std::error::Error>> {{ async fn autogen_la_{name}() -> Result<(), Box<dyn std::error::Error>> {{
let org_path = "{path}"; let org_path = "{path}";
let org_contents = std::fs::read_to_string(org_path).expect("Read org file."); let org_contents = std::fs::read_to_string(org_path).expect("Read org file.");
let global_settings = {{ let global_settings = organic::settings::GlobalSettings {{
let mut global_settings = organic::settings::GlobalSettings::default(); list_allow_alphabetical: true,
global_settings.list_allow_alphabetical = true; ..Default::default()
global_settings
}}; }};
assert!(organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings, false).await?); assert!(organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings, false).await?);
Ok(()) Ok(())
@ -28,10 +27,9 @@ async fn autogen_la_{name}() -> Result<(), Box<dyn std::error::Error>> {{
async fn autogen_t1_{name}() -> Result<(), Box<dyn std::error::Error>> {{ async fn autogen_t1_{name}() -> Result<(), Box<dyn std::error::Error>> {{
let org_path = "{path}"; let org_path = "{path}";
let org_contents = std::fs::read_to_string(org_path).expect("Read org file."); let org_contents = std::fs::read_to_string(org_path).expect("Read org file.");
let global_settings = {{ let global_settings = organic::settings::GlobalSettings {{
let mut global_settings = organic::settings::GlobalSettings::default(); tab_width: 1,
global_settings.tab_width = 1; ..Default::default()
global_settings
}}; }};
assert!(organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings, false).await?); assert!(organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings, false).await?);
Ok(()) Ok(())
@ -42,10 +40,9 @@ async fn autogen_t1_{name}() -> Result<(), Box<dyn std::error::Error>> {{
async fn autogen_t16_{name}() -> Result<(), Box<dyn std::error::Error>> {{ async fn autogen_t16_{name}() -> Result<(), Box<dyn std::error::Error>> {{
let org_path = "{path}"; let org_path = "{path}";
let org_contents = std::fs::read_to_string(org_path).expect("Read org file."); let org_contents = std::fs::read_to_string(org_path).expect("Read org file.");
let global_settings = {{ let global_settings = organic::settings::GlobalSettings {{
let mut global_settings = organic::settings::GlobalSettings::default(); tab_width: 16,
global_settings.tab_width = 16; ..Default::default()
global_settings
}}; }};
assert!(organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings, false).await?); assert!(organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings, false).await?);
Ok(()) Ok(())
@ -56,10 +53,9 @@ async fn autogen_t16_{name}() -> Result<(), Box<dyn std::error::Error>> {{
async fn autogen_odd_{name}() -> Result<(), Box<dyn std::error::Error>> {{ async fn autogen_odd_{name}() -> Result<(), Box<dyn std::error::Error>> {{
let org_path = "{path}"; let org_path = "{path}";
let org_contents = std::fs::read_to_string(org_path).expect("Read org file."); let org_contents = std::fs::read_to_string(org_path).expect("Read org file.");
let global_settings = {{ let global_settings = organic::settings::GlobalSettings {{
let mut global_settings = organic::settings::GlobalSettings::default(); odd_levels_only: organic::settings::HeadlineLevelFilter::Odd,
global_settings.odd_levels_only = organic::settings::HeadlineLevelFilter::Odd; ..Default::default()
global_settings
}}; }};
assert!(organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings, false).await?); assert!(organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings, false).await?);
Ok(()) Ok(())