mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-26 01:15:27 +00:00
228 lines
4.9 KiB
Bash
Executable file
228 lines
4.9 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
# ================================================================
|
|
# This is similar to reg_test/run except that this one is only ever run
|
|
# manually, not automatically as part of the build. It can be used to iterate on
|
|
# as-yet-unreleased features (in particular, features whose definition isn't
|
|
# finalized) without breaking the build.
|
|
# ================================================================
|
|
set -e
|
|
|
|
ourdir=`dirname $0`
|
|
srcdir=$ourdir/../..
|
|
pwd=`pwd`
|
|
|
|
try1=$pwd/../mlr # For autoconf builds, in-tree or out-of-tree
|
|
try2=$srcdir/c/mlr # For non-autoconf builds
|
|
if [ -x "$try1" ]; then
|
|
path_to_mlr=$try1
|
|
elif [ -x "$try2" ]; then
|
|
path_to_mlr=$try2
|
|
else
|
|
echo "$0: Could not find path to mlr executable." 1>&2
|
|
echo "Try 1: $try1" 1>&2
|
|
echo "Try 2: $try2" 1>&2
|
|
exit 1
|
|
fi
|
|
do_diff="true"
|
|
|
|
for arg; do
|
|
if [ "$1" = "--valgrind" ]; then
|
|
# Leak-check the test suite. Needs 'make mlrg' first.
|
|
# ../tools/clean-valg can be used to filter the output.
|
|
path_to_mlr="valgrind --leak-check=full ${path_to_mlr}g"
|
|
elif [ "$1" = "--nodiff" ]; then
|
|
do_diff="false"
|
|
fi
|
|
done
|
|
echo Using mlr executable $path_to_mlr
|
|
|
|
indir=$ourdir/input
|
|
expdir=$ourdir/expected
|
|
outdir=$pwd/output
|
|
outfile=$outdir/out-dev
|
|
expfile=$expdir/out-dev
|
|
mkdir -p $outdir
|
|
|
|
rm -f $outfile
|
|
touch $outfile
|
|
echo
|
|
|
|
num_passed=0
|
|
|
|
announce() {
|
|
echo >> $outfile
|
|
echo "================================================================" >> $outfile
|
|
echo "$@" >> $outfile
|
|
echo >> $outfile
|
|
}
|
|
|
|
mention() {
|
|
echo >> $outfile
|
|
echo ---------------------------------------------------------------- "$@" >> $outfile
|
|
}
|
|
|
|
run_mlr() {
|
|
# Use just "mlr" for info messages
|
|
echo mlr "$@"
|
|
echo mlr "$@" >> $outfile
|
|
# Use path to mlr for invoking the command
|
|
$path_to_mlr "$@" >> $outfile
|
|
echo >> $outfile
|
|
# since set -e
|
|
num_passed=`expr $num_passed + 1`
|
|
}
|
|
|
|
# ================================================================
|
|
announce GRAMMAR REORG
|
|
|
|
mention simplest
|
|
run_mlr -n put -v ''
|
|
run_mlr -n put -v '$m=2'
|
|
run_mlr -n put -v '$m=2;$m=3'
|
|
run_mlr -n put -v '$m=2;$m=3;$m=4'
|
|
run_mlr -n put -v '$m=2;;$m=3;$m=4'
|
|
|
|
mention begin/main/end
|
|
# expect parse fail
|
|
#run_mlr -n put -v 'begin{$b=1};$m=2;end{$e=3}'
|
|
run_mlr -n put -v 'begin{@b=1};$m=2;end{@e=3}'
|
|
|
|
mention main:cond
|
|
run_mlr -n put -v 'true{$m=2}'
|
|
|
|
mention main:empty-for
|
|
run_mlr -n put -v 'for(k,v in $*) { }'
|
|
|
|
mention main:single-statement-for
|
|
run_mlr -n put -v 'for(k,v in $*) { $m=1}'
|
|
|
|
mention main:double-statement-for
|
|
run_mlr -n put -v 'for(k,v in $*) { $m=1;$m=2 }'
|
|
|
|
mention main:for w/ break/continue
|
|
run_mlr -n put -v 'for(k,v in $*) { $m=1;break;$m=2 }'
|
|
run_mlr -n put -v 'for(k,v in $*) { $m=1;break;continue;$m=2 }'
|
|
run_mlr -n put -v 'for(k,v in $*) { $m=1;break;continue;;$m=2 }'
|
|
|
|
mention main:for:cond
|
|
run_mlr -n put -v 'for(k,v in $*) { true{$m=3} }'
|
|
|
|
mention main:cond:for
|
|
run_mlr -n put -v 'true{ for(k,v in $*) { $m=1 } }'
|
|
run_mlr -n put -v 'true{ for(k,v in $*) { $m=1;break;continue;;$m=2 } }'
|
|
|
|
mention main:cond:for:cond
|
|
run_mlr -n put -v 'true{ for(k,v in $*) { true{$m=3} } }'
|
|
|
|
mention ifs
|
|
run_mlr -n put -v '
|
|
if (NR==1) {
|
|
$x = 2;
|
|
$x = 3
|
|
};
|
|
if (NR == 4) {
|
|
$x = 5;
|
|
$x = 6
|
|
} else {
|
|
$x = 7;
|
|
$x = 8
|
|
};
|
|
if (NR == 9) {
|
|
$x = 10;
|
|
$x = 11
|
|
} elif (NR == 12) {
|
|
$x = 13;
|
|
$x = 14
|
|
} else {
|
|
$x = 15;
|
|
$x = 16
|
|
};
|
|
if (NR == 17) {
|
|
$x = 18;
|
|
$x = 19
|
|
} elif (NR == 20) {
|
|
$x = 21;
|
|
$x = 22
|
|
} elif (NR == 23) {
|
|
$x = 24;
|
|
$x = 25
|
|
} else {
|
|
$x = 26;
|
|
$x = 27
|
|
};
|
|
if (NR == 28) {
|
|
$x = 29;
|
|
$x = 30
|
|
} elif (NR == 31) {
|
|
$x = 32;
|
|
$x = 33
|
|
} elif (NR == 34) {
|
|
$x = 35;
|
|
$x = 36
|
|
} elif (NR == 37) {
|
|
$x = 38;
|
|
$x = 39
|
|
} else {
|
|
$x = 40;
|
|
$x = 41
|
|
}'
|
|
|
|
mention ifs
|
|
run_mlr -n put -v '
|
|
if (NR==1) {
|
|
$x = 2;
|
|
$x = 3
|
|
};
|
|
if (NR == 4) {
|
|
$x = 5;
|
|
$x = 6
|
|
};
|
|
if (NR == 7) {
|
|
$x = 8;
|
|
$x = 9
|
|
} elif (NR == 10) {
|
|
$x = 11;
|
|
$x = 12
|
|
};
|
|
if (NR == 13) {
|
|
$x = 14;
|
|
$x = 15
|
|
} elif (NR == 16) {
|
|
$x = 17;
|
|
$x = 18
|
|
} elif (NR == 19) {
|
|
$x = 20;
|
|
$x = 21
|
|
};
|
|
if (NR == 22) {
|
|
$x = 23;
|
|
$x = 24
|
|
} elif (NR == 25) {
|
|
$x = 26;
|
|
$x = 27
|
|
} elif (NR == 28) {
|
|
$x = 29;
|
|
$x = 30
|
|
} elif (NR == 31) {
|
|
$x = 32;
|
|
$x = 33
|
|
}'
|
|
|
|
run_mlr --opprint put 'if(NR==2){$x=777}' $indir/abixy
|
|
run_mlr --opprint put 'if(NR==2){$x=777}elif(NR==4){$x=888}' $indir/abixy
|
|
run_mlr --opprint put 'if(NR==2){$x=777}elif(NR==4){$x=888}elif(NR==6){$x=999}' $indir/abixy
|
|
run_mlr --opprint put 'if(NR==2){$x=777}else{$x=0}' $indir/abixy
|
|
run_mlr --opprint put 'if(NR==2){$x=777}elif(NR==4){$x=888}else{$x=0}' $indir/abixy
|
|
run_mlr --opprint put 'if(NR==2){$x=777}elif(NR==4){$x=888}elif(NR==6){$x=999}else{$x=0}' $indir/abixy
|
|
|
|
# ================================================================
|
|
cat $outfile
|
|
|
|
if [ "$do_diff" = "true" ]; then
|
|
echo
|
|
diff -I '^mlr ' -C5 $expfile $outfile
|
|
echo diff OK # since set -e
|
|
echo ALL REGRESSION TESTS PASSED
|
|
echo Tests completed: $num_passed
|
|
fi
|