Skip to content

Instantly share code, notes, and snippets.

@lastarc
Last active October 7, 2021 16:53
Show Gist options
  • Select an option

  • Save lastarc/d7e5f753d881eca48a674b2850355361 to your computer and use it in GitHub Desktop.

Select an option

Save lastarc/d7e5f753d881eca48a674b2850355361 to your computer and use it in GitHub Desktop.
Bash script for compiling and running clean files, optionally enabling function testing
#!/usr/bin/env bash
# Developed by Arc (github.com/lastarc)
if [[ -n $1 ]]; then
fileDir="$( cd "$( dirname "$1" )" && pwd )";
fileName="$( basename $1 )";
moduleName="$( echo $fileName | sed -e "s/\.icl//" )";
filePath="$fileDir/$fileName";
echo "$fileDir/$fileName" $moduleName;
if [[ $2 == "--test" && $# == 5 ]]; then
# TODO: support testing files that already have Start statement
# i. e. --test "<result>"
# or functions doesn't need arguments
# i. e. --test <function> "<result>"
# a way to solve: dynamic arguments, at least one argument (result),
# additionals sent to Start statement
echo "Testing: $3 $4";
echo "Expecting: $5";
(
tempDir="/tmp/cm";
mkdir -p $tempDir;
cd $tempDir;
cp $filePath $fileName;
echo -e "\nStart = $3 $4 \n" >> $fileName;
clm -ms -nt $moduleName -o $moduleName;
result=$(./$moduleName);
rm -r $tempDir;
)
df=$(diff <(echo "$result") <(echo "$5"));
if [[ -z $df ]]; then
echo "Success!";
echo "Result: $result";
else
echo "Fail!";
echo "Result: $result";
fi
else
(
clear &&
cd "$fileDir" &&
clm -ms "$moduleName" -o "$moduleName" &&
./$moduleName
)
fi
else
echo "
You have to enter the module name as an agrument.
Additionally, you can set up testing by adding --test flag
with function name, arguments, and expected result:
cm <modulename> --test <function name> <arguments> <result>
Example:
\$ cm mycleanmodule --test sum \"[1..10]\" \"15\"
";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment