summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2023-03-12 10:57:00 +0400
committerJoursoir <chat@joursoir.net>2023-03-13 01:33:49 +0400
commit1e992e31a0ca7691dc576011e475a3a801d5a0ea (patch)
treeaf495ac6574793da3fb0638635e2912bc87195be
parent7f4ad7365d6cd422d704224fdeb37bbee1a36e9e (diff)
downloadtrgrep-1e992e31a0ca7691dc576011e475a3a801d5a0ea.tar.gz
trgrep-1e992e31a0ca7691dc576011e475a3a801d5a0ea.tar.bz2
trgrep-1e992e31a0ca7691dc576011e475a3a801d5a0ea.zip
add an output comparison testHEADmaster
-rwxr-xr-xtest.sh35
1 files changed, 35 insertions, 0 deletions
diff --git a/test.sh b/test.sh
new file mode 100755
index 0000000..d6db5f5
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+trgrep_output_file="rust_output.txt"
+grep_output_file="grep_output.txt"
+
+function run_test {
+ local options="$1"
+
+ # Run trgrep and redirect its output to a file
+ cargo run --quiet -- $options > "$trgrep_output_file"
+
+ # Run the real grep and redirect its output to a file
+ grep $options > "$grep_output_file"
+
+ # Compare the two output files using diff
+ if diff "$trgrep_output_file" "$grep_output_file" >/dev/null ; then
+ echo "$options: passed"
+ return 0
+ else
+ echo "$options: FAILED"
+ return 1
+ fi
+}
+
+# Run some tests
+run_test "-v --ignore-case twinkle sample-files/poem.txt"
+run_test "-w 'apple' sample-files/words.txt"
+run_test "a sample-files/words.txt"
+run_test "-n 4 sample-files/numbers.txt"
+run_test "-h -n fil src/lib.rs src/main.rs"
+run_test "-l { src/lib.rs src/main.rs"
+run_test "-c -l l src/lib.rs src/main.rs"
+
+# Clean up
+rm -f $trgrep_output_file $grep_output_file