diff --git a/src/bin_wasm_test.rs b/src/bin_wasm_test.rs index 9db94ec0..f64d70af 100644 --- a/src/bin_wasm_test.rs +++ b/src/bin_wasm_test.rs @@ -1,10 +1,12 @@ #![feature(exact_size_is_empty)] +#![feature(exit_status_error)] use std::io::Read; use organic::settings::GlobalSettings; use wasm::wasm_parse_org; mod error; +mod util; mod wasm; #[cfg(feature = "tracing")] diff --git a/src/util/mod.rs b/src/util/mod.rs new file mode 100644 index 00000000..e747f159 --- /dev/null +++ b/src/util/mod.rs @@ -0,0 +1,47 @@ +use tokio::process::Command; + +pub(crate) async fn print_versions() -> Result<(), Box> { + eprintln!("Using emacs version: {}", get_emacs_version().await?.trim()); + eprintln!( + "Using org-mode version: {}", + get_org_mode_version().await?.trim() + ); + Ok(()) +} + +pub(crate) async fn get_emacs_version() -> Result> { + let elisp_script = r#"(progn + (message "%s" (version)) +)"#; + let mut cmd = Command::new("emacs"); + let cmd = cmd + .arg("-q") + .arg("--no-site-file") + .arg("--no-splash") + .arg("--batch") + .arg("--eval") + .arg(elisp_script); + + let out = cmd.output().await?; + out.status.exit_ok()?; + Ok(String::from_utf8(out.stderr)?) +} + +pub(crate) async fn get_org_mode_version() -> Result> { + let elisp_script = r#"(progn + (org-mode) + (message "%s" (org-version nil t nil)) +)"#; + let mut cmd = Command::new("emacs"); + let cmd = cmd + .arg("-q") + .arg("--no-site-file") + .arg("--no-splash") + .arg("--batch") + .arg("--eval") + .arg(elisp_script); + + let out = cmd.output().await?; + out.status.exit_ok()?; + Ok(String::from_utf8(out.stderr)?) +} diff --git a/src/wasm/compare/runner.rs b/src/wasm/compare/runner.rs index 41a0b24b..aaf2f9ba 100644 --- a/src/wasm/compare/runner.rs +++ b/src/wasm/compare/runner.rs @@ -1,6 +1,8 @@ use organic::parser::parse_with_settings; use organic::settings::GlobalSettings; +use crate::util::print_versions; + pub async fn wasm_run_anonymous_compare_with_settings<'g, 's, P: AsRef>( org_contents: P, global_settings: &GlobalSettings<'g, 's>, @@ -9,9 +11,9 @@ pub async fn wasm_run_anonymous_compare_with_settings<'g, 's, P: AsRef>( // 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. let org_contents = org_contents.as_ref().replace("\r\n", "\n"); let org_contents = org_contents.as_str(); - // if !silent { - // print_versions().await?; - // } + if !silent { + print_versions().await?; + } let rust_parsed = parse_with_settings(org_contents, global_settings)?; // let org_sexp = emacs_parse_anonymous_org_document(org_contents, global_settings).await?; // let (_remaining, parsed_sexp) = sexp(org_sexp.as_str()).map_err(|e| e.to_string())?;