DIFF = diff
# Use this to configure diff output
DIFFFLAGS = # -u show context
GREP = grep
RM = rm

# Define INTERCEPT environment variable before calling make to interpose some
# other program before splint, e.g. 
# INTERCEPT = valgrind --leak-resolution=high --num-callers=20 --show-reachable=no --leak-check=no

RUNSPLINT    = $(INTERCEPT) $(SPLINT)
RUNSPLINTP   = $(RUNSPLINT) -nof
# Make sure .splintrc files are not used so test results do not
# depend on local settings.
RUNSPLINTRN  = $(RUNSPLINTP) -hints -booltype "bool"
RUNSPLINTR   = $(RUNSPLINTRN) -exportlocal +debugfcnconstraint

UNITTESTS = \
	    help \
	    abstptr \
	    abstract \
	    alias \
	    alttypes \
	    ansireserved \
	    argorder \
	    args \
	    arraydims \
	    arrayinit \
	    arraylit \
	    blocks \
	    branchstate \
	    break \
	    c99decl \
	    cases \
	    cast \
	    chararraylit \
	    charlit \
	    clauses \
	    commentchar \
	    compdestroy \
	    compoundliterals \
	    compoundstmt \
	    condifomit \
	    constannot \
	    controldepth \
	    csyntax \
	    czechnames \
	    czechoslovaknames \
	    deadparam \
	    decl \
	    divzero \
	    duffextensive \
	    ensures \
	    enum \
	    enuminitredeftype \
	    enumtag \
	    exports \
	    external \
	    fields \
	    flags \
	    forbody \
	    format \
	    freearray \
	    funcpointer \
	    functionmacro \
	    glob \
	    globals \
	    impabstract \
	    info \
	    init \
	    innerarray \
	    inparam \
	    internal \
	    iter \
	    keep \
	    libs \
	    linked \
	    lintcomments \
	    list \
	    longconstants \
	    longint \
	    loopexec \
	    looptesteffect \
	    macros \
	    macrosef \
	    malloc \
	    merge \
	    mergenull \
	    mixedstyle \
	    modifies \
	    modtest \
	    moduncon \
	    mongoincludes \
	    mystrncat \
	    noeffect \
	    null \
	    nullret \
	    nullassign \
	    numabstract \
	    observer \
	    oldstyle \
	    outglob \
	    outparam \
	    parentype \
	    postnotnull \
	    preds \
	    prefixes \
	    print \
	    printflike \
	    qualcombine \
	    rc \
	    refcounts \
	    release \
	    repexpose \
	    returned \
	    russian \
	    sharing \
	    shifts \
	    sizesigns \
	    slovaknames \
	    specclauses \
	    speccollision \
	    special \
	    stack \
	    staticarray \
	    strings \
	    stringliteral \
	    structassign \
	    typequals \
	    typeof \
	    ud \
	    ulstypes \
	    unaryop \
	    union \
	    unioninit \
	    unnamedsu \
	    unreachable \
	    unsignedcompare \
	    unused \
	    ullint \
	    utypes \
	    void \
	    variadicmacro \
	    widestrings

SUBDIRTESTS = \
	      metastate \
	      mergestate \
	      tainted \
	      fileio \
	      simplebufferConstraintTests \
	      moreBufferTests \
	      moreBufferTests2 \
	      globalbufferannotation \
	      maxset \
	      strchr \
	      sizeoftest \
	      skipheader \
	      enumredefmacro \
	      for \
	      manual\
	      tests2.2 \
	      tests2.2a \
	      tests2.4 \
	      tests2.5 \
	      db1 \
	      db2 \
	      db3

# doesn't work yet!
# SUBDIRTESTS += warnuse

SPLINTTESTS = $(UNITTESTS) $(SUBDIRTESTS)

QUICKTESTS = db3

.PHONY: check
check: fulltest

.PHONY: help

help:
	-@$(RUNSPLINT)
	-@$(RUNSPLINT) -help
	-@$(RUNSPLINTP) -asdf
	-@$(RUNSPLINTP) +boolint +boolint 
	-@$(RUNSPLINT) -help flags alpha

.PHONY: clean
clean:
	-@$(RM) -f *.out *.lcd *.lcs *.lh
	-@for dir in $(SUBDIRTESTS); do \
		$(MAKE) -C $$dir clean; \
	 done

## All tests need $(SPLINT) to be built

$(SPLINTTESTS): $(SPLINT)

## This is a kludgey way of processing the output to make it match exactly
## The last matcher is the most annoying, as it can differ (the first two are
##  pretty much fixed); usually, you'll have 'make[1]:', but on DOS it is
##  'make.exe[1]:' (it might even be 'c:/path/to/make.exe[1]:', but that's
##  not supported).
## The tests should really be re-done as shell-scripts or something... maybe
##  autotest could be used once it's finished.

CLEANOUTPUT = $(GREP) -v -F "$(SPLINT)" | $(GREP) -v -E "(Splint 3\.)|(^(g)?make((.*\[[0-9]+\]:)|( -e)))"

#drl 12/07/2002 These rules for .c and .expect files don't make sense
# and they are confusing make dist so I'm taking them out.

## Not real C code

#.c.expect:
#	$(MAKE) $* |& $(CLEANOUTPUT) >$*.expect && cat $*.expect
#
#.c.diff:
#	$(MAKE) $* |& $(CLEANOUTPUT) >$*.out && diff $*.expect $*.out


#drl temporally take this out.
#.PHONY: expects
#expects:
#	@echo "Saving old expects..."; \
#	 cat *.expect >expects-`date +"%y-%m-%d-%H"`
#	@for TEST in $(UNITTESTS) $(INTEGTESTS); do \
#	   echo "Making $$TEST.expect..."; \
#	   $(MAKE) $$TEST 2>&1 | $(CLEANOUTPUT) >$$TEST.expect; \
#	   cat $$TEST.expect; \
#	 done

.PHONY: quicktest
quicktest:
	@for TEST in $(QUICKTESTS); do \
	echo "Checking $$TEST..."; \
	    if $(MAKE) $$TEST 2>&1 | $(CLEANOUTPUT) >$$TEST.out && \
	       $(DIFF) $(DIFFFLAGS) $$TEST.expect $$TEST.out ; then \
	        rm -f $$TEST.out; \
	    else \
	    	echo "*** FAIL ***"; \
	    fi; \
	done

.PHONY: fulltest
fulltest:
	@echo "Testing $(SPLINT)..."
	@echo
	@echo "Version Info:"
	@$(RUNSPLINT) -help version
	@$(RUNSPLINT) -help vars
	@echo
	@echo "Tests:"
	@echo
	@for TEST in $(SPLINTTESTS); do \
	    echo "Checking $$TEST..."; \
	    if $(MAKE) $$TEST 2>&1 | $(CLEANOUTPUT) >$$TEST.out && \
	       $(DIFF) $(DIFFFLAGS) $$TEST.expect $$TEST.out ; then \
	        rm -f $$TEST.out; \
	    else \
		echo "*** FAIL ***"; \
	    fi; \
	done

### Rules for tests start here

.PHONY: abstptr
abstptr:
	-@$(RUNSPLINTR) abstptr -expect 9
	-@$(RUNSPLINTR) abstptr +voidabstract -expect 6

.PHONY: abstract
abstract:
	-@$(RUNSPLINTR) abst_t.lcl commentcmd.c -expect 15

.PHONY: alias
alias:
	-@$(RUNSPLINTR) +lh mut
	-@$(RUNSPLINTR) mut alias +globalias -expect 19
	-@$(RUNSPLINTR) mut alias2 +globalias -expect 17
	-@$(RUNSPLINTR) +lh alias3 -expect 14 
	-@$(RUNSPLINTR) +lh alias4 +boolint
	-@$(RUNSPLINTR) alias4 -pred +retalias -expect 6
	-@$(RUNSPLINTR) +lh alias5 +memchecks -null -specundef -expect 5
	-@$(RUNSPLINTR) globalalias.c -null -expect 5

.PHONY: alttypes
alttypes:
	-@$(RUNSPLINTR) alttypes.c -expect 2

###
### evans 2001-06-07 - updated nameCheck.c to reflect C9X.
### Reports one new errors for ansireserved.c - wctomb is bad even as a local
###    variable (could be a macro?)
### Reports 3 additional errors for +checks; no longer suppresses name errors
###    in the presense of other errors.
###

.PHONY: ansireserved
ansireserved:
	-@$(RUNSPLINTR) ansireserved.c +ansireserved -nolib -expect 9
	-@$(RUNSPLINTR) ansireserved.c +ansireserved +ansireservedlocal -nolib -expect 11
	-@$(RUNSPLINTRN) ansireserved.c +checks -exportlocal -exportheadervar -exportheader -expect 12
	-@$(RUNSPLINTR) ansireserved2.c +ansireserved -expect 1

.PHONY: argorder
argorder:
	-@$(RUNSPLINTR) argorder.c -expect 4
	-@$(RUNSPLINTR) argorder2  -expect 5
	-@$(RUNSPLINTR) argorder3.c -expect 8
	-@$(RUNSPLINTR) argorder4 -expect 9
	-@$(RUNSPLINTR) argorder4 -evalorder -expect 1
	-@$(RUNSPLINTR) argorder5.c +evalorderuncon -expect 3

.PHONY: args
args:
	-@$(RUNSPLINTR) args -noeffect -expect 12

.PHONY: arraydims
arraydims:
	-@$(RUNSPLINTR) arraydims.c -varuse -expect 2
	-@$(RUNSPLINTR) arraydims.c -initsize -varuse

.PHONY: arrayinit
arrayinit:
	-@$(RUNSPLINTR) arrayinit.c -expect 9

.PHONY: arraylit
arraylit:
	-@$(RUNSPLINTR) arraylit.c -expect 2
	-@$(RUNSPLINTR) arraylit.c +stringliteralsmaller -expect 4

.PHONY: blocks
blocks:
	-@$(RUNSPLINTR) blocks.c -expect 4
	-@$(RUNSPLINTR) blocks.c +ifblock +elseifcomplete -expect 7
	-@$(RUNSPLINTR) blocks.c -ifempty +whileempty +whileblock -expect 3
	-@$(RUNSPLINTR) blocks.c -ifempty +forempty +forblock -expect 3
	-@$(RUNSPLINTR) blocks.c +allempty -expect 6
	-@$(RUNSPLINTRN) blocks.c +strict -exportlocal +partial -exportheader -expect 11

.PHONY: branchstate
branchstate:
	-@$(RUNSPLINTP) branchstate.c -branchstate -expect 1

.PHONY: break
break:
	-@$(RUNSPLINTR) break.c -expect 4
	-@$(RUNSPLINTR) break.c +deepbreak -expect 6
	-@$(RUNSPLINTR) break.c +deepbreak -looploopbreak -expect 5

.PHONY: c99decl
c99decl:
	-@$(RUNSPLINTRN) c99decl.c -expect 6

.PHONY: cases
cases: 
	-@$(RUNSPLINTR) cases.c -expect 5
	-@$(RUNSPLINTR) cases2.c -expect 2
	-@$(RUNSPLINTRN) cases2.c +checks -exportlocal -exportheader -expect 3
	-@$(RUNSPLINTRN) cases2.c +checks -exportlocal -exportheader -branchstate -expect 3

.PHONY: cast
cast:
	-@$(RUNSPLINTR) cast -accessmodule -expect 20
	-@$(RUNSPLINTRN) cast2.c +checks -exportlocal -exportheader -expect 3

.PHONY: chararraylit
chararraylit:
	-@$(RUNSPLINTR) chararraylit.c -expect 2

### Two addition errors detected with 2.5 with -numliteral.

### evans 2002-12-15: finds one more but in charlit
.PHONY: charlit
charlit:
	-@$(RUNSPLINTR) +hints charlit.c -expect 4
	-@$(RUNSPLINTR) +hints -numliteral charlit.c -expect 6
	-@$(RUNSPLINTR) +hints charlit.c +charintliteral +ignoresigns -expect 1

.PHONY: clauses
clauses: 
	-@$(RUNSPLINTR) clauses.c +memchecks -expect 4
	-@$(RUNSPLINTR) clauses2.c +memchecks 
	-@$(RUNSPLINTR) clauses3.c +memchecks -expect 2
	-@$(RUNSPLINTR) clauses3.c +memchecks +unixlib -expect 3

.PHONY: commentchar
commentchar:
	-@$(RUNSPLINTR) commentchar.c -expect 4
	-@$(RUNSPLINTR) -commentchar '#' commentchar.c -expect 4

.PHONY: controldepth
controldepth:
	-@$(RUNSPLINTR) +hints -controlnestdepth 2 controldepth.c -expect 2
	-@$(RUNSPLINTR) +hints -controlnestdepth 1 controldepth.c -expect 2

###
### 1 extra warning reported for +strict now because of out-of-bounds read
###

.PHONY: compdestroy
compdestroy:
	-@$(RUNSPLINTRN) compdestroy.c +checks -exportlocal -exportheader -expect 1
	-@$(RUNSPLINTRN) compdestroy.c +checks -exportlocal -exportheader +strictdestroy -expect 2
	-@$(RUNSPLINTRN) compdestroy.c +checks -exportlocal -exportheader +strictdestroy +strictusereleased -expect 3
	-@$(RUNSPLINTRN) compdestroy.c +strict +partial -exportheader -expect 4

.PHONY: compoundliterals
compoundliterals:
	-@$(RUNSPLINTRN) compoundliterals.c 

.PHONY: compoundstmt
compoundstmt:
	-@$(RUNSPLINTRN) compoundstmt.c -expect 3

.PHONY: condifomit
condifomit:
	-@$(RUNSPLINTRN) -gnuextensions condifomit.c -expect 4
	-@$(RUNSPLINTRN) +gnuextensions condifomit.c -expect 1

.PHONY: constannot
constannot:
	-@$(RUNSPLINTRN) constannot.c +boundswrite -exportlocal -expect 2

.PHONY: csyntax
csyntax:
	-@$(RUNSPLINTR) +quiet -incondefs csyntax.c -expect 1 
	-@$(RUNSPLINTR) +quiet csyntax2.c -expect 2
	-@$(RUNSPLINTR) +quiet csyntax3.c -expect 1
	-@$(RUNSPLINTR) +quiet -incondefs csyntax4.c
	-@$(RUNSPLINTR) +quiet csyntax5.c
	-@$(RUNSPLINTR) +quiet csyntax6.c
	-@$(RUNSPLINTR) +quiet csyntax7.c
	-@$(RUNSPLINTR) +quiet csyntax8.c
	-@$(RUNSPLINTR) +quiet csyntax9.c
	-@$(RUNSPLINTR) +quiet csyntax10.c
	-@$(RUNSPLINTR) +quiet csyntax11.c
	-@$(RUNSPLINTR) +quiet csyntax12.c
	-@$(RUNSPLINTR) +quiet csyntax13.c -expect 1
	-@$(RUNSPLINTR) +quiet csyntax14.c
	-@$(RUNSPLINTR) +quiet csyntax15.c
	-@$(RUNSPLINTR) +quiet csyntax16.c -expect 2
	-@$(RUNSPLINTR) +quiet csyntax17.c -expect 3

.PHONY: czechnames
czechnames:
	-@$(RUNSPLINTR) czechnames.c
	-@$(RUNSPLINTR) +hints +czech czechnames.c -expect 2
	-@$(RUNSPLINTR) +hints +czech -czechvars czechnames.c -expect 1
	-@$(RUNSPLINTR) +hints +czech -accessczech czechnames.c -expect 6

.PHONY: czechoslovaknames
czechoslovaknames:
	-@$(RUNSPLINTR) +hints +czechoslovak czechnames.c -expect 1
	-@$(RUNSPLINTR) +hints +czechoslovak slovaknames.c -expect 1
	-@$(RUNSPLINTR) +hints +czechoslovak +slovakvars slovaknames.c -expect 2

###
### deadparam added 2001-05-27
###

.PHONY: deadparam
deadparam:
	-@$(RUNSPLINTR) deadparam.c -expect 3

#
# Was expect 3 before 2.4.  Earlier versions did not handle implicit
# function pointers correctly.
#

.PHONY: decl
decl:
	-@$(RUNSPLINTR) decl.c -expect 2
	-@$(RUNSPLINTRN) decl.c +strict -exportlocal -expect 6
	-@$(RUNSPLINTR) decl2 -expect 4

.PHONY: divzero
divzero:
	-@$(RUNSPLINTR) divzero.c -varuse

.PHONY: duffextensive
duffextensive:
	-@$(RUNSPLINTR) -casebreak -firstcase duffextensive.c

.PHONY: ensures
ensures:
	-@$(RUNSPLINTR) ensures.c -expect 4

.PHONY: enum
enum:
	-@$(RUNSPLINTR) enum -expect 16
	-@$(RUNSPLINTR) enum -misscase -expect 14

.PHONY: enuminitredeftype
enuminitredeftype:
	-@$(RUNSPLINTR) enuminitredeftype.c -expect 4

.PHONY: enumtag
enumtag:
	-@$(RUNSPLINTR) enumtag.c -expect 2

.PHONY: exports
exports:
	-@$(RUNSPLINTR) exports.c +exporttype +exportvar +exportfcn +topuse +typeuse -expect 6
	-@$(RUNSPLINTR) exports.c +exportany -expect 3
	-@$(RUNSPLINTR) exports.c

.PHONY: external
external:
	-@$(RUNSPLINTR) external.c +partial
	-@$(RUNSPLINTR) external.c +partial +distinctexternalnames +ansi89limits -expect 2
	-@$(RUNSPLINTR) external.c -nolib +partial -externalnamelength 3 -expect 3
	-@$(RUNSPLINTR) external.c -nolib +partial -externalnamelength 3 +externalnamecaseinsensitive -expect 3
	-@$(RUNSPLINTR) external.c +partial -externalnamelength 3 -expect 4

.PHONY: fields
fields:
	-@$(RUNSPLINTR) fields.c +memchecks -expect 6
	-@$(RUNSPLINTR) fields2.c +memchecks -expect 5
	-@$(RUNSPLINTR) fields3.c +memchecks

.PHONY: flags
flags:
	-@$(RUNSPLINTR) flags.c -expect 8
	-@$(RUNSPLINTR) +nocomments flags.c -expect 2

### Added 2001-06-02

.PHONY: forbody
forbody:
	-@$(RUNSPLINTR) forbody.c -expect 2

### Added 2001-06-03
.PHONY: format
format:
	-@$(RUNSPLINTR) format.c -expect 3
	-@$(RUNSPLINTR) format.c -formatconst 

.PHONY: funcpointer
funcpointer:
	-@$(RUNSPLINTR) +memchecks +noparams funcpointer.c -expect 19

.PHONY: functionmacro
functionmacro:
	-@$(RUNSPLINTR) functionmacro.c -expect 1
	-@$(RUNSPLINTR) -gnu-extensions -DGNU functionmacro.c -expect 2

.PHONY: glob
glob:
	-@$(RUNSPLINTR) glob -expect 4
	-@$(RUNSPLINTR) glob -globuse -expect 3
	-@$(RUNSPLINTR) glob +globunspec -expect 6

.PHONY: globals
globals:
	-@$(RUNSPLINTR) -modifies globals.c -expect 5
	-@$(RUNSPLINTR) -modifies globals.c +allglobals -expect 6
	-@$(RUNSPLINTR) -modifies globals.c +impcheckedglobals -expect 6
	-@$(RUNSPLINTR) -modifies globals.c -globals -checkstrictglobals -expect 2
	-@$(RUNSPLINTR) -modifies globals.c +globunspec -expect 6
	-@$(RUNSPLINTR) -modifies globals.c +globunspec +allglobals -expect 8

# Was -accessfile
.PHONY: impabstract
impabstract: 
	-@$(RUNSPLINTR) -accessmodule impabstract.c 
	-@$(RUNSPLINTR) -accessmodule +hints +impabstract impabstract.c -expect 2
	-@$(RUNSPLINTR) -accessmodule +hints +impabstract impabstract -expect 4

###
### evans 2001-12-30: Handle unrecognized pre-processor directives
###    (Reported by Pierluigi Sanzani)

.PHONY: info
info:
	-@$(RUNSPLINTR) info.c -expect 4

### evans 2001-10-14: Expected errors updated
.PHONY: init
init:
	-@$(RUNSPLINTR) init.c -expect 14
	-@$(RUNSPLINTRN) init.c +checks -exportlocal -exportheadervar -expect 17

### evans 2003-09-16
.PHONY: innerarray
innerarray:
	-@$(RUNSPLINTR) innerarray.c -expect 10

.PHONY: inparam
inparam:
	-@$(RUNSPLINTR) inparam.c -expect 2
	-@$(RUNSPLINTR) +impouts inparam.c -expect 1

.PHONY: internal
internal:
	-@$(RUNSPLINTR) internal.c -expect 1
	-@$(RUNSPLINTR) internal.c +distinctinternalnames -expect 1
	-@$(RUNSPLINTR) internal.c +distinctinternalnames +ansi89limits -expect 2
	-@$(RUNSPLINTR) internal.c -internalnamelen 28 -expect 3
	-@$(RUNSPLINTR) internal.c +internalnamecaseinsensitive -expect 3
	-@$(RUNSPLINTR) internal.c +internalnamecaseinsensitive +internalnamelookalike -expect 11

.PHONY: iter
iter:
	-@$(RUNSPLINTR) iter -expect 15 -lclexpect 1
	-@$(RUNSPLINTR) iter2.c -expect 13

.PHONY: keep
keep:
	-@$(RUNSPLINTR) keep.c +memchecks -expect 6

### libs
### 2001-05-22: 2 new errors found (fixed spec of signal)
### 2001-05-30: 3 new errors found (formatconst)
### 2002-07-08: 2 new errors found (getc modifies errno)

.PHONY: libs
libs:
	-@$(RUNSPLINTR) libs.c +longunsignedunsignedintegral -expect 18
	-@$(RUNSPLINTR) libs.c -expect 22
	-@$(RUNSPLINTR) libs.c +globunspec +modunspec -expect 25
	-@$(RUNSPLINTR) libs.c +strictlib +globunspec +modunspec -expect 44

.PHONY: lintcomments
lintcomments:
	-@$(RUNSPLINTR) lintcomments.c -expect 5
	-@$(RUNSPLINTR) lintcomments.c -warnlintcomments -expect 1
	-@$(RUNSPLINTR) lintcomments.c -lintcomments -expect 4

.PHONY: list
list:
	-@$(RUNSPLINTR) list.c -expect 3

.PHONY: longconstants
longconstants:
	-@$(RUNSPLINTR) longconstants.c -expect 1

###
### 2002-12-12: Added test case for +longint and +shortint flags
###

.PHONY: longint
longint:
	-@$(RUNSPLINTR) longint.c -expect 3
	-@$(RUNSPLINTR) longint.c +longint -expect 2
	-@$(RUNSPLINTR) longint.c +shortint -expect 2
	-@$(RUNSPLINTR) longint.c +shortint +longint -expect 0

###
### 2002-01-01: Added test case for obvious loop execution.
###

.PHONY: loopexec
loopexec:
	-@$(RUNSPLINTR) loopexec.c -expect 1
	-@$(RUNSPLINTR) loopexec.c -obviousloopexec -expect 3

.PHONY: looptesteffect
looptesteffect:
	-@$(RUNSPLINTR) looptesteffect.c -expect 1

.PHONY: macros
macros:
	-@$(RUNSPLINTR) macros -expect 17 
	-@$(RUNSPLINTR) macros.c +allmacros -expect 34
	-@$(RUNSPLINTR) macros.c +fcnmacros -expect 31


.PHONY: macrosef
macrosef:
	-@$(RUNSPLINTR) macrosef -expect 4
	-@$(RUNSPLINTR) macrosef.c +allmacros -expect 3
	-@$(RUNSPLINTR) macrosef.c +allmacros +sefuncon -expect 4

.PHONY: malloc
malloc:
	-@$(RUNSPLINTRN) malloc.c +bounds -exportlocal -expect 7

.PHONY: merge
merge:
	-@$(RUNSPLINTRN) merge.c +checks -exportlocal -exportheadervar -exportheader -expect 3

.PHONY: mergenull
mergenull:
	-@$(RUNSPLINTRN) mergenull.c 

.PHONY: mixedstyle
mixedstyle:
	-@$(RUNSPLINTRN) +try-to-recover mixedstyle.c -expect 2

.PHONY: modifies
modifies:
	-@$(RUNSPLINTR) modifies.c modclient.c +impcheckedstatics +mustmod -expect 7

.PHONY: modtest
modtest:
	-@$(RUNSPLINTR) modtest -expect 10
	-@$(RUNSPLINTR) modtest +modunspec -expect 13
	-@$(RUNSPLINTR) modtest +mustmod -expect 14

.PHONY: moduncon
moduncon:
	-@$(RUNSPLINTR) moduncon.c +moduncon -memchecks -expect 4
	-@$(RUNSPLINTRN) moduncon.c +strict +impboundsconstraints -exportlocal -expect 22 

.PHONY: mongoincludes
mongoincludes:
	-@$(RUNSPLINTR) mongoincludes.c -includenest 1 -expect 19
	-@$(RUNSPLINTR) mongoincludes.c -includenest 2 -expect 10
	-@$(RUNSPLINTR) mongoincludes.c -includenest 3 -expect 4
	-@$(RUNSPLINTR) mongoincludes.c -includenest 4 -expect 1
	-@$(RUNSPLINTR) mongoincludes.c -includenest 5 -expect 0

.PHONY: mystrncat
mystrncat:
	-@$(RUNSPLINTR) mystrncat.c +boundsread +boundswrite -expect 4 

.PHONY: noeffect
noeffect:
	-@$(RUNSPLINTP) noeffect.c +allmacros +checks -expect 3

###
### 2002-01-01: null1.c: expect increased to 15 because out must be defined
###                         checking detects one new error
###

.PHONY: null
null: 
	-@$(RUNSPLINTR) null1.c -expect 15
	-@$(RUNSPLINTR) null1.c -null -mustdefine -expect 4
	-@$(RUNSPLINTR) null2.c -expect 11
	-@$(RUNSPLINTR) null3.c -expect 15
	-@$(RUNSPLINTR) null3.c +unixlib -expect 16
	-@$(RUNSPLINTR) null4.c -expect 1
	-@$(RUNSPLINTR) null5.c -expect 4
	-@$(RUNSPLINTR) null6 -expect 4
	-@$(RUNSPLINTR) +quiet null6.lcl -dump null6
	-@$(RUNSPLINTR) null6.c -load null6 -expect 4

### Added for 3.0 (bugs reported by Kevin Broady)

.PHONY: nullret
nullret:
	-@$(RUNSPLINTR) nullret.c -expect 2
	-@$(RUNSPLINTR) -nullret nullret.c -expect 0

.PHONY: nullassign
nullassign:
	-@$(RUNSPLINTR) nullassign.c -expect 2
	-@$(RUNSPLINTR) -nullassign nullassign.c -expect 1


### Added for 3.1 - evans 2002-12-14

.PHONY: numabstract
numabstract:
	-@$(RUNSPLINTR) numabstract.c -expect 11
	-@$(RUNSPLINTR) numabstract.c +numabstractlit -expect 9
	-@$(RUNSPLINTR) numabstract.c -numabstractcast -expect 10

#
# Before 2.4, expected one more because error was reported both as 
# dependent and observer.
#

.PHONY: observer
observer:
	-@$(RUNSPLINTRN) observer +checks -exportlocal -exportheader -expect 9
	-@$(RUNSPLINTRN) observer.c +checks -exportlocal -exportheader -expect 8
	-@$(RUNSPLINTR) observer.c -expect 7

.PHONY: oldstyle
oldstyle:
	-@$(RUNSPLINTR) oldstyle oldstyle2.c -expect 6

.PHONY: outglob
outglob:
	-@$(RUNSPLINTR) outglob -expect 10

.PHONY: outparam
outparam:
	-@$(RUNSPLINTR) outparam -expect 12

### evans 2001-08-26: postnotnull new

.PHONY: postnotnull
postnotnull:
	-@$(RUNSPLINTR) postnotnull.c -expect 1

### evans 2002-02-09: added parentype.c
.PHONY: parentype
parentype:
	-@$(RUNSPLINTR) parentype.c 

#
# Four new +fcnuse errors for -strict (evans 2001-07-22)
# 

.PHONY: preds
preds:
	-@$(RUNSPLINTR) +hints preds.c -expect 6
	-@$(RUNSPLINTRN) +hints preds.c -weak -expect 1
	-@$(RUNSPLINTRN) +hints preds.c -strict +impboundsconstraints -exportlocal -exportheader -expect 10

.PHONY: prefixes
prefixes:
	-@$(RUNSPLINTR) prefixes.c +partial
	-@$(RUNSPLINTRN) prefixes.c +allmacros +checks -exportlocal +partial -exportheader -exportheadervar -expect 4
	-@$(RUNSPLINTR) prefixes.c -typeprefix "T" -expect 2
	-@$(RUNSPLINTR) prefixes.c -typeprefix "^" -expect 1
	-@$(RUNSPLINTR) prefixes.c -typeprefix "^*" -expect 2
	-@$(RUNSPLINTR) prefixes.c -typeprefix "^%*" -expect 2
	-@$(RUNSPLINTR) prefixes.c -typeprefix "^~*" -expect 2
	-@$(RUNSPLINTR) prefixes.c -typeprefix "^" +typeprefixexclude -expect 7
	-@$(RUNSPLINTR) prefixes.c -filestaticprefix "^^" -expect 4
	-@$(RUNSPLINTR) prefixes.c -filestaticprefix "^#" -expect 5
	-@$(RUNSPLINTR) prefixes.c -filestaticprefix "^?&x" -expect 5
	-@$(RUNSPLINTR) prefixes.c -globalprefix "G" -expect 1
	-@$(RUNSPLINTR) prefixes.c -globalprefix "&G?_^" -expect 1
	-@$(RUNSPLINTR) prefixes.c -externalprefix "G" -expect 5
	-@$(RUNSPLINTR) prefixes.c -typeprefix "T" -externalprefix "G" -expect 4
	-@$(RUNSPLINTR) prefixes.c -localprefix "?*" +localprefixexclude -expect 13

.PHONY: print
print:
	-@$(SPLINT) print.c -expect 1

.PHONY: printflike
printflike:
	-@$(RUNSPLINTR) printflike.c -expect 6
	-@$(RUNSPLINTR) printflike.c -warnlintcomments -expect 5

.PHONY: qualcombine
qualcombine:
	-@$(RUNSPLINTR) qualcombine.c -expect 82

#
# This is actually not a good test, as it tries to test a feature (rc)
# in combination with another one: preprocessor (un)defines [-D/-U].
# The problem is that -U implementation actually has a bug, thus this
# test can't really test all that it intended to check.

.PHONY: rc
rc:
	-@$(RUNSPLINTR) -DMYSTERY='"a flag\"wicked cool"' rc.c -expect 1
	-@$(RUNSPLINTR) -DMYSTERY=12 rc.c -expect 1
	-@$(RUNSPLINTR) -f rc1.splintrc rc.c -expect 1
	-@$(RUNSPLINTR) -UMYSTERY -f rc1.splintrc rc.c
	-@$(RUNSPLINTR) -f rc3.splintrc rc.c -expect 1

.PHONY: refcounts
refcounts:
	-@$(RUNSPLINTR) refcounts.c -expect 7 

.PHONY: release
release:
	-@$(RUNSPLINTR) release.c +memchecks -expect 1

.PHONY: repexpose
repexpose:
	-@$(RUNSPLINTR) +lh repexpose +memchecks -expect 12
	-@$(RUNSPLINTR) repexpose +memchecks +retalias -expect 15
	-@$(RUNSPLINTRN) repexpose +checks -exportlocal -expect 27

### returned added 2001-05-27
### (Bug discovered checking splint sources.)

.PHONY: returned
returned:
	-@$(RUNSPLINTR) returned.c -expect 1

### russian added 2003-06-07: bug reported in pre-processing non-standard characters.
.PHONY: russian
russian:
	-@$(RUNSPLINTR) russian.c 

.PHONY: sharing
sharing: 
	-@$(RUNSPLINTR) sharing1.c -expect 21
	-@$(RUNSPLINTR) sharing3.c -expect  3
	-@$(RUNSPLINTR) sharing4.c -expect 13
	-@$(RUNSPLINTR) sharing4.c -paramimptemp -expect 12
	-@$(RUNSPLINTR) sharing5.c -expect 6

.PHONY: shifts
shifts:
	-@$(RUNSPLINTR) shifts.c -expect 4
	-@$(RUNSPLINTR) shifts.c -shiftimplementation -expect 3
	-@$(RUNSPLINTR) shifts.c -shiftnegative -expect 1

#drl comment this out until sizesigns is added to cvs

### evans - added 2002-08-17: check warnings with arbitrary integral types
sizesigns:
	-@$(RUNSPLINTR) +strict sizesigns.c -expect 5
	-@$(RUNSPLINTR) +strict +matchanyintegral sizesigns.c -expect 4

.PHONY: slovaknames
slovaknames:
	-@$(RUNSPLINTR) +hints slovaknames.c -expect 1
	-@$(RUNSPLINTR) +hints slovaknames.c +accessslovak 
	-@$(RUNSPLINTR) +hints +slovak slovaknames.c -expect 3
	-@$(RUNSPLINTR) +hints +slovak -slovakvars slovaknames.c -expect 2
	-@$(RUNSPLINTR) +hints +slovak -accessslovak slovaknames.c -expect 7

##
## evans 2002-07-22: 1 less warning for specclauses3.c because of NULL result
##

.PHONY: specclauses
specclauses:
	-@$(RUNSPLINTR) specclauses.c -expect 6
	-@$(RUNSPLINTR) specclauses2.c -expect 8
	-@$(RUNSPLINTR) specclauses3.c -expect 5
	-@$(RUNSPLINTR) specclauses4.c -expect 3
	-@$(RUNSPLINTR) specclauses5.c -expect 3

.PHONY: speccollision
speccollision:
	-@$(RUNSPLINTR) speccollision.c

.PHONY: special
special:
	-@$(RUNSPLINTR) special -expect 22
	-@$(RUNSPLINTR) special -relaxquals -expect 24

.PHONY: stack
stack:
	-@$(RUNSPLINTR) stack.c -expect 5
	-@$(RUNSPLINTR) stack.c -stackref

.PHONY: staticarray
staticarray:
	-@$(RUNSPLINTR) staticarray.c -expect 3

.PHONY: stringliteral
stringliteral:
	-@$(RUNSPLINTR) stringliteral.c -stringliteralnoroomfinalnull -expect 3
	-@$(RUNSPLINTR) stringliteral.c -stringliterallen 160 -expect 5

.PHONY: strings
strings:
	-@$(RUNSPLINTR) strings.c -expect 3
	-@$(RUNSPLINTR) -readonlystrings -expect 1 strings.c
	-@$(RUNSPLINTR) +modobserverstrict -maintype -expect 4 strings.c

.PHONY: structassign
structassign:
	-@$(RUNSPLINTR) structassign.c -expect 4

.PHONY: typeof
typeof:
	-@$(RUNSPLINTR) typeof.c -expect 2

.PHONY: typequals
typequals:
	-@$(RUNSPLINTR) typequals.c tq.lcl -expect 5
	-@$(RUNSPLINTR) typequals.c -expect 2

.PHONY: ud
ud:
	-@$(RUNSPLINTR) ud.c -expect 9
	-@$(RUNSPLINTR) ud2 -specundef -expect 3

.PHONY: ulstypes
ulstypes:
	-@$(RUNSPLINTR) ulstypes.c -expect 8
	-@$(RUNSPLINTR) ulstypes.c +ignorequals 
	-@$(RUNSPLINTRN) ulstypes.c +strict -exportheader -exportheadervar -expect 28

.PHONY: unaryop
unaryop:
	-@$(RUNSPLINTR) unaryop.c

# 3 more detected with version 2.5 (change in -numliteral setting)

.PHONY: union
union:
	-@$(RUNSPLINTR) +memchecks union.c -expect 8

###
### Added 2001-12-30: fixed union initializer checking in response to
### bug report from Jim Zelenka.
###

.PHONY: unioninit
unioninit:
	-@$(RUNSPLINTR) unioninit.c -expect 2

.PHONY: unnamedsu
unnamedsu:
	-@$(RUNSPLINTR) unnamedsu.c -expect 0

.PHONY: unreachable
unreachable:
	-@$(RUNSPLINTR) unreachable.c -expect 5
	-@$(RUNSPLINTR) -unreachable unreachable.c -expect 2
	-@$(RUNSPLINTR) switch.c -expect 4

.PHONY: unsignedcompare
unsignedcompare:
	-@$(RUNSPLINTR) +posixlib unsignedcompare.c -expect 4


###
### 2001-06-08 evans: 2 new errors after fixing ansireserved name checks
###

.PHONY: unused
unused:
	-@$(RUNSPLINTRN) unused.c +checks -exportlocal -expect 5
	-@$(RUNSPLINTRN) unused.c +checks -exportlocal +topuse -expect 8

###
### 2001-06-10: Provided by Jim Zalenka
###

.PHONY: ullint
ullint:
	-@$(RUNSPLINTRN) ullint.c -expect 5
	-@$(RUNSPLINTRN) ullint.c +charint +charintliteral -expect 2

###
### 2001-12-30: Poor warnings reported by Peter Deutsch
###
### 2002-07-03: removed warnings for datatype/macro definitions
###

.PHONY: utypes
utypes:
	-@$(RUNSPLINTRN) utypes.c -expect 2

###

.PHONY: void
void:
	-@$(RUNSPLINTRN) void.c -expect 2

.PHONY: variadicmacro
variadicmacro:
	-@$(RUNSPLINTRN) variadicmacro.c
	-@$(RUNSPLINTRN) variadicmacro.c -gnu-extensions -expect 2

###
### 2001-12-30: Problems with wide character strings reported by Nelson Beebe
###

.PHONY: widestrings
widestrings:
	-@$(RUNSPLINTRN) widestrings.c -expect 2

###
### New since 2.5q:
###

.PHONY: linked
linked:
	-@$(RUNSPLINTR) linked.c -expect 4
	-@$(RUNSPLINTR) linked2.c -expect 3
	-@$(RUNSPLINTR) linked3.c -expect 5
	-@$(RUNSPLINTR) linked4.c -expect 6
	-@$(RUNSPLINTR) linked5.c -expect 4
	-@$(RUNSPLINTR) linked6.c -expect 4

.PHONY: freearray
freearray:
	-@$(RUNSPLINTR) freearray.c -expect 1

.PHONY: sizeof
sizeof:
	-@$(RUNSPLINTR) +bounds sizeof.c -expect 1


.PHONY: buffertest
buffertest:
	-@$(RUNSPLINTR) +bounds buffertest1.c -expect 5

## Integration Tests

## evans 2000-12-22
## db2: 2 errors are no longer reported, since eref is immutable.
## Need to clarify what it means for an object to be immutable;
## there should be 2 types with different storage requirements.

.PHONY: $(SUBDIRTESTS)
$(SUBDIRTESTS):
	$(MAKE) -C $@ SPLINT="$(RUNSPLINTRN)"

