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.

Revisions

  1. lastarc revised this gist Oct 7, 2021. 1 changed file with 38 additions and 23 deletions.
    61 changes: 38 additions & 23 deletions cm
    Original file line number Diff line number Diff line change
    @@ -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
  2. lastarc created this gist Oct 7, 2021.
    42 changes: 42 additions & 0 deletions cm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #!/usr/bin/env bash



    if [[ -n $1 ]]; then
    echo $1;
    # echo $2 $3 $4 $5;
    # if [[ $2 ]]; then
    # echo $#;
    # fi
    # exit;
    if [[ $2 == "--test" && $# == 5 ]]; then
    # ./crt.sh cleanfile --test <function> "<arguments>" "<result>"
    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\"
    df=$(diff <(echo "$result") <(echo "$5"));
    if [[ -z $df ]]; then
    echo "Success!";
    echo "Result: $result";
    else
    echo "Fail!";
    echo "Result: $result";
    fi
    else
    clear && clm -ms $1 -o $1 && ./$1;
    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.";
    fi