|
|
@@ -1,28 +1,34 @@ |
|
|
#!/usr/bin/env bash |
|
|
|
|
|
|
|
|
# Developed by Arc (github.com/lastarc) |
|
|
|
|
|
if [[ -n $1 ]]; then |
|
|
echo $1; |
|
|
# echo $2 $3 $4 $5; |
|
|
# if [[ $2 ]]; then |
|
|
# echo $#; |
|
|
# fi |
|
|
# exit; |
|
|
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 |
|
|
# ./crt.sh cleanfile --test <function> "<arguments>" "<result>" |
|
|
|
|
|
# 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"; |
|
|
# exit; |
|
|
mkdir -p tmp; |
|
|
cp $1.icl ./tmp/$1.icl; |
|
|
cd ./tmp; |
|
|
echo -e "\nStart = $3 $4 \n" >> ./$1.icl; |
|
|
clm -ms -nt $1 -o $1; |
|
|
result=$(./$1); |
|
|
cd ..; |
|
|
rm -r ./tmp; |
|
|
# echo \"$result\" \"$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!"; |
|
|
@@ -32,11 +38,20 @@ if [[ -n $1 ]]; then |
|
|
echo "Result: $result"; |
|
|
fi |
|
|
else |
|
|
clear && clm -ms $1 -o $1 && ./$1; |
|
|
( |
|
|
clear && |
|
|
cd "$fileDir" && |
|
|
clm -ms "$moduleName" -o "$moduleName" && |
|
|
./$moduleName |
|
|
) |
|
|
fi |
|
|
elif [[ -e $CL ]]; then |
|
|
clear && clm $CL -o $CL && ./$CL; |
|
|
else |
|
|
echo "You have to enter the module name as an agrument or |
|
|
have \$CL environmental variable set."; |
|
|
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 |