feat: add rust-script

This commit is contained in:
2022-08-06 01:14:04 +08:00
parent 70f202e982
commit a65b8f0aae
67 changed files with 5086 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
hello
2
3
4

View File

@@ -0,0 +1,7 @@
#!/bin/sh
set -e -u
rust-script -e 'println!("hello");'
rust-script -e '1+1'
rust-script -e '1+2'
rust-script -e '1+3'

View File

@@ -0,0 +1,6 @@
First:
1: line1
2: line2
Second:
1: line1
2: line2

View File

@@ -0,0 +1,10 @@
#!/bin/sh
set -e -u
echo "First:"
echo "line1\nline2" | rust-script --loop \
"let mut n=0; move |l| {n+=1; println!(\"{:>6}: {}\",n,l.trim_right())}"
echo "Second:"
echo "line1\nline2" | rust-script --count --loop \
"|l,n| println!(\"{:>6}: {}\", n, l.trim_right())"

View File

@@ -0,0 +1,40 @@
#!/bin/bash
set -e -u
ANY_ERROR=0
# Make sure newly built binary is first in PATH:
cargo build &> /dev/null || {
echo "ERROR: Compilation failed"
exit 1
}
export PATH=$PWD/target/debug/:$PATH
cd tests/scripts
for TEST_SCRIPT in *.script; do
EXPECTED_STDOUT=${TEST_SCRIPT/.script/.expected}
ACTUAL_STDOUT=${TEST_SCRIPT/.script/.actual-stdout}
ACTUAL_STDERR=${TEST_SCRIPT/.script/.actual-stderr}
echo -n "Running $TEST_SCRIPT ... "
./$TEST_SCRIPT > $ACTUAL_STDOUT 2> $ACTUAL_STDERR || {
ANY_ERROR=1
echo "Failed to run!"
}
if cmp -s "$EXPECTED_STDOUT" "$ACTUAL_STDOUT"; then
echo "Ok"
else
ANY_ERROR=1
echo "Failed!"
echo "######################## Expected:"
cat $EXPECTED_STDOUT
echo "######################## Actual:"
cat $ACTUAL_STDOUT
echo "######################## Error output:"
cat $ACTUAL_STDERR
echo "########################"
fi
done
exit $ANY_ERROR