#-*- Makefile -*-
#
# ${R_HOME}/tests/Makefile.common

## If you add test scripts here, review
## >>>> ../src/library/tools/R/testing.R -> testInstalledBasic() <<<<<<<<<<<<

test-src-gct = \
	eval-etc.R \
	simple-true.R \
	arith-true.R \
	arith.R \
	lm-tests.R \
	ok-errors.R \
	method-dispatch.R \
	any-all.R \
	structure.R
test-src-strict-1 = \
	$(test-src-gct) \
	d-p-q-r-tests.R
test-src-strict-auto =
test-src-sloppy-a = \
	complex.R \
	print-tests.R \
	lapack.R \
	datasets.R \
	datetime.R \
	iec60559.R
## set in Makefile.{in,win} as requires recommended packages
##test-src-sloppy-b = eval-etc-2.R
test-src-sloppy-1 = $(test-src-sloppy-a) $(test-src-sloppy-b)
test-src-sloppy-auto =

test-src-1 = $(test-src-strict-1) $(test-src-sloppy-1)
test-src-auto = $(test-src-strict-auto) $(test-src-sloppy-auto) \
  ${test-src-isas} ${test-src-segfault}
test-src-sloppy = $(test-src-sloppy-1) $(test-src-sloppy-auto)
test-src-strict = $(test-src-strict-1) $(test-src-strict-auto)

test-src-dt = datetime2.R datetime3.R datetime4.R datetime5.R
test-src-demo = demos.R demos2.R
test-src-internet = internet.R
test-src-internet2 = internet2.R libcurl.R
test-src-internet-dev = download.file.R sockets.R
test-src-CRANtools = CRANtools.R
test-src-large = reg-large.R
test-src-isas = isas-tests.R
test-src-primitive = primitives.R
test-src-random = p-r-random-tests.R
test-src-regexp = utf8-regex.R PCRE.R
test-src-segfault = no-segfault.R
test-src-tz = timezone.R
test-src-cond = conditions.R
test-src-misc-dev = misc-devel.R

test-src-reg-1 = array-subset.R \
  classes-methods.R \
  reg-tests-1a.R reg-tests-1b.R reg-tests-1c.R reg-tests-1d.R \
  reg-tests-1e.R reg-tests-2.R \
  reg-examples1.R reg-examples2.R reg-packages.R \
  p-qbeta-strict-tst.R d-p-q-r-tst-2.R \
  r-strict-tst.R \
  reg-IO.R reg-IO2.R reg-plot.R reg-S4.R reg-S4-examples.R reg-BLAS.R
## added to in Makefile.win
test-src-reg-1e =
test-src-reg = $(test-src-reg-1) $(test-src-reg-1e)
## to be run with $(R2), not forcing LC_ALL=C
test-src-reg-enc = reg-encodings.R
## overridden in Makefile if recommended packages are not installed.
## *-src-reg3 are sloppy (*.Rout may differ from *.Rout.save):
test-src-reg3 = reg-tests-3.R reg-examples3.R reg-plot-latin1.R

test-out-strict = $(test-src-strict:.R=.Rout)
test-out-sloppy = $(test-src-sloppy:.R=.Rout)

test-out-gct = $(test-src-gct:.R=.Rout-gct)
test-out-valgct = $(test-src-gct:.R=.Rout-valgct)

test-out-CRANtools = $(test-src-CRANtools:.R=.Rout)
test-out-dt = $(test-src-dt:.R=.Rout)
test-out-demo = $(test-src-demo:.R=.Rout)
test-out-internet = $(test-src-internet:.R=.Rout)
test-out-internet2 = $(test-src-internet2:.R=.Rout)
test-out-internet-dev = $(test-src-internet-dev:.R=.Rout)
test-out-isas = $(test-src-isas:.R=.Rout)
test-out-primitive = $(test-src-primitive:.R=.Rout)
test-out-large = $(test-src-large:.R=.Rout)
test-out-random = $(test-src-random:.R=.Rout)
test-out-reg = $(test-src-reg:.R=.Rout)
test-out-reg-enc = $(test-src-reg-enc:.R=.Rout)
test-out-regexp = $(test-src-regexp:.R=.Rout)
test-out-reg3 = $(test-src-reg3:.R=.Rout)
test-out-segfault = $(test-src-segfault:.R=.Rout)
test-out-tz = $(test-src-tz:.R=.Rout)
test-out-cond = $(test-src-cond:.R=.Rout)
test-out-misc-dev = $(test-src-misc-dev:.R=.Rout)

## This macro is used only for dependencies and for distclean
test-out = $(test-out-strict) $(test-out-sloppy) $(test-out-demo) $(test-out-gct) \
	$(test-out-internet) \
	$(test-out-random) $(test-out-reg) $(test-out-reg-enc) $(test-out-reg3) \
	$(test-out-segfault) $(test-out-isas) \
	$(test-out-internet2) $(test-out-internet-dev) \
	$(test-out-CRANtools) $(test-out-large) $(test-out-primitive) $(test-out-dt) \
	$(test-out-regexp) $(test-out-tz) $(test-out-cond) $(test-out-misc-dev) \
	utf8.Rout reg-translation.Rout iconv.Rout

.SUFFIXES:
.SUFFIXES: .R .Rin .Rout .Rout-gct .Rout-valgct .trin .tsin .log

.Rin.R:
	@$(ECHO) "creating '$@'"
	@$(R) < $< > /dev/null

.R.Rout:
	@rm -f $@ $@.fail $@.log
	@$(ECHO) $(ECHO_N) "running code in '$<' ...$(ECHO_C)" > $@.log
	@$(R) < $< > $@.fail 2>&1 || { \
	  $(ECHO) "$(ECHO_T) FAILED" >> $@.log; \
	  $(ECHO) "==> $@.fail <==" >> $@.log; \
	  tail $@.fail >>$@.log; \
	  cat $@.log && rm $@.log && exit 1; \
	}
	@$(ECHO) "$(ECHO_T) OK" >> $@.log
	@if test -f $(srcdir)/$@.save ; then \
	  $(ECHO) $(ECHO_N) \
	    "  comparing '$@' to '$(srcdir)/$@.save' ...$(ECHO_C)" >> $@.log; \
	  $(RDIFF) $@.fail $(srcdir)/$@.save $(RVAL_IF_DIFF) >> $@.log \
	    || (cat $@.log && rm $@.log && exit 1) || exit 1; \
	  mv $@.fail $@; \
	  $(ECHO) "$(ECHO_T) OK" >> $@.log; \
	else \
	  mv $@.fail $@; \
	fi
	@cat $@.log; rm $@.log

reg-plot.Rout: reg-plot.R
	@rm -f $@ $@.fail $@.log
	@$(ECHO) $(ECHO_N) "running code in '$<' ...$(ECHO_C)" > $@.log
	@$(R) < $< > $@ 2>&1 || (mv $@ $@.fail && cat $@.log && rm $@.log && exit 1)
	@$(ECHO) "$(ECHO_T) OK" >> $@.log
	@$(ECHO) $(ECHO_N) \
	  "  comparing 'reg-plot.pdf' to '$(srcdir)/reg-plot.pdf.save' ...$(ECHO_C)" >> $@.log
	@$(RDIFF) reg-plot.pdf $(srcdir)/reg-plot.pdf.save >> $@.log
	@$(ECHO) "$(ECHO_T) OK" >> $@.log
	@cat $@.log; rm $@.log

## Using $(R2) (whenever LC_ALL=C is not needed - so LANGUAGE can work)
reg-translation.Rout: reg-translation.R
	@rm -f $@ $@.fail $@.log
	@$(ECHO) $(ECHO_N) "running code in '$<' ...$(ECHO_C)" > $@.log
	@LANGUAGE=fr $(R2) < $< > $@ 2>&1 || (mv $@ $@.fail && cat $@.log && rm $@.log && exit 1)
	@$(ECHO) "$(ECHO_T) OK" >> $@.log
	@cat $@.log; rm $@.log

## allow this to fail, as it may if the locale does not support Latin-1 chars
reg-plot-latin1.Rout: reg-plot-latin1.R
	@rm -f $@ $@.fail
	@$(ECHO) "running tests of plotting Latin-1"
	@$(ECHO) "  expect failure or some differences if not in a Latin-1 or UTF-8 locale"
	@$(ECHO) $(ECHO_N) "running code in '$<' ...$(ECHO_C)"
	@$(R2) < $< > $@ 2>&1 || mv $@ $@.fail
	@if test -f $@.fail; then \
	  $(ECHO) "$(ECHO_T) FAILED"; \
	else \
	  $(ECHO) "$(ECHO_T) OK"; \
	  $(ECHO) $(ECHO_N) \
	  "  comparing 'reg-plot-latin1.pdf' to '$(srcdir)/reg-plot-latin1.pdf.save' ...$(ECHO_C)"; \
	  $(RDIFF) reg-plot-latin1.pdf $(srcdir)/reg-plot-latin1.pdf.save; \
	  $(ECHO) "$(ECHO_T) OK"; \
	fi

.R.Rout-gct:
	@$(ECHO) "running gctorture() + '$<'"
	@($(ECHO) '.ptime <- proc.time(); gctorture()' ; \
	  cat $< $(srcdir)/gct-foot.R) | $(R) > $@ 2>&1
	@mv $@ $@.fail; Ro=`basename $@ .Rout-gct`.Rout; \
	  if test ! -r $${Ro}; then $(MK) $${Ro}; fi; \
	  $(ECHO) $(ECHO_N) "  comparing '$@' to '$${Ro}' ...$(ECHO_C)"; \
	  grep -v 'gctorture()' $@.fail | $(RDIFF) - $${Ro} 1 || exit 1; \
	  mv $@.fail $@; \
	  $(ECHO) "$(ECHO_T) OK"

R-valgrind = $(R) --debugger="valgrind --tool=memcheck"

.R.Rout-valgct:
	@$(ECHO) "running gctorture() + valgrind + '$<'"
	@($(ECHO) '.ptime <- proc.time(); gctorture()' ; \
	  cat $< $(srcdir)/gct-foot.R) | $(R-valgrind) > $@ 2>&1
	grep "==[0-9]*==" $@

## The definitions for Internet are in Makefile.{in,win}.
## (That's historical: they are currently the same.)
all-basic-tests = Examples Specific Reg Internet
test-all-basics:
	@for name in $(all-basic-tests); do \
	  $(MK) test-$${name} || exit 1; \
	done

## if you change this, also edit *both* Makefile.install{,.win}
## The definitions for Standalone are in Makefile.{in,win}.
##  'Packages' slow ==> last
all-devel-tests = DateTime Docs IsAs Random Demo Primitive Regexp Translation \
    Internet2 CRANtools Segfault Standalone Conditions Misc-dev Packages
test-all-devel:
	@for name in $(all-devel-tests); do \
	  $(MK) test-$${name} || exit 1; \
	done

test-Examples:
	@(cd Examples && $(MK) $@)
test-Examples-Recommended:
	@(cd Examples && $(MK) $@)

test-Specific-strict: $(test-out-strict)
test-Specific-sloppy: $(test-out-sloppy)
test-Specific:
	@$(ECHO) "running strict specific tests"
	@$(MK) test-Specific-strict RVAL_IF_DIFF=1
	@$(ECHO) "running sloppy specific tests"
	@$(MK) test-Specific-sloppy RVAL_IF_DIFF=0
	@$(MK) test-TimeZone

test-Packages:
	@if test -n "${TEST_MC_CORES}"; then \
	  $(ECHO) "Using ${TEST_MC_CORES} cores to check packages"; \
	  $(MK) -j ${TEST_MC_CORES} test-Packages2; \
	else \
	  $(MK) test-Packages1; \
	fi

## R_PKGS_BASE is from ../share/make/vars.mk
test-Packages1:
	@fail=; for p in $(R_PKGS_BASE); do \
	  $(ECHO) "checking package '$${p}'"; \
	  _R_CHECK_FF_CALLS_=registration \
	  _R_CHECK_CODE_USAGE_WITH_ONLY_BASE_ATTACHED_=true \
	  $(RCHK) --install=skip --no-build-vignettes \
	    $(top_srcdir)/src/library/$${p} || fail="$${fail} $${p}"; \
	done; if test -n "$${fail}"; then $(ECHO) "FAILED:$${fail}"; exit 1; fi

PKG_OBJECTS = $(R_PKGS_BASE:=.log)

test-Packages2:
	@for p in $(R_PKGS_BASE); do \
	  touch $${p}.tsin; \
	done
	+@$(MK) stamp-Packages
	@rm -f *.tsin
stamp-Packages: $(PKG_OBJECTS)

.tsin.log:
	@$(ECHO) "begin checking package '`basename $@ .log`'"
	@rm -f $@
	@_R_CHECK_FF_CALLS_=registration \
	  _R_CHECK_CODE_USAGE_WITH_ONLY_BASE_ATTACHED_=true \
	  $(RCHK) --install=skip --no-build-vignettes \
	  $(top_srcdir)/src/library/`basename $@ .log` > $@ 2>&1 || (cat $@ && exit 1)
	@cat $@

test-Gct: $(test-out-gct)

test-Vgct: $(test-out-valgct)

test-DateTime:
	@$(ECHO) "running tests of date-time printing"
	@$(ECHO) "  expect platform-specific differences"
	@$(MK) $(test-out-dt) RVAL_IF_DIFF=0

## This should be allowed to fail, visibly.
test-TimeZone:
	@$(ECHO) "checking Sys.timezone ..."
	@$(MK) $(test-out-tz) || $(ECHO) "  Sys.timezone() appears unknown"

test-Docs:
	@$(ECHO) "running tests of documentation examples"
	@cp ${top_srcdir}/doc/manual/*.R .
	@$(MK) R-intro.Rout RVAL_IF_DIFF=0
	@cp ${top_srcdir}/doc/manual/R-exts.c .
	@$(top_builddir)/bin/R CMD SHLIB R-exts.c
	@$(MK) R-exts.Rout
	@rm R-exts.*

test-Demo:
	@$(ECHO) "running demos from base and stats"
	@$(MK) $(test-out-demo) RVAL_IF_DIFF=0

test-IsAs:
	@$(ECHO) "running tests of consistency of as/is.*"
	@$(MK) $(test-out-isas) RVAL_IF_DIFF=1

## As for test-Internet, allow to fail, possibly slowly
test-Internet2:
	@$(ECHO) "running more Internet tests"
	-@$(MK) $(test-out-internet2) RVAL_IF_DIFF=0

## This is intended to be run as a standalone target
test-Internet-dev:
	@$(ECHO) "running Internet tests for developers"
	-@$(MK) $(test-out-internet-dev) RVAL_IF_DIFF=0

test-CRANtools:
	@$(ECHO) "running tests of CRAN tools"
	@$(ECHO) "  (can be slow unless mirror is local)"
	@$(MK) $(test-out-CRANtools) RVAL_IF_DIFF=0

## Not part of any other target.
## On x86_64 Linux uses up to 220GB of VM and takes the best part of an hour.
## On Linux tests are skipped if there is no enough memory.
test-Large:
	@$(ECHO) "running tests needing large amounts of processor memory"
	@$(ECHO) "  (is slow, notably when memory is available)"
	@$(MK) $(test-out-large) RVAL_IF_DIFF=0

test-Primitive:
	@$(ECHO) "running tests of primitives"
	@$(MK) $(test-out-primitive) RVAL_IF_DIFF=0

test-Random:
	@$(ECHO) "running tests of random deviate generation"
	@$(MK) $(test-out-random) RVAL_IF_DIFF=1

test-Reg:
	@$(ECHO) "running regression tests ..."
	@if test -n "${TEST_MC_CORES}"; then \
	  $(MK) -j ${TEST_MC_CORES} $(test-out-reg) RVAL_IF_DIFF=1; \
	else \
	  $(MK) $(test-out-reg) RVAL_IF_DIFF=1; \
	fi
	@$(MK) $(test-out-reg-enc) R="$(R2)"
	@$(MK) $(test-out-reg3) RVAL_IF_DIFF=0

test-Regexp:
	@$(ECHO) "running regexp regression tests"
	@$(R2) < $(srcdir)/utf8-regex.R > utf8-regex.Rout 2>&1 || (mv utf8-regex.Rout utf8-regex.Rout.fail && exit 1)
	@$(R2) < $(srcdir)/PCRE.R > PCRE.Rout 2>&1 || (mv PCRE.Rout PCRE.Rout.fail && exit 1)

test-Segfault:
	@$(ECHO) "running tests to possibly trigger segfaults"
	@$(MK) $(test-out-segfault) RVAL_IF_DIFF=0
	-@rm -Rf data dumpdata.R ./-package.Rd ./-Ex.R .Rd l0.Rd m0.Rd df0.Rd Rprof.out Rplots* \
	    PACKAGES PACKAGES.gz [A-Za-z]*-package.Rd FALSE.* mirrors.html

test-Translation:
	@$(ECHO) "running tests of translation"
	@$(MK) reg-translation.Rout RVAL_IF_DIFF=0

test-Misc-dev:
	@$(ECHO) "running other miscellaneous devel tests"
	@$(MK) $(test-out-misc-dev) RVAL_IF_DIFF=1


## Not run by any other target
test-UTF-8:
	@$(ECHO) "running regression tests for UTF-8 <--> int conversion (slow)"
	@$(R2) < $(srcdir)/utf8.R > utf8.Rout 2>&1 || (mv utf8.Rout utf8.Rout.fail && exit 1)

## Not part of any other target
test-Iconv:
	@$(ECHO) "running regression tests for iconv()"
	@$(R2) < $(srcdir)/iconv.R > iconv.Rout 2>&1 || (mv iconv.Rout iconv.Rout.fail && exit 1)

test-Conditions:
	@$(ECHO) "running unit tests for the condition system"
	@$(MK) $(test-out-cond) RVAL_IF_DIFF=0

## Avoid site library, which could be very large
no-segfault.Rout: no-segfault.R
	@rm -f $@ $@.fail
	@$(ECHO) $(ECHO_N) "running code in '$<' ...$(ECHO_C)"
	@R_LIBS_SITE=no-such-dir $(R) < $< > $@ 2>&1 || (mv $@ $@.fail && exit 1)
	@$(ECHO) "$(ECHO_T) OK"

## Not run by any other target
test-Rd:
	@$(ECHO) "testing Rd conversion"
	@for name in testit ver20; do \
	  $(RDCONV) -t txt     -o $${name}.txt  $(srcdir)/$${name}.Rd || exit 1; \
	  $(RDCONV) -t html    -o $${name}.html $(srcdir)/$${name}.Rd || exit 1; \
	  $(RDCONV) -t latex   -o $${name}.tex  $(srcdir)/$${name}.Rd || exit 1; \
	  $(RDCONV) -t example -o $${name}-Ex.R $(srcdir)/$${name}.Rd || exit 1; \
	  diff -U 0 -b $(srcdir)/$${name}.txt.save  $${name}.txt  || $(ECHO); \
	  diff -U 0 -b $(srcdir)/$${name}.html.save $${name}.html || $(ECHO); \
	  diff -U 0 -b $(srcdir)/$${name}.tex.save  $${name}.tex  || $(ECHO); \
	  diff -U 0 -b $(srcdir)/$${name}-Ex.R.save $${name}-Ex.R || $(ECHO); \
	done
	@$(ECHO) "running Rd2pdf"
	@for name in testit ver20; do \
	  $(RD2PDF) -o $${name}.pdf $(srcdir)/$${name}.Rd || exit 1; \
	done
	@$(RD2PDF) --no-index --output=Rd2.pdf $(srcdir)/Pkgs/pkgC/man \
	  && rm -f Rd2.pdf || exit 1

## The following 6 tests are covered by test-Packages
test-DocFiles:
	@$(ECHO) "checking Rd usage sections"
	@for p in $(R_PKGS_BASE); do \
	  $(ECHO) $(ECHO_N) "package '$${p}' ...$(ECHO_C)"; \
	  out=`($(ECHO) "library(\"tools\")"; \
	         $(ECHO) "checkDocFiles(package = \"$${p}\")") | \
	       $(R) -q | sed '/^>/d'`; \
	  if test -n "$${out}"; then \
	    $(ECHO) "$(ECHO_T) WARNING"; \
	    $(ECHO); \
	    $(ECHO) "$${out}"; \
	    $(ECHO); \
	  else \
	    $(ECHO) "$(ECHO_T) OK"; \
	  fi; \
	done

test-DocStyle:
	@$(ECHO) "checking S3 method documentation style"
	@for p in $(R_PKGS_BASE); do \
	  $(ECHO) $(ECHO_N) "package '$${p}' ...$(ECHO_C)"; \
	  out=`($(ECHO) "library(\"tools\")"; \
	         $(ECHO) "checkDocStyle(package = \"$${p}\")") | \
	       $(R) -q | sed '/^>/d'`; \
	  if test -n "$${out}"; then \
	    $(ECHO) "$(ECHO_T) WARNING"; \
	    $(ECHO); \
	    $(ECHO) "$${out}"; \
	    $(ECHO); \
	  else \
	    $(ECHO) "$(ECHO_T) OK"; \
	  fi; \
	done

test-FF:
	@$(ECHO) "checking foreign function calls"
	@for p in $(R_PKGS_BASE); do \
	  $(ECHO) $(ECHO_N) "package '$${p}' ...$(ECHO_C)"; \
	  out=`($(ECHO) "library(\"tools\")"; \
	         $(ECHO) "checkFF(package = \"$${p}\")") | \
	       $(R) -q | sed '/^>/d'`; \
	  if test -n "$${out}"; then \
	    $(ECHO) "$(ECHO_T) WARNING"; \
	    $(ECHO) "$${out}"; \
	  else \
	    $(ECHO) "$(ECHO_T) OK"; \
	  fi; \
	done

test-S3methods:
	@$(ECHO) "checking for S3 generic/method consistency"
	@for p in $(R_PKGS_BASE); do \
	  $(ECHO) $(ECHO_N) "package '$${p}' ...$(ECHO_C)"; \
	  out=`($(ECHO) "library(\"tools\")"; \
	         $(ECHO) "checkS3methods(package = \"$${p}\")") | \
	       $(R) -q | sed '/^>/d'`; \
	  if test -n "$${out}"; then \
	    $(ECHO) "$(ECHO_T) WARNING"; \
	    $(ECHO); \
	    $(ECHO) "$${out}"; \
	    $(ECHO); \
	  else \
	    $(ECHO) "$(ECHO_T) OK"; \
	  fi; \
	done
test-codoc:
	@$(ECHO) "checking for code/documentation mismatches in functions"
	@for p in $(R_PKGS_BASE); do \
	  $(ECHO) $(ECHO_N) "package '$${p}' ...$(ECHO_C)"; \
	  out=`($(ECHO) "library(\"tools\")"; \
	         $(ECHO) "codoc(package = \"$${p}\")") | \
	       $(R) -q | sed '/^>/d'`; \
	  if test -n "$${out}"; then \
	    $(ECHO) "$(ECHO_T) WARNING"; \
	    $(ECHO); \
	    $(ECHO) "$${out}"; \
	    $(ECHO); \
	  else \
	    $(ECHO) "$(ECHO_T) OK"; \
	  fi; \
	done

test-undoc:
	@$(ECHO) "checking for missing documentation entries"
	@for p in $(R_PKGS_BASE); do \
	  $(ECHO) $(ECHO_N) "package '$${p}' ...$(ECHO_C)"; \
	  out=`($(ECHO) "library(\"tools\")"; \
	         $(ECHO) "undoc(package = \"$${p}\")") | \
	       $(R) -q | sed '/^>/d'`; \
	  if test -n "$${out}"; then \
	    $(ECHO) "$(ECHO_T) WARNING"; \
	    $(ECHO) "$${out}"; \
	  else \
	    $(ECHO) "$(ECHO_T) OK"; \
	  fi; \
	done

test-Packages-Recommended:
	@if test -n "${TEST_MC_CORES}"; then \
	  $(ECHO) "Using ${TEST_MC_CORES} cores to check packages"; \
	  $(MK) -j ${TEST_MC_CORES} test-Packages2-Recommended; \
	else \
	  $(MK) test-Packages1-Recommended; \
	fi

test-Packages1-Recommended:
	@test -d RecPackages || mkdir RecPackages
	@fail=; for p in $(R_PKGS_RECOMMENDED); do \
	  rm -Rf RecPackages/$${p}; \
	  gzip -dc "$(top_srcdir)/src/library/Recommended/$${p}.tgz" | \
	    (cd RecPackages && $(TAR) -x -f -) ; \
	  $(ECHO) "checking package '$${p}'"; \
	  R_LIBS="$(top_builddir)/library:$${R_LIBS}" \
	  _R_CHECK_FORCE_SUGGESTS_=FALSE \
	  $(RCHK) --install=skip --library="$(top_builddir)/library" \
	    RecPackages/$${p} || fail="$${fail} $${p}"; \
	done; if test -n "$${fail}"; then $(ECHO) "FAILED:$${fail}"; exit 1; fi

PKG_ROBJECTS = $(R_PKGS_RECOMMENDED:=.log)

test-Packages2-Recommended:
	@test -d RecPackages || mkdir RecPackages
	@for p in $(R_PKGS_RECOMMENDED); do \
	  touch $${p}.trin; \
	done
	+@$(MK) stamp-Packages2
	@rm -f *.trin
stamp-Packages2: $(PKG_ROBJECTS)

.trin.log:
	@p=`basename $@ .log`; \
	rm -Rf RecPackages/$${p}; \
	gzip -dc "$(top_srcdir)/src/library/Recommended/$${p}.tgz" | \
	    (cd RecPackages && $(TAR) -x -f -) ; \
	  $(ECHO) "begin checking package '$${p}'"; \
	  R_LIBS="$(top_builddir)/library:$${R_LIBS}" \
	 _R_CHECK_FORCE_SUGGESTS_=FALSE $(RCHK) --install=skip \
	    --library="$(top_builddir)/library" RecPackages/$${p}  > $@ 2>&1 || (cat $@ && exit 1)
	@cat $@

## This ensures that test scripts always re-run (at least in GNU make)
$(test-out): FORCE
FORCE:

INSTFILES = README \
	$(test-src-strict-1) $(test-src-strict-1:.R=.Rout.save) \
	$(test-src-sloppy-1) $(test-src-sloppy-1:.R=.Rout.save) \
	$(test-src-auto:.R=.Rin) isas-tests.Rout.save \
	$(test-src-dt) datetime2.Rout.save datetime4.Rout.save datetime5.Rout.save \
	$(test-src-demo) demos.Rout.save \
	$(test-src-internet) $(test-src-internet2) \
	$(test-src-internet-dev) internet.Rout.save \
	$(test-src-primitive) \
	$(test-src-random) p-r-random-tests.Rout.save \
	$(test-src-reg) $(test-src-reg-enc) $(test-src-reg3) \
	  reg-S4.Rout.save \
	  reg-IO.Rout.save reg-IO2.Rout.save \
	  reg-plot.pdf.save reg-tests-2.Rout.save reg-tests-3.Rout.save \
	  reg-examples3.Rout.save reg-plot-latin1.pdf.save \
	  $(test-src-regexp) $(test-src-CRANtools) \
	  $(test-src-tz) $(test-src-cond) reg-translation.R iconv.R \
	  $(test-src-misc-dev) \
	  nanbug.rda WinUnicode.dat arima.rda EmbeddedNuls.csv eval-fns.R
