Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

make clean && \
make bench && \
Expand Down
6 changes: 3 additions & 3 deletions coverage.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

export LLVM_PROFILE_FILE="$PWD/.coverage/chaos-%p.profraw" && \
make clean && \
Expand All @@ -13,7 +13,7 @@ make test-official-spells && \
make rosetta-install-clang && \
make rosetta-test && \
make rosetta-test-compiler && \
llvm-profdata merge -output=chaos.profdata $PWD/.coverage/chaos-*.profraw && \
llvm-profdata merge -output=chaos.profdata "$PWD/.coverage/chaos-*.profraw && \
rm $PWD/.coverage/chaos-*.profraw && \
llvm-cov show /usr/local/bin/chaos -instr-profile=chaos.profdata > coverage.txt && \
llvm-cov report /usr/local/bin/chaos -instr-profile=chaos.profdata -use-color && \
Expand All @@ -26,4 +26,4 @@ llvm-cov show /usr/local/bin/chaos -instr-profile=chaos.profdata \
./parser/*.c \
./preemptive/*.c \
./utilities/*.c \
-path-equivalence -use-color --format html > /tmp/coverage.html
-path-equivalence -use-color --format html > /tmp/coverage.html"
2 changes: 1 addition & 1 deletion profile.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

echo "Compiling with -fprofile-generate"
make clean && \
Expand Down
58 changes: 29 additions & 29 deletions tests/cli_args.sh
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
#!/bin/bash
#!/bin/sh

echo -e "\nINFO: Test the positional arguments (interpreter)\n"
chaos tests/everything.kaos && echo -e "\nOK\n\n" && \
chaos -d tests/everything.kaos && echo -e "\nOK\n\n" && \
printf "\nINFO: Test the positional arguments (interpreter)\n"
chaos tests/everything.kaos && printf "\nOK\n\n" && \
chaos -d tests/everything.kaos && printf "\nOK\n\n" && \

echo -e "\nINFO: Test no arguments (REPL)\n"
echo "exit" | chaos && echo -e "\nOK\n\n" && \
echo "exit" | chaos -d && echo -e "\nOK\n\n" && \
printf "\nINFO: Test no arguments (REPL)\n"
echo "exit" | chaos && printf "\nOK\n\n" && \
echo "exit" | chaos -d && printf "\nOK\n\n" && \

echo -e "\nINFO: Test compilation variants with short options\n"
printf "\nINFO: Test compilation variants with short options\n"
chaos -c tests/everything.kaos && \
[ -f build/main ] && \
echo -e "\nOK\n\n" && \
printf "\nOK\n\n" && \
chaos -c tests/everything.kaos -o everything && \
[ -f build/everything ] && \
echo -e "\nOK\n\n" && \
printf "\nOK\n\n" && \
chaos -c tests/everything.kaos -o everything -e "-ggdb" && \
[ -f build/everything ] && \
echo -e "\nOK\n\n" && \
printf "\nOK\n\n" && \
chaos -c tests/everything.kaos -o everything -e "-ggdb" -k && \
[ -f build/everything ] && \
[ -f build/everything.c ] && \
[ -f build/everything.h ] && \
echo -e "\nOK\n\n" && \
printf "\nOK\n\n" && \
chaos -c tests/everything.kaos -o everything -e "-ggdb" -kd && \
[ -f build/everything ] && \
[ -f build/everything.c ] && \
[ -f build/everything.h ] && \
echo -e "\nOK\n\n" && \
printf "\nOK\n\n" && \

echo -e "\nINFO: Test compilation variants with long options\n"
printf "\nINFO: Test compilation variants with long options\n"
chaos --compile tests/everything.kaos && \
[ -f build/main ] && \
echo -e "\nOK\n\n" && \
printf "\nOK\n\n" && \
chaos --compile tests/everything.kaos --output everything && \
[ -f build/everything ] && \
echo -e "\nOK\n\n" && \
printf "\nOK\n\n" && \
chaos --compile tests/everything.kaos --output everything --extra "-ggdb" && \
[ -f build/everything ] && \
echo -e "\nOK\n\n" && \
printf "\nOK\n\n" && \
chaos --compile tests/everything.kaos --output everything --extra "-ggdb" --keep && \
[ -f build/everything ] && \
[ -f build/everything.c ] && \
[ -f build/everything.h ] && \
echo -e "\nOK\n\n" && \
printf "\nOK\n\n" && \
chaos --compile tests/everything.kaos --output everything --extra "-ggdb" --keep --debug && \
[ -f build/everything ] && \
[ -f build/everything.c ] && \
[ -f build/everything.h ] && \
echo -e "\nOK\n\n" && \
printf "\nOK\n\n" && \

echo -e "\nINFO: Test other arguments\n"
printf "\nINFO: Test other arguments\n"
chaos -h && chaos --help && \
chaos -v && chaos --version && \
chaos -l && chaos --license && \
chaos -u tests/everything.kaos && chaos --unsafe tests/everything.kaos && \
echo -e "\nOK\n\n" && \
printf "\nOK\n\n" && \

echo -e "\nINFO: Test invalid argument messages with short options\n"
chaos -c || echo -e "\nOK\n\n" && \
chaos -c tests/everything.kaos -o || echo -e "\nOK\n\n" && \
chaos -o everything || echo -e "\nOK\n\n" && \
chaos -c tests/everything.kaos -o everything -e || echo -e "\nOK\n\n" && \
printf "\nINFO: Test invalid argument messages with short options\n"
chaos -c || printf "\nOK\n\n" && \
chaos -c tests/everything.kaos -o || printf "\nOK\n\n" && \
chaos -o everything || printf "\nOK\n\n" && \
chaos -c tests/everything.kaos -o everything -e || printf "\nOK\n\n" && \

echo -e "\nINFO: Test other erroring arguments\n"
printf "\nINFO: Test other erroring arguments\n"
chaos --no_such_arg || \
chaos no_such_file.kaos || \
echo -e "\nOK\n\n" && \
printf "\nOK\n\n" && \

echo -e "\nINFO: CLI arguments are OK."
printf "\nINFO: CLI arguments are OK."
28 changes: 14 additions & 14 deletions tests/compiler.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

extra_flags=""
EXTRA_FLAGS_ENABLED=false
Expand All @@ -19,27 +19,27 @@ while getopts ":e:" opt; do
esac
done

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$( cd "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"

failed=false

for filepath in $(find $DIR -maxdepth 1 -name '*.kaos'); do
filename=$(basename $filepath)
for filepath in $(find "$DIR" -maxdepth 1 -name '*.kaos'); do
filename=$(basename "$filepath")
testname="${filename%.*}"
out=$(<"$DIR/$testname.out")

@dumblob dumblob Oct 22, 2021

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be POSIX-compliant? I don't think cat is needed, but I didn't look it up in the spec...

Edit: Needless to say using cat here is always better because of better error handling. So this is just my thinking out loud.

I've checked it and the POSIX manual isn't explicit about this being disallowed or "non-POSIX" but e.g. dash doesn't seem to do the right thing, so I suppose it's definitely not portable and probably generally not considered POSIX compliant.

So thanks for spotting this (I myself wouldn't use $(<... because as I wrote above - error handling is better with cat).

out=$(cat "$DIR/$testname.out")

SKIP_TESTS="syntax_error preemptive"

if echo $SKIP_TESTS | grep -w $testname > /dev/null; then
if echo "$SKIP_TESTS" | grep -w "$testname" > /dev/null; then
continue
fi

echo "(compiler) Compiling test: ${testname}"

if [ "$EXTRA_FLAGS_ENABLED" = true ] ; then
cout=$(chaos -c tests/$filename -o $testname -e "$extra_flags" 2>&1)
cout=$(chaos -c "tests/$filename" -o "$testname" -e "$extra_flags" 2>&1)
else
cout=$(chaos -c tests/$filename -o $testname 2>&1)
cout=$(chaos -c "tests/$filename" -o "$testname" 2>&1)
fi
status=$?

Expand All @@ -53,21 +53,21 @@ for filepath in $(find $DIR -maxdepth 1 -name '*.kaos'); do
fi
done

for filepath in $(find $DIR -maxdepth 1 -name '*.kaos'); do
filename=$(basename $filepath)
for filepath in $(find "$DIR" -maxdepth 1 -name '*.kaos'); do
filename=$(basename "$filepath")
testname="${filename%.*}"
out=$(<"$DIR/$testname.out")
out=$(cat "$DIR/$testname.out")

SKIP_TESTS="syntax_error preemptive"

if echo $SKIP_TESTS | grep -w $testname > /dev/null; then
if echo "$SKIP_TESTS" | grep -w "$testname" > /dev/null; then
continue
fi

echo "(compiler) Running test: ${testname}"

test=$(build/$testname 2>&1)
if [ "$test" == "$out" ]
test=$("build/$testname" 2>&1)
if [ "$test" = "$out" ]
then
echo "OK"
else
Expand Down
32 changes: 16 additions & 16 deletions tests/interpreter.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#!/bin/sh

OPTS=`getopt \
OPTS=$(getopt \
-o ns --long no-shell \
-- "$@"`
-- "$@")
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
eval set -- "$OPTS"

Expand All @@ -24,19 +24,19 @@ while true; do
done


DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$( cd "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"

failed=false

for filepath in $(find $DIR -maxdepth 1 -name '*.kaos'); do
filename=$(basename $filepath)
for filepath in $(find "$DIR" -maxdepth 1 -name '*.kaos'); do
filename=$(basename "$filepath")
testname="${filename%.*}"
out=$(<"$DIR/$testname.out")
out=$(cat "$DIR/$testname.out")

echo "(interpreter) Running test: ${testname}"

test=$(chaos tests/$filename 2>&1)
if [ "$test" == "$out" ]
test=$(chaos "tests/$filename" 2>&1)
if [ "$test" = "$out" ]
then
echo "OK"
else
Expand All @@ -46,26 +46,26 @@ for filepath in $(find $DIR -maxdepth 1 -name '*.kaos'); do
fi
done

for filepath in $(find $DIR -maxdepth 1 -name '*.kaos'); do
filename=$(basename $filepath)
for filepath in $(find "$DIR" -maxdepth 1 -name '*.kaos'); do
filename=$(basename "$filepath")
testname="${filename%.*}"
out=$(<"$DIR/$testname.out")
out=$(cat "$DIR/$testname.out")

SKIP_TESTS="nonewline function decision everything syntax_error preemptive"

if echo $SKIP_TESTS | grep -w $testname > /dev/null; then
if echo "$SKIP_TESTS" | grep -w "$testname" > /dev/null; then
continue
fi

echo "(interpreter) Interactive test: ${testname}"

cd tests/

test=$(cat $filename | chaos 2>&1 | sed "s|.\[1;41m\s*||g" | sed "s|.\[0;41m\s*||g" \
test=$(cat "$filename" | chaos 2>&1 | sed "s|.\[1;41m\s*||g" | sed "s|.\[0;41m\s*||g" \
| sed "s|.\[1;44m\s*||g" | sed "s|\s*.\[0m||g" | sed "s|.\[5;42m\s*||g" | sed "s|.\[0;90m.*||g" \
| sed "s|.*\/chaos|File: \"~/chaos|g")

if [ "$test" == "$out" ]
if [ "$test" = "$out" ]
then
echo "OK"
else
Expand All @@ -78,7 +78,7 @@ for filepath in $(find $DIR -maxdepth 1 -name '*.kaos'); do
done

if [ "$SHELL" = true ] ; then
$DIR/shell/interpreter.sh
"$DIR/shell/interpreter.sh"
fi

if [ "$failed" = true ] ; then
Expand Down
29 changes: 15 additions & 14 deletions tests/memcheck.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
#!/bin/bash
#!/bin/sh

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
OSTYPE=$(uname --kernel-name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DIR="$( cd "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"

for filepath in $(find $DIR -maxdepth 1 -name '*.kaos'); do
filename=$(basename $filepath)
for filepath in $(find "$DIR" -maxdepth 1 -name '*.kaos'); do
filename=$(basename "$filepath")
testname="${filename%.*}"

if [[ "$testname" == "exit_"* ]]; then
if [ "$testname" = "exit_*" ]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird - can a file exit_* actually exist? Or is it a forgotten "stop iteration over an empty list" relic before for filepath in $(find "$DIR" -maxdepth 1 -name '*.kaos'); do was introduced (instead of presumably for filepath in exit_*; do)?

continue
fi

SKIP_TESTS="syntax_error preemptive"

if echo $SKIP_TESTS | grep -w $testname > /dev/null; then
if echo "$SKIP_TESTS" | grep -w "$testname" > /dev/null; then
continue
fi

echo -e "\n\n(interpreter) Running memcheck: ${testname}\n"
printf "\n\n(interpreter) Running memcheck: %s\n" "$testname"

if [[ "$OSTYPE" == "linux"* ]]; then
valgrind --tool=memcheck --leak-check=full --show-reachable=yes --num-callers=20 --track-fds=yes --track-origins=yes --error-exitcode=1 chaos $DIR/$filename || exit 1
elif [[ "$OSTYPE" == "darwin"* ]]; then
/tmp/DrMemory/bin64/drmemory -exit_code_if_errors 1 -suppress tests/shell/suppress.mac.txt -- chaos $DIR/$filename || exit 1
if [ "$OSTYPE" = "Linux" ]; then
valgrind --tool=memcheck --leak-check=full --show-reachable=yes --num-callers=20 --track-fds=yes --track-origins=yes --error-exitcode=1 chaos "$DIR/$filename" || exit 1
elif [ "$OSTYPE" = "Darwin" ]; then
/tmp/DrMemory/bin64/drmemory -exit_code_if_errors 1 -suppress tests/shell/suppress.mac.txt -- chaos "$DIR/$filename" || exit 1
fi
done

for dirpath in $(find $DIR -mindepth 1 -maxdepth 1 -type d); do
if [ -f $dirpath/memcheck.sh ]; then
$dirpath/memcheck.sh
for dirpath in $(find "$DIR" -mindepth 1 -maxdepth 1 -type d); do
if [ -f "$dirpath/memcheck.sh" ]; then
"$dirpath/memcheck.sh"
fi
done
Loading