test-all.sh SHELL 370 lines View on github.com → Search inside
1#!/bin/bash23# make sure this script can be executed from any dir4cd $(dirname $0)56GREEN='\033[1;32m'7RED='\033[0;31m'8NC='\033[0m'910echo "Running go generate..."11go generate1213echo "Running go fmt..."14go fmt ./...1516echo "Running unit tests..."17go test ./... || exit1819# Race Detection20echo "Running race detection..."21if  go run --race . 2>&1 >/dev/null | grep -q "Found" ; then22    echo -e "${RED}======================================================="23    echo -e "FAILED race detection run 'go run --race .' to identify"24    echo -e "=======================================================${NC}"25    exit26else27    echo -e "${GREEN}PASSED race detection${NC}"28fi2930echo "Building application..."31go build -ldflags="-s -w" || exit323334echo "Building HTML report..."3536./scc --format html -a --by-file -i go -o SCC-OUTPUT-REPORT.html3738echo "Running integration tests..."3940## NB you need to have pyyaml installed via pip install pyyaml for this to work41#if ./scc "examples/language/" --format cloc-yaml -o .tmp_scc_yaml >/dev/null && python <<EOS42#import yaml,sys43#try:44#    with open('.tmp_scc_yaml','r') as f:45#        data = yaml.load(f.read())46#        if type(data) is dict and data.keys():47#            sys.exit(0)48#        else:49#            print('data was {}'.format(type(data)))50#except Exception as e:51#    pass52#sys.exit(1)53#EOS54#55#then56#	echo -e "${GREEN}PASSED cloc-yaml format test"57#else58#    echo -e "${RED}======================================================="59#    echo -e "${RED}FAILED Should accept --format cloc-yaml and should generate valid output"60#    echo -e "=======================================================${NC}"61#    rm -f .tmp_scc_yaml62#    exit63#fi64#65#if ./scc "examples/language/" --format cloc-yml -o .tmp_scc_yaml >/dev/null && python <<EOS66#import yaml,sys67#try:68#    with open('.tmp_scc_yaml','r') as f:69#        data = yaml.load(f.read())70#        if type(data) is dict and data.keys():71#            sys.exit(0)72#        else:73#            print('data was {}'.format(type(data)))74#except Exception as e:75#    pass76#sys.exit(1)77#EOS78#79#then80#	echo -e "${GREEN}PASSED cloc-yml format test"81#else82#    echo -e "${RED}======================================================="83#    echo -e "${RED}FAILED Should accept --format cloc-yml and should generate valid output"84#    echo -e "=======================================================${NC}"85#    rm -f .tmp_scc_yaml86#    exit87#fi8889if ./scc NOTAREALDIRECTORYORFILE > /dev/null ; then90    echo -e "${RED}================================================="91    echo -e "FAILED Invalid file/directory should produce error code "92    echo -e "=======================================================${NC}"93    exit94else95    echo -e "${GREEN}PASSED invalid file/directory test"96fi9798if ./scc > /dev/null ; then99    echo -e "${GREEN}PASSED no directory specified test"100else101    echo -e "${RED}======================================================="102    echo -e "FAILED Should run correctly with no directory specified"103    echo -e "=======================================================${NC}"104    exit105fi106107if ./scc processor > /dev/null ; then108    echo -e "${GREEN}PASSED directory specified test"109else110    echo -e "${RED}======================================================="111    echo -e "FAILED Should run correctly with directory specified"112    echo -e "=======================================================${NC}"113    exit114fi115116if ./scc --avg-wage 10000 --binary --by-file --no-cocomo --no-size --size-unit si --include-symlinks --debug --exclude-dir .git -f tabular -i go -c -d -M something -s name -w processor > /dev/null ; then117    echo -e "${GREEN}PASSED multiple options test"118else119    echo -e "${RED}======================================================="120    echo -e "FAILED Should run correctly with multiple options"121    echo -e "=======================================================${NC}"122    exit123fi124125if ./scc -i sh -M "vendor|examples|p.*" > /dev/null ; then126    echo -e "${GREEN}PASSED regular expression ignore test"127else128    echo -e "${RED}======================================================="129    echo -e "FAILED Should run with regular expression ignore"130    echo -e "=======================================================${NC}"131    exit132fi133134if ./scc "examples/shared_extension/" | grep -q "Coq"; then135    echo -e "${GREEN}PASSED shared extension test 1"136else137    echo -e "${RED}======================================================="138    echo -e "FAILED Should be able to work with shared extension 1"139    echo -e "=======================================================${NC}"140    exit141fi142143if ./scc "examples/shared_extension/" | grep -q "Verilog"; then144    echo -e "${GREEN}PASSED shared extension test 2"145else146    echo -e "${RED}======================================================="147    echo -e "FAILED Should be able to work with shared extension 2"148    echo -e "=======================================================${NC}"149    exit150fi151152if ./scc "examples/shared_extension/" | grep -q "V "; then153    echo -e "${GREEN}PASSED shared extension test 3"154else155    echo -e "${RED}======================================================="156    echo -e "FAILED Should be able to work with shared extension 3"157    echo -e "=======================================================${NC}"158    exit159fi160161if ./scc --ci | grep -q "\-\-\-\-"; then162    echo -e "${GREEN}PASSED ci param test"163else164    echo -e "${RED}======================================================="165    echo -e "FAILED Should be able to work with ci flag"166    echo -e "=======================================================${NC}"167    exit168fi169170if ./scc "examples/denylist/" | grep -q "Java"; then171    echo -e "${RED}======================================================="172    echo -e "FAILED Should hit default .git denylist "173    echo -e "=======================================================${NC}"174    exit175else176    echo -e "${GREEN}PASSED denylist test"177fi178179# Simple test to see if we get any concurrency issues180for i in {1..100}181do182    if ./scc > /dev/null ; then183        :184    else185        echo -e "${RED}======================================================="186        echo -e "FAILED Should not have concurrency issue"187        echo -e "=================================================${NC}"188        exit189    fi190done191echo -e "${GREEN}PASSED concurrency issue test"192193if ./scc main.go > /dev/null ; then194    echo -e "${GREEN}PASSED file specified test"195else196    echo -e "${RED}======================================================="197    echo -e "FAILED Should run correctly with a file is specified"198    echo -e "=================================================${NC}"199    exit200fi201202# Multiple directory or file arguments203if ./scc main.go README.md | grep -q "Go " ; then204    echo -e "${GREEN}PASSED multiple file argument test 1"205else206    echo -e "${RED}======================================================="207    echo -e "FAILED Should work with multiple file arguments 1"208    echo -e "=======================================================${NC}"209    exit210fi211212if ./scc main.go README.md | grep -q "Markdown " ; then213    echo -e "${GREEN}PASSED multiple file argument test 2"214else215    echo -e "${RED}======================================================="216    echo -e "FAILED Should work with multiple file arguments 2"217    echo -e "=======================================================${NC}"218    exit219fi220221if ./scc processor scripts > /dev/null ; then222    echo -e "${GREEN}PASSED multiple directory specified test"223else224    echo -e "${RED}======================================================="225    echo -e "FAILED Should run correctly with multiple directory specified"226    echo -e "=================================================${NC}"227    exit228fi229230# Check for multiple regex via https://github.com/andyfitzgerald231a=$(./scc --not-match="(.*\.hex|.*\.d|.*\.o|.*\.csv|^(./)?[0-9]{8}_.*)" . | grep Estimated | md5sum)232b=$(./scc --not-match=".*\.hex" --not-match=".*\.d" --not-match=".*\.o" --not-match=".*\.csv" --not-match="^(./)?[0-9]{8}_.*" . | grep Estimated | md5sum)233if [ "$a" == "$b" ]; then234    echo -e "${GREEN}PASSED multiple regex test"235else236    echo -e "${RED}======================================================="237    echo -e "FAILED multiple regex test"238    echo -e "=================================================${NC}"239    exit240fi241242a=$(./scc | grep Total)243b=$(./scc --no-ignore | grep Total)244if [ "$a" == "$b" ]; then245    echo "$a"246    echo "$b"247    echo -e "${RED}======================================================="248    echo -e "FAILED ignore filter"249    echo -e "=================================================${NC}"250    exit251else252    echo -e "${GREEN}PASSED ignore filter"253fi254255a=$(./scc -i js ./examples/minified/ --no-scc-ignore)256b=$(./scc -i js -z ./examples/minified/ --no-scc-ignore)257if [ "$a" == "$b" ]; then258    echo "$a"259    echo "$b"260    echo -e "${RED}======================================================="261    echo -e "FAILED Minified check"262    echo -e "=================================================${NC}"263    exit264else265    echo -e "${GREEN}PASSED minified check"266fi267268a=$(./scc -i js -z ./examples/minified/ --no-scc-ignore)269b=$(./scc -i js -z --no-min-gen ./examples/minified/ --no-scc-ignore)270if [ "$a" == "$b" ]; then271    echo "$a"272    echo "$b"273    echo -e "${RED}======================================================="274    echo -e "FAILED Minified ignored check"275    echo -e "=================================================${NC}"276    exit277else278    echo -e "${GREEN}PASSED minified ignored check"279fi280281if ./scc ./examples/minified/ --no-min-gen --no-scc-ignore | grep -q "\$0"; then282    echo -e "${GREEN}PASSED removed min"283else284    echo -e "${RED}======================================================="285    echo -e "FAILED removed min"286    echo -e "=======================================================${NC}"287    exit288fi289290if ./scc ./examples/generated/ --no-min-gen --no-scc-ignore | grep -q "\$0"; then291    echo -e "${GREEN}PASSED removed gen"292else293    echo -e "${RED}======================================================="294    echo -e "FAILED removed gen"295    echo -e "=======================================================${NC}"296    exit297fi298299if ./scc -z ./examples/generated/ --no-scc-ignore | grep -q "C Header (gen)"; then300    echo -e "${GREEN}PASSED flagged as gen"301else302    echo -e "${RED}======================================================="303    echo -e "FAILED flagged as gen"304    echo -e "=======================================================${NC}"305    exit306fi307308if ./scc ./examples/minified/ -i js -z --no-scc-ignore | grep -q "JavaScript (mi"; then309    echo -e "${GREEN}PASSED flagged as min"310else311    echo -e "${RED}======================================================="312    echo -e "FAILED flagged as min"313    echo -e "=======================================================${NC}"314    exit315fi316317if ./scc -z --min-gen-line-length 1 --no-min-gen . | grep -q "\$0"; then318    echo -e "${GREEN}PASSED min gen line length"319else320    echo -e "${RED}======================================================="321    echo -e "FAILED min gen line length"322    echo -e "=======================================================${NC}"323    exit324fi325326if ./scc --no-large --large-byte-count 0 ./examples/language | grep -q "\$0"; then327    echo -e "${GREEN}PASSED no large byte test"328else329    echo -e "${RED}======================================================="330    echo -e "FAILED no large byte test"331    echo -e "=======================================================${NC}"332    exit333fi334335if ./scc --no-large --large-line-count 0 ./examples/language | grep -q "\$0"; then336    echo -e "${GREEN}PASSED no large line test"337else338    echo -e "${RED}======================================================="339    echo -e "FAILED no large line test"340    echo -e "=======================================================${NC}"341    exit342fi343344echo -e  "${NC}Checking compile targets..."345346echo "   darwin..."347GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w"348GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w"349echo "   windows..."350GOOS=windows GOARCH=amd64 go build -ldflags="-s -w"351GOOS=windows GOARCH=386 go build -ldflags="-s -w"352GOOS=windows GOARCH=arm64 go build -ldflags="-s -w"353echo "   linux..."354GOOS=linux GOARCH=amd64 go build -ldflags="-s -w"355GOOS=linux GOARCH=386 go build -ldflags="-s -w"356GOOS=linux GOARCH=arm64 go build -ldflags="-s -w"357GOOS=linux GOARCH=riscv64 go build -ldflags="-s -w"358GOOS=linux GOARCH=loong64 go build -ldflags="-s -w"359360echo -e "${NC}Cleaning up..."361rm ./scc362rm ./scc.exe363rm .tmp_scc_yaml364rm ./code.db365366367echo -e "${GREEN}================================================="368echo -e "ALL TESTS PASSED"369echo -e "=================================================${NC}"

Findings

✓ No findings reported for this file.

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.