Compare commits
No commits in common. "ad5efc4b0f2947f92d1d7826b8cd3d1496fa4d2d" and "92afdc0ea6281e66f3c234240b892460250048b0" have entirely different histories.
ad5efc4b0f
...
92afdc0ea6
@ -137,21 +137,6 @@ spec:
|
|||||||
value: []
|
value: []
|
||||||
- name: docker-image
|
- name: docker-image
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
||||||
- name: run-image-tracing-compare
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
runAfter:
|
|
||||||
- run-image-default
|
|
||||||
params:
|
|
||||||
- name: args
|
|
||||||
value: ["--no-default-features", "--features", "tracing,compare"]
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: run-image-all
|
- name: run-image-all
|
||||||
taskRef:
|
taskRef:
|
||||||
name: run-docker-image
|
name: run-docker-image
|
||||||
@ -164,12 +149,7 @@ spec:
|
|||||||
- run-image-default
|
- run-image-default
|
||||||
params:
|
params:
|
||||||
- name: args
|
- name: args
|
||||||
value:
|
value: ["--no-default-features", "--features", "tracing,compare"]
|
||||||
[
|
|
||||||
"--no-default-features",
|
|
||||||
"--features",
|
|
||||||
"tracing,compare,foreign_document_test",
|
|
||||||
]
|
|
||||||
- name: docker-image
|
- name: docker-image
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
||||||
finally:
|
finally:
|
||||||
|
@ -53,9 +53,9 @@ walkdir = { version = "2.3.3", optional = true }
|
|||||||
walkdir = "2.3.3"
|
walkdir = "2.3.3"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = ["compare", "foreign_document_test"]
|
||||||
compare = ["tokio/process"]
|
compare = []
|
||||||
foreign_document_test = ["compare", "dep:futures", "tokio/sync", "dep:walkdir", "tokio/process"]
|
foreign_document_test = ["compare", "dep:tokio", "dep:futures", "tokio/sync", "dep:walkdir"]
|
||||||
tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"]
|
tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"]
|
||||||
|
|
||||||
# Optimized build for any sort of release.
|
# Optimized build for any sort of release.
|
||||||
|
1
Makefile
1
Makefile
@ -52,7 +52,6 @@ buildtest:
|
|||||||
> cargo build --no-default-features --features compare
|
> cargo build --no-default-features --features compare
|
||||||
> cargo build --no-default-features --features tracing
|
> cargo build --no-default-features --features tracing
|
||||||
> cargo build --no-default-features --features compare,tracing
|
> cargo build --no-default-features --features compare,tracing
|
||||||
> cargo build --no-default-features --features compare,tracing,foreign_document_test
|
|
||||||
|
|
||||||
.PHONY: foreign_document_test
|
.PHONY: foreign_document_test
|
||||||
foreign_document_test:
|
foreign_document_test:
|
||||||
|
@ -102,4 +102,4 @@ COPY --from=foreign-document-gather /foreign_documents/doomemacs /foreign_docume
|
|||||||
COPY --from=foreign-document-gather /foreign_documents/worg /foreign_documents/worg
|
COPY --from=foreign-document-gather /foreign_documents/worg /foreign_documents/worg
|
||||||
COPY --from=build-org-mode /root/org-mode /foreign_documents/org-mode
|
COPY --from=build-org-mode /root/org-mode /foreign_documents/org-mode
|
||||||
COPY --from=build-emacs /root/emacs /foreign_documents/emacs
|
COPY --from=build-emacs /root/emacs /foreign_documents/emacs
|
||||||
ENTRYPOINT ["cargo", "run", "--bin", "foreign_document_test", "--features", "compare,foreign_document_test", "--profile", "release-lto"]
|
ENTRYPOINT ["cargo", "run", "--bin", "foreign_document_test", "--features", "compare,foreign_document_test"]
|
||||||
|
149
docker/organic_test/foreign_document_test_entrypoint.sh
Normal file
149
docker/organic_test/foreign_document_test_entrypoint.sh
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Run the Organic compare script against a series of documents sourced from exterior places.
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
REALPATH=$(command -v uu-realpath || command -v realpath)
|
||||||
|
|
||||||
|
function log {
|
||||||
|
(>&2 echo "${@}")
|
||||||
|
}
|
||||||
|
|
||||||
|
function die {
|
||||||
|
local status_code="$1"
|
||||||
|
shift
|
||||||
|
(>&2 echo "${@}")
|
||||||
|
exit "$status_code"
|
||||||
|
}
|
||||||
|
|
||||||
|
function main {
|
||||||
|
cargo build --no-default-features --features compare --profile release-lto
|
||||||
|
if [ "${CARGO_TARGET_DIR:-}" = "" ]; then
|
||||||
|
CARGO_TARGET_DIR=$(realpath target/)
|
||||||
|
fi
|
||||||
|
PARSE="${CARGO_TARGET_DIR}/release-lto/compare"
|
||||||
|
|
||||||
|
local all_status=0
|
||||||
|
set +e
|
||||||
|
|
||||||
|
(run_compare_function "org-mode" compare_all_org_document "/foreign_documents/org-mode")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
(run_compare_function "emacs" compare_all_org_document "/foreign_documents/emacs")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
(run_compare_function "worg" compare_all_org_document "/foreign_documents/worg")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
(run_compare_function "howard_abrams" compare_howard_abrams)
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
(run_compare_function "doomemacs" compare_all_org_document "/foreign_documents/doomemacs")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
|
||||||
|
set -e
|
||||||
|
if [ "$all_status" -ne 0 ]; then
|
||||||
|
red_text "Some tests failed."
|
||||||
|
else
|
||||||
|
green_text "All tests passed."
|
||||||
|
fi
|
||||||
|
return "$all_status"
|
||||||
|
}
|
||||||
|
|
||||||
|
function green_text {
|
||||||
|
(IFS=' '; printf '\x1b[38;2;0;255;0m%s\x1b[0m' "${*}")
|
||||||
|
}
|
||||||
|
|
||||||
|
function red_text {
|
||||||
|
(IFS=' '; printf '\x1b[38;2;255;0;0m%s\x1b[0m' "${*}")
|
||||||
|
}
|
||||||
|
|
||||||
|
function yellow_text {
|
||||||
|
(IFS=' '; printf '\x1b[38;2;255;255;0m%s\x1b[0m' "${*}")
|
||||||
|
}
|
||||||
|
|
||||||
|
function indent {
|
||||||
|
local depth="$1"
|
||||||
|
local scaled_depth=$((depth * 2))
|
||||||
|
shift 1
|
||||||
|
local prefix
|
||||||
|
prefix=$(printf -- "%${scaled_depth}s")
|
||||||
|
while read -r l; do
|
||||||
|
(IFS=' '; printf -- '%s%s\n' "$prefix" "$l")
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_compare_function {
|
||||||
|
local name="$1"
|
||||||
|
local stdoutput
|
||||||
|
shift 1
|
||||||
|
set +e
|
||||||
|
stdoutput=$("${@}")
|
||||||
|
local status=$?
|
||||||
|
set -e
|
||||||
|
if [ "$status" -eq 0 ]; then
|
||||||
|
echo "$(green_text "GOOD") $name"
|
||||||
|
indent 1 <<<"$stdoutput"
|
||||||
|
else
|
||||||
|
echo "$(red_text "FAIL") $name"
|
||||||
|
indent 1 <<<"$stdoutput"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function compare_all_org_document {
|
||||||
|
local root_dir="$1"
|
||||||
|
local target_document
|
||||||
|
local all_status=0
|
||||||
|
while read target_document; do
|
||||||
|
local relative_path
|
||||||
|
relative_path=$($REALPATH --relative-to "$root_dir" "$target_document")
|
||||||
|
set +e
|
||||||
|
(run_compare "$relative_path" "$target_document")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
set -e
|
||||||
|
done<<<"$(find "$root_dir" -type f -iname '*.org' | sort)"
|
||||||
|
return "$all_status"
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_compare {
|
||||||
|
local name="$1"
|
||||||
|
local target_document="$2"
|
||||||
|
set +e
|
||||||
|
($PARSE "$target_document" &> /dev/null)
|
||||||
|
local status=$?
|
||||||
|
set -e
|
||||||
|
if [ "$status" -eq 0 ]; then
|
||||||
|
echo "$(green_text "GOOD") $name"
|
||||||
|
else
|
||||||
|
echo "$(red_text "FAIL") $name"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function compare_howard_abrams {
|
||||||
|
local all_status=0
|
||||||
|
set +e
|
||||||
|
|
||||||
|
(run_compare_function "dot-files" compare_all_org_document "/foreign_documents/howardabrams/dot-files")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
(run_compare_function "hamacs" compare_all_org_document "/foreign_documents/howardabrams/hamacs")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
(run_compare_function "demo-it" compare_all_org_document "/foreign_documents/howardabrams/demo-it")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
(run_compare_function "magit-demo" compare_all_org_document "/foreign_documents/howardabrams/magit-demo")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
(run_compare_function "pdx-emacs-hackers" compare_all_org_document "/foreign_documents/howardabrams/pdx-emacs-hackers")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
(run_compare_function "flora-simulator" compare_all_org_document "/foreign_documents/howardabrams/flora-simulator")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
(run_compare_function "literate-devops-demo" compare_all_org_document "/foreign_documents/howardabrams/literate-devops-demo")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
(run_compare_function "clojure-yesql-xp" compare_all_org_document "/foreign_documents/howardabrams/clojure-yesql-xp")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
(run_compare_function "veep" compare_all_org_document "/foreign_documents/howardabrams/veep")
|
||||||
|
if [ "$?" -ne 0 ]; then all_status=1; fi
|
||||||
|
|
||||||
|
set -e
|
||||||
|
return "$all_status"
|
||||||
|
}
|
||||||
|
|
||||||
|
main "${@}"
|
@ -14,12 +14,7 @@ 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()?;
|
main_body()
|
||||||
let result = rt.block_on(async {
|
|
||||||
let main_body_result = main_body().await;
|
|
||||||
main_body_result
|
|
||||||
});
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
@ -35,18 +30,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
async fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
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 run_anonymous_compare(org_contents).await? {
|
if let Ok(true) = run_anonymous_compare(org_contents) {
|
||||||
} 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).await? {
|
if run_compare_on_file(arg)? {
|
||||||
} else {
|
} else {
|
||||||
Err("Diff results do not match.")?;
|
Err("Diff results do not match.")?;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#![feature(exact_size_is_empty)]
|
#![feature(exact_size_is_empty)]
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::ExitCode;
|
|
||||||
|
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
use futures::future::FutureExt;
|
use futures::future::FutureExt;
|
||||||
@ -19,7 +18,7 @@ use crate::init_tracing::shutdown_telemetry;
|
|||||||
mod init_tracing;
|
mod init_tracing;
|
||||||
|
|
||||||
#[cfg(not(feature = "tracing"))]
|
#[cfg(not(feature = "tracing"))]
|
||||||
fn main() -> Result<ExitCode, 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 {
|
let result = rt.block_on(async {
|
||||||
let main_body_result = main_body().await;
|
let main_body_result = main_body().await;
|
||||||
@ -29,7 +28,7 @@ fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
fn main() -> Result<ExitCode, 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 {
|
let result = rt.block_on(async {
|
||||||
init_telemetry()?;
|
init_telemetry()?;
|
||||||
@ -41,77 +40,21 @@ fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
async fn main_body() -> Result<ExitCode, Box<dyn std::error::Error>> {
|
async fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let layer = compare_group("org-mode", || {
|
let layer = compare_group("org-mode", || {
|
||||||
compare_all_org_document("/foreign_documents/org-mode")
|
compare_all_org_document("/foreign_documents/org-mode")
|
||||||
});
|
});
|
||||||
let layer = layer.chain(compare_group("emacs", || {
|
let layer = layer.chain(compare_group("emacs", || {
|
||||||
compare_all_org_document("/foreign_documents/emacs")
|
compare_all_org_document("/foreign_documents/emacs")
|
||||||
}));
|
}));
|
||||||
let layer = layer.chain(compare_group("worg", || {
|
|
||||||
compare_all_org_document("/foreign_documents/worg")
|
|
||||||
}));
|
|
||||||
let layer = layer.chain(compare_group("howard_abrams", compare_howard_abrams));
|
|
||||||
let layer = layer.chain(compare_group("doomemacs", || {
|
|
||||||
compare_all_org_document("/foreign_documents/doomemacs")
|
|
||||||
}));
|
|
||||||
|
|
||||||
let running_tests: Vec<_> = layer.map(|c| tokio::spawn(c.run_test())).collect();
|
let running_tests: Vec<_> = layer.map(|c| tokio::spawn(c.run_test())).collect();
|
||||||
let mut any_failed = false;
|
|
||||||
for test in running_tests.into_iter() {
|
for test in running_tests.into_iter() {
|
||||||
let test_result = test.await??;
|
let test_result = test.await??;
|
||||||
if test_result.is_immediately_bad() || test_result.has_bad_children() {
|
|
||||||
any_failed = true;
|
|
||||||
}
|
|
||||||
test_result.print();
|
test_result.print();
|
||||||
}
|
}
|
||||||
|
|
||||||
if any_failed {
|
Ok(())
|
||||||
println!(
|
|
||||||
"{color}Some tests failed.{reset}",
|
|
||||||
color = TestResult::foreground_color(255, 0, 0),
|
|
||||||
reset = TestResult::reset_color(),
|
|
||||||
);
|
|
||||||
Ok(ExitCode::FAILURE)
|
|
||||||
} else {
|
|
||||||
println!(
|
|
||||||
"{color}All tests passed.{reset}",
|
|
||||||
color = TestResult::foreground_color(0, 255, 0),
|
|
||||||
reset = TestResult::reset_color(),
|
|
||||||
);
|
|
||||||
Ok(ExitCode::SUCCESS)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compare_howard_abrams() -> impl Iterator<Item = TestConfig> {
|
|
||||||
let layer = compare_group("dot-files", || {
|
|
||||||
compare_all_org_document("/foreign_documents/howardabrams/dot-files")
|
|
||||||
});
|
|
||||||
let layer = layer.chain(compare_group("hamacs", || {
|
|
||||||
compare_all_org_document("/foreign_documents/howardabrams/hamacs")
|
|
||||||
}));
|
|
||||||
let layer = layer.chain(compare_group("demo-it", || {
|
|
||||||
compare_all_org_document("/foreign_documents/howardabrams/demo-it")
|
|
||||||
}));
|
|
||||||
let layer = layer.chain(compare_group("magit-demo", || {
|
|
||||||
compare_all_org_document("/foreign_documents/howardabrams/magit-demo")
|
|
||||||
}));
|
|
||||||
let layer = layer.chain(compare_group("pdx-emacs-hackers", || {
|
|
||||||
compare_all_org_document("/foreign_documents/howardabrams/pdx-emacs-hackers")
|
|
||||||
}));
|
|
||||||
let layer = layer.chain(compare_group("flora-simulator", || {
|
|
||||||
compare_all_org_document("/foreign_documents/howardabrams/flora-simulator")
|
|
||||||
}));
|
|
||||||
let layer = layer.chain(compare_group("literate-devops-demo", || {
|
|
||||||
compare_all_org_document("/foreign_documents/howardabrams/literate-devops-demo")
|
|
||||||
}));
|
|
||||||
let layer = layer.chain(compare_group("clojure-yesql-xp", || {
|
|
||||||
compare_all_org_document("/foreign_documents/howardabrams/clojure-yesql-xp")
|
|
||||||
}));
|
|
||||||
let layer = layer.chain(compare_group("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>>(
|
||||||
@ -126,7 +69,7 @@ fn compare_group<N: Into<String>, F: Fn() -> I, I: Iterator<Item = TestConfig>>(
|
|||||||
|
|
||||||
fn compare_all_org_document<P: AsRef<Path>>(root_dir: P) -> impl Iterator<Item = TestConfig> {
|
fn compare_all_org_document<P: AsRef<Path>>(root_dir: P) -> impl Iterator<Item = TestConfig> {
|
||||||
let root_dir = root_dir.as_ref();
|
let root_dir = root_dir.as_ref();
|
||||||
let mut test_files = WalkDir::new(root_dir)
|
let test_files = WalkDir::new(root_dir)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|e| match e {
|
.filter(|e| match e {
|
||||||
Ok(dir_entry) => {
|
Ok(dir_entry) => {
|
||||||
@ -140,7 +83,6 @@ fn compare_all_org_document<P: AsRef<Path>>(root_dir: P) -> impl Iterator<Item =
|
|||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
test_files.sort_by_cached_key(|test_file| PathBuf::from(test_file.path()));
|
|
||||||
let test_configs: Vec<_> = test_files
|
let test_configs: Vec<_> = test_files
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|test_file| {
|
.map(|test_file| {
|
||||||
@ -222,7 +164,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).await;
|
let result = silent_compare_on_file(&self.file_path);
|
||||||
Ok(SingleFileResult {
|
Ok(SingleFileResult {
|
||||||
name: self.name,
|
name: self.name,
|
||||||
file_path: self.file_path,
|
file_path: self.file_path,
|
||||||
|
@ -12,43 +12,43 @@ 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 async fn run_anonymous_compare<P: AsRef<str>>(
|
pub 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).await
|
run_anonymous_compare_with_settings(org_contents, &GlobalSettings::default(), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run_compare_on_file<P: AsRef<Path>>(
|
pub 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).await
|
run_compare_on_file_with_settings(org_path, &GlobalSettings::default(), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn silent_anonymous_compare<P: AsRef<str>>(
|
pub 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).await
|
run_anonymous_compare_with_settings(org_contents, &GlobalSettings::default(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn silent_compare_on_file<P: AsRef<Path>>(
|
pub 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).await
|
run_compare_on_file_with_settings(org_path, &GlobalSettings::default(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run_anonymous_compare_with_settings<'g, 's, P: AsRef<str>>(
|
pub fn run_anonymous_compare_with_settings<P: AsRef<str>>(
|
||||||
org_contents: P,
|
org_contents: P,
|
||||||
global_settings: &GlobalSettings<'g, 's>,
|
global_settings: &GlobalSettings,
|
||||||
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.
|
||||||
let org_contents = org_contents.as_ref().replace("\r\n", "\n");
|
let org_contents = org_contents.as_ref().replace("\r\n", "\n");
|
||||||
let org_contents = org_contents.as_str();
|
let org_contents = org_contents.as_str();
|
||||||
if !silent {
|
if !silent {
|
||||||
print_versions().await?;
|
print_versions()?;
|
||||||
}
|
}
|
||||||
let rust_parsed = parse_with_settings(org_contents, global_settings)?;
|
let rust_parsed = parse_with_settings(org_contents, global_settings)?;
|
||||||
let org_sexp = emacs_parse_anonymous_org_document(org_contents, global_settings).await?;
|
let org_sexp = emacs_parse_anonymous_org_document(org_contents, global_settings)?;
|
||||||
let (_remaining, parsed_sexp) = sexp(org_sexp.as_str()).map_err(|e| e.to_string())?;
|
let (_remaining, parsed_sexp) = sexp(org_sexp.as_str()).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
if !silent {
|
if !silent {
|
||||||
@ -76,14 +76,14 @@ pub async fn run_anonymous_compare_with_settings<'g, 's, P: AsRef<str>>(
|
|||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run_compare_on_file_with_settings<'g, 's, P: AsRef<Path>>(
|
pub fn run_compare_on_file_with_settings<P: AsRef<Path>>(
|
||||||
org_path: P,
|
org_path: P,
|
||||||
global_settings: &GlobalSettings<'g, 's>,
|
global_settings: &GlobalSettings,
|
||||||
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();
|
||||||
if !silent {
|
if !silent {
|
||||||
print_versions().await?;
|
print_versions()?;
|
||||||
}
|
}
|
||||||
let parent_directory = org_path
|
let parent_directory = org_path
|
||||||
.parent()
|
.parent()
|
||||||
@ -101,7 +101,7 @@ pub async fn run_compare_on_file_with_settings<'g, 's, P: AsRef<Path>>(
|
|||||||
global_settings
|
global_settings
|
||||||
};
|
};
|
||||||
let rust_parsed = parse_file_with_settings(org_contents, &global_settings, Some(org_path))?;
|
let rust_parsed = parse_file_with_settings(org_contents, &global_settings, Some(org_path))?;
|
||||||
let org_sexp = emacs_parse_file_org_document(org_path, &global_settings).await?;
|
let org_sexp = emacs_parse_file_org_document(org_path, &global_settings)?;
|
||||||
let (_remaining, parsed_sexp) = sexp(org_sexp.as_str()).map_err(|e| e.to_string())?;
|
let (_remaining, parsed_sexp) = sexp(org_sexp.as_str()).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
if !silent {
|
if !silent {
|
||||||
@ -129,11 +129,8 @@ pub async fn run_compare_on_file_with_settings<'g, 's, P: AsRef<Path>>(
|
|||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn print_versions() -> Result<(), Box<dyn std::error::Error>> {
|
fn print_versions() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
eprintln!("Using emacs version: {}", get_emacs_version().await?.trim());
|
eprintln!("Using emacs version: {}", get_emacs_version()?.trim());
|
||||||
eprintln!(
|
eprintln!("Using org-mode version: {}", get_org_mode_version()?.trim());
|
||||||
"Using org-mode version: {}",
|
|
||||||
get_org_mode_version().await?.trim()
|
|
||||||
);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::process::Command;
|
||||||
use tokio::process::Command;
|
|
||||||
|
|
||||||
use crate::context::HeadlineLevelFilter;
|
use crate::context::HeadlineLevelFilter;
|
||||||
use crate::settings::GlobalSettings;
|
use crate::settings::GlobalSettings;
|
||||||
@ -26,9 +25,9 @@ fn global_settings_elisp(global_settings: &GlobalSettings) -> String {
|
|||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn emacs_parse_anonymous_org_document<'g, 's, C>(
|
pub(crate) fn emacs_parse_anonymous_org_document<C>(
|
||||||
file_contents: C,
|
file_contents: C,
|
||||||
global_settings: &GlobalSettings<'g, 's>,
|
global_settings: &GlobalSettings,
|
||||||
) -> Result<String, Box<dyn std::error::Error>>
|
) -> Result<String, Box<dyn std::error::Error>>
|
||||||
where
|
where
|
||||||
C: AsRef<str>,
|
C: AsRef<str>,
|
||||||
@ -55,7 +54,7 @@ where
|
|||||||
.arg("--batch")
|
.arg("--batch")
|
||||||
.arg("--eval")
|
.arg("--eval")
|
||||||
.arg(elisp_script);
|
.arg(elisp_script);
|
||||||
let out = cmd.output().await?;
|
let out = cmd.output()?;
|
||||||
let status = out.status.exit_ok();
|
let status = out.status.exit_ok();
|
||||||
if status.is_err() {
|
if status.is_err() {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
@ -70,9 +69,9 @@ where
|
|||||||
Ok(String::from_utf8(org_sexp)?)
|
Ok(String::from_utf8(org_sexp)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn emacs_parse_file_org_document<'g, 's, P>(
|
pub(crate) fn emacs_parse_file_org_document<P>(
|
||||||
file_path: P,
|
file_path: P,
|
||||||
global_settings: &GlobalSettings<'g, 's>,
|
global_settings: &GlobalSettings,
|
||||||
) -> Result<String, Box<dyn std::error::Error>>
|
) -> Result<String, Box<dyn std::error::Error>>
|
||||||
where
|
where
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
@ -107,7 +106,7 @@ where
|
|||||||
.arg("--batch")
|
.arg("--batch")
|
||||||
.arg("--eval")
|
.arg("--eval")
|
||||||
.arg(elisp_script);
|
.arg(elisp_script);
|
||||||
let out = cmd.output().await?;
|
let out = cmd.output()?;
|
||||||
let status = out.status.exit_ok();
|
let status = out.status.exit_ok();
|
||||||
if status.is_err() {
|
if status.is_err() {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
@ -144,7 +143,7 @@ where
|
|||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_emacs_version() -> Result<String, Box<dyn std::error::Error>> {
|
pub fn get_emacs_version() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
let elisp_script = r#"(progn
|
let elisp_script = r#"(progn
|
||||||
(message "%s" (version))
|
(message "%s" (version))
|
||||||
)"#;
|
)"#;
|
||||||
@ -157,12 +156,12 @@ pub async fn get_emacs_version() -> Result<String, Box<dyn std::error::Error>> {
|
|||||||
.arg("--eval")
|
.arg("--eval")
|
||||||
.arg(elisp_script);
|
.arg(elisp_script);
|
||||||
|
|
||||||
let out = cmd.output().await?;
|
let out = cmd.output()?;
|
||||||
out.status.exit_ok()?;
|
out.status.exit_ok()?;
|
||||||
Ok(String::from_utf8(out.stderr)?)
|
Ok(String::from_utf8(out.stderr)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_org_mode_version() -> Result<String, Box<dyn std::error::Error>> {
|
pub fn get_org_mode_version() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
let elisp_script = r#"(progn
|
let elisp_script = r#"(progn
|
||||||
(org-mode)
|
(org-mode)
|
||||||
(message "%s" (org-version nil t nil))
|
(message "%s" (org-version nil t nil))
|
||||||
@ -176,7 +175,7 @@ pub async fn get_org_mode_version() -> Result<String, Box<dyn std::error::Error>
|
|||||||
.arg("--eval")
|
.arg("--eval")
|
||||||
.arg(elisp_script);
|
.arg(elisp_script);
|
||||||
|
|
||||||
let out = cmd.output().await?;
|
let out = cmd.output()?;
|
||||||
out.status.exit_ok()?;
|
out.status.exit_ok()?;
|
||||||
Ok(String::from_utf8(out.stderr)?)
|
Ok(String::from_utf8(out.stderr)?)
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[cfg(any(feature = "compare", feature = "foreign_document_test"))]
|
|
||||||
pub trait FileAccessInterface: Sync + Debug {
|
|
||||||
fn read_file(&self, path: &str) -> Result<String, std::io::Error>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(any(feature = "compare", feature = "foreign_document_test")))]
|
|
||||||
pub trait FileAccessInterface: Debug {
|
pub trait FileAccessInterface: Debug {
|
||||||
fn read_file(&self, path: &str) -> Result<String, std::io::Error>;
|
fn read_file(&self, path: &str) -> Result<String, std::io::Error>;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user