Style tests on M1 Macs

Run style tests on M1 Macs

Prerequisites

  • Have Docker set up and at least once run setup_docker.sh from the Prog2 Docker Zip file

Installation of necessary tools

As soon as you have brew installed (/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)") run the following commands:

brew install cpplint
brew install cppcheck

Creation of style checker

Create a file called stylecheck.sh in your project directory and paste the following content:

echo Running cpplint
cpplint --filter=-legal/copyright,-build/include_subdir,-readability/casting ./include/*.h ./src/*.c 

echo Running cppcheck
cppcheck .

echo Running splint
CURDIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
BASE_COMMAND="docker run --rm --platform linux/amd64 -u prog2 -w /home/prog2 -v\"${CURDIR}\":/home/prog2/:z -it prog2"
SPLINT_COMMAND="splint -compdestroy -retvalother -retvalint -branchstate -exportlocal -usedef -compdef -temptrans +charint -predboolint -predboolothers -nullret -nullderef -nullpass -unrecog -mustdefine +matchanyintegral -mustfreefresh +ptrnegate -I include "
FILES="src/*.c"
for f in $FILES
do
  if [ "$f" != "src/unit_tests.c" ] && [ "$f" != "src/test_main.c" ]
  then
    SPLINT_COMMAND+="${f} "
  fi
done

eval "$BASE_COMMAND $SPLINT_COMMAND"

Now open your terminal at the project location and run chmod +x stylecheck.sh.

Usage

From now on, you can just run ./stylecheck.sh in your project directory to run the style checks.


Warning:

You will not get the color coded output you may be familiar with from make check. E. g. the splint check should output something like
image
if successful.

make check will still fail the style checks.

5 Likes