From a7ea77d2a2fd2d2add507472eaabb0b6c30282ae Mon Sep 17 00:00:00 2001
From: Pere Mato <pere.mato@cern.ch>
Date: Sun, 15 Jun 2014 00:29:41 +0200
Subject: [PATCH] Added a test (CTest) for each tutorial (321 new tests). Made
 FITSIO and cernstaff.C tutorials independent of the current working
 directory.

---
 CMakeLists.txt                    |   1 +
 test/CMakeLists.txt               |   8 --
 tutorials/CMakeLists.txt          | 156 ++++++++++++++++++++++++++++++
 tutorials/fitsio/FITS_tutorial1.C |   5 +-
 tutorials/fitsio/FITS_tutorial2.C |   3 +-
 tutorials/fitsio/FITS_tutorial3.C |   5 +-
 tutorials/fitsio/FITS_tutorial4.C |   5 +-
 tutorials/fitsio/FITS_tutorial5.C |   6 +-
 tutorials/fitsio/FITS_tutorial6.C |   5 +-
 tutorials/tree/cernstaff.C        |   6 +-
 10 files changed, 179 insertions(+), 21 deletions(-)
 create mode 100644 tutorials/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 602d249870c..02535aed0b8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -76,6 +76,7 @@ if(roofit)
 endif()
 
 ROOT_ADD_TEST_SUBDIRECTORY(test)
+ROOT_ADD_TEST_SUBDIRECTORY(tutorials)
 
 #---Global PCH-----------------------------------------------------------------------------------
 get_property(__allTargets GLOBAL PROPERTY ROOT_DICTIONARY_TARGETS)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 9cc4e772da9..85a7e004f20 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -28,20 +28,12 @@ else()
   include_directories(${ROOT_INCLUDE_DIRS}/../tutorials)
 endif()
 
-macro(ROOT_ADD_MACRO macrofile)
-  get_filename_component(name ${macrofile} NAME_WE)
-  ROOT_ADD_TEST(macro-${name} COMMAND ${ROOT_root_CMD} -b -q ${macrofile} PASSRC 1 FAILREGEX Error)
-endmacro()
-
 #---environment-------------------------------------------------------------------------------
 ROOT_ADD_TEST(show-environment COMMAND ${CMAKE_COMMAND} -E environment)
 
 #---hworld------------------------------------------------------------------------------------
 ROOT_EXECUTABLE(hworld hworld.cxx LIBRARIES Gpad)
 
-#---Defines some of the tutorials as tests----------------------------------------------------
-ROOT_ADD_MACRO(${ROOT_SOURCE_DIR}/tutorials/hsimple.C)
-
 #---event-------------------------------------------------------------------------------------
 ROOT_GENERATE_DICTIONARY(EventDict ${CMAKE_CURRENT_SOURCE_DIR}/Event.h MODULE Event LINKDEF EventLinkDef.h)
 ROOT_LINKER_LIBRARY(Event Event.cxx EventDict.cxx LIBRARIES Hist MathCore)
diff --git a/tutorials/CMakeLists.txt b/tutorials/CMakeLists.txt
new file mode 100644
index 00000000000..9ae7f32704c
--- /dev/null
+++ b/tutorials/CMakeLists.txt
@@ -0,0 +1,156 @@
+# CMakeLists.txt for the ROOT tutorials programs.
+# Author: Pere Mato, 25/10/2010
+cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
+
+project(tutorials)
+find_package(ROOT REQUIRED)
+
+include(${ROOT_USE_FILE})
+
+#---Definition of the helper function--------------------------------
+function(ROOT_ADD_TUTORIAL macrofile rc)
+  string(REPLACE ".C" "" name ${macrofile})
+  string(REPLACE "/" "-" name ${name})
+  ROOT_ADD_TEST(tutorial-${name} COMMAND ${ROOT_root_CMD} -b -l -q ${CMAKE_CURRENT_SOURCE_DIR}/${macrofile} 
+                PASSRC ${rc} FAILREGEX "Error in" "error:" LABELS tutorial)
+endfunction()
+
+#---Tutorials disabled depending on the build components-------------
+if(NOT ROOT_minuit2_FOUND)
+  set(minuit2_veto fit/fit2dHist.C fit/fit2dHist.C
+                   fit/fitCircle.C fit/minuit2FitBench2D.C
+                   fit/minuit2FitBench2D.C fit/minuit2FitBench.C
+                   fit/minuit2FitBench.C fit/minuit2GausFit.C
+                   fit/minuit2GausFit.C fit/NumericalMinimization.C
+                   fit/combinedFit.C)
+endif()
+
+if(NOT ROOT_roofit_FOUND)
+  set(roofit_veto  fit/RoofitDemo.C 
+                   roofit/*.C roostats/*.C histfactory/*.C)
+endif()
+
+if(NOT ROOT_unuran_FOUND)
+  set(unuran_veto  math/testrandom.C unuran/unuranDemo.C unuran/unuranFoamTest.C)
+endif()
+
+if(NOT ROOT_xml_FOUND)
+  set(xml_veto  xml/*.C)
+endif()
+
+if(NOT ROOT_fitsio_FOUND)
+  set(fitsio_veto  fitsio/*.C)
+endif()
+
+if(NOT ROOT_mathmore_FOUND)
+  set(mathmore_veto math/quasirandom.C math/exampleMultiRoot.C)
+endif()
+
+if(NOT ROOT_fftw3_FOUND)
+  set(fftw3_veto roofit/rf208_convolution.C
+                 roofit/rf210_angularconv.C
+                 roofit/rf211_paramconv.C)
+endif()
+
+#---These ones requires a display to run-----------------------------
+set(gui_veto fit/fitpanel_playback.C
+             cocoa/*.C
+             geom/*.C
+             gl/*.C
+             gui/*.C
+             hist/exec1.C hist/exec2.C
+             image/*.C
+             graphics/psview.C graphics/gtime.C
+             graphics/graph_edit_playback.C
+             tree/tvdemo.C
+             eve/*.C)
+
+#---These ones are disabled !!! ------------------------------------
+set(extra_veto
+  htmlex.C
+  rootalias.C
+  rootlogon.C
+  rootlogoff.C
+  fft/FFT.C
+  fit/fit1_C.C  fit/TwoHistoFit2D.C fit/line3Dfit.C fit/MDF.C
+  foam/*.C
+  graphs/graphstruct.C
+  html/*.C
+  math/Bessel.C math/LegendreAssoc.C math/Legendre.C
+  math/mathmoreIntegration.C math/normalDist.C math/tStudent.C
+  math/testUnfold2.C math/pca.C
+  net/*.C
+  proof/*.C
+  pythia/*.C
+  sql/*.C
+  tree/hsimpleProxy.C tree/tree0.C tree/tree2a.C tree/tree4.C
+  roostats/rs401d_FeldmanCousins.C
+  roofit/rf104_classfactory.C
+  histfactory/ModifyInterpolation.C
+  tree/copytree2.C tree/copytree3.C tree/copytree.C
+  math/testUnfold4.C
+  fit/minuit2FitBench.C
+  fit/minuit2FitBench2D.C
+  roostats/*.C
+  http/*.C)
+  
+set(all_veto hsimple.C
+             ${extra_veto}
+             ${gui_veto}
+             ${minuit2_veto}
+             ${roofit_veto}
+             ${unuran_veto}
+             ${xml_veto}
+             ${fitsio_veto}
+             ${mathmore_veto}
+             ${fftw3_veto})
+             
+file(GLOB_RECURSE tutorials RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.C)
+file(GLOB tutorials_veto RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${all_veto})
+
+list(LENGTH tutorials total)
+list(LENGTH tutorials_veto veto)
+message(STATUS "${veto}/${total} tutorials have been vetoed for various reasons")
+
+list(REMOVE_ITEM tutorials ${tutorials_veto})
+
+set(returncode_1 fit/fit2a.C fit/graph2dfit.C fit/multidimfit.C
+                 graphics/archi.C graphics/arrow.C
+                 graphics/crown.C graphics/diamond.C
+                 graphics/earth.C graphics/ellipse.C
+                 graphics/event.C graphics/pavetext.C
+                 graphics/tmathtext.C graphics/tmathtext2.C
+                 graphs/exclusiongraph.C graphs/multigraph.C
+                 graphs/multipalette.C 
+                 hist/ContourList.C hist/hstack.C 
+                 hist/th2polyBoxes.C
+                 io/fildir.C 
+                 math/chi2test.C )
+
+#---Loop over all tutorials and define the corresponding test---------
+
+ROOT_ADD_TEST(tutorial-hsimple COMMAND ${ROOT_root_CMD} -b -l -q ${CMAKE_CURRENT_SOURCE_DIR}/hsimple.C
+                PASSRC 1 FAILREGEX "Error in" "error:" LABELS tutorial)
+foreach(t ${tutorials})
+  list(FIND returncode_1 ${t} index)
+  if(index EQUAL -1)
+    set(rc 0)
+  else()
+    set(rc 1)
+  endif()
+  string(REPLACE ".C" "" tname ${t})
+  string(REPLACE "/" "-" tname ${tname})
+  ROOT_ADD_TEST(tutorial-${tname} 
+                COMMAND ${ROOT_root_CMD} -b -l -q ${CMAKE_CURRENT_SOURCE_DIR}/${t}
+                PASSRC ${rc} FAILREGEX "Error in" "error:" 
+                LABELS tutorial
+                DEPENDS tutorial-hsimple )
+endforeach()
+
+
+                   
+
+
+
+
+
diff --git a/tutorials/fitsio/FITS_tutorial1.C b/tutorials/fitsio/FITS_tutorial1.C
index bea7521826d..a677b27a109 100644
--- a/tutorials/fitsio/FITS_tutorial1.C
+++ b/tutorials/fitsio/FITS_tutorial1.C
@@ -13,9 +13,10 @@ void FITS_tutorial1()
    if (!gROOT->IsBatch()) {
       //printf("Press ENTER to start..."); getchar();
    }
-   
+   TString dir = gSystem->DirName(gInterpreter->GetCurrentMacroName());
+  
    // Open primary HDU from file
-   TFITSHDU *hdu = new TFITSHDU("sample1.fits");
+   TFITSHDU *hdu = new TFITSHDU(dir+"/sample1.fits");
    if (hdu == 0) {
       printf("ERROR: could not access the HDU\n"); return;
    }
diff --git a/tutorials/fitsio/FITS_tutorial2.C b/tutorials/fitsio/FITS_tutorial2.C
index 1929b5f5320..c16f2ca83c6 100644
--- a/tutorials/fitsio/FITS_tutorial2.C
+++ b/tutorials/fitsio/FITS_tutorial2.C
@@ -15,9 +15,10 @@ void FITS_tutorial2()
    if (!gROOT->IsBatch()) {
       //printf("Press ENTER to start..."); getchar();
    }
+   TString dir = gSystem->DirName(gInterpreter->GetCurrentMacroName());
 
    // Open primary HDU from file
-   TFITSHDU *hdu = new TFITSHDU("sample2.fits");
+   TFITSHDU *hdu = new TFITSHDU(dir+"/sample2.fits");
    if (hdu == 0) {
       printf("ERROR: could not access the HDU\n"); return;
    }
diff --git a/tutorials/fitsio/FITS_tutorial3.C b/tutorials/fitsio/FITS_tutorial3.C
index 991d3e36cd1..34dab386d0a 100644
--- a/tutorials/fitsio/FITS_tutorial3.C
+++ b/tutorials/fitsio/FITS_tutorial3.C
@@ -15,11 +15,12 @@ void FITS_tutorial3()
    
    // Open extensions 1 to 5 from file
    //printf("Press ENTER to see a canvas with all images within the file:"); getchar();
-   
+   TString dir = gSystem->DirName(gInterpreter->GetCurrentMacroName());
+  
    TCanvas *c = new TCanvas("c1", "FITS tutorial #1", 800, 700);
    c->Divide(2,3);
    for (int i=1; i <= 5; i++) {
-      TFITSHDU *hdu = new TFITSHDU("sample3.fits", i);
+      TFITSHDU *hdu = new TFITSHDU(dir+"/sample3.fits", i);
       if (hdu == 0) {
          printf("ERROR: could not access the HDU\n"); return;
       }
diff --git a/tutorials/fitsio/FITS_tutorial4.C b/tutorials/fitsio/FITS_tutorial4.C
index 791072c906b..63fc0419725 100644
--- a/tutorials/fitsio/FITS_tutorial4.C
+++ b/tutorials/fitsio/FITS_tutorial4.C
@@ -16,9 +16,10 @@ void FITS_tutorial4()
    if (!gROOT->IsBatch()) {
       //printf("Press ENTER to start..."); getchar();
    }
-    
+   TString dir = gSystem->DirName(gInterpreter->GetCurrentMacroName());
+
    //Open the table extension number 1)
-   TFITSHDU *hdu = new TFITSHDU("sample2.fits[1][DATAMAX > 2e-15]");
+   TFITSHDU *hdu = new TFITSHDU(dir+"/sample2.fits[1][DATAMAX > 2e-15]");
    if (hdu == 0) {
       printf("ERROR: could not access the HDU\n"); return;
    }
diff --git a/tutorials/fitsio/FITS_tutorial5.C b/tutorials/fitsio/FITS_tutorial5.C
index cb600d5d065..0e484d22916 100755
--- a/tutorials/fitsio/FITS_tutorial5.C
+++ b/tutorials/fitsio/FITS_tutorial5.C
@@ -19,9 +19,11 @@ void FITS_tutorial5()
       //printf("Press ENTER to start..."); getchar();
       //printf("\n");
    }
-    
+  
+   TString dir = gSystem->DirName(gInterpreter->GetCurrentMacroName());
+
    //Open the table
-   TFITSHDU *hdu = new TFITSHDU("sample4.fits[1]");
+   TFITSHDU *hdu = new TFITSHDU(dir+"/sample4.fits[1]");
    if (hdu == 0) {
       printf("ERROR: could not access the HDU\n"); return;
    }
diff --git a/tutorials/fitsio/FITS_tutorial6.C b/tutorials/fitsio/FITS_tutorial6.C
index 458d680f440..ad0294b3e13 100644
--- a/tutorials/fitsio/FITS_tutorial6.C
+++ b/tutorials/fitsio/FITS_tutorial6.C
@@ -10,9 +10,10 @@ void FITS_tutorial6()
    printf("We are going to open a table from a FITS file\n");
    printf("and dump its columns.\n\n");
   
-       
+   TString dir = gSystem->DirName(gInterpreter->GetCurrentMacroName());
+
    //Open the table
-   TFITSHDU *hdu = new TFITSHDU("sample4.fits[1]");
+   TFITSHDU *hdu = new TFITSHDU(dir+"/sample4.fits[1]");
    if (hdu == 0) {
       printf("ERROR: could not access the HDU\n"); return;
    }
diff --git a/tutorials/tree/cernstaff.C b/tutorials/tree/cernstaff.C
index 85062739c99..480133df26e 100644
--- a/tutorials/tree/cernstaff.C
+++ b/tutorials/tree/cernstaff.C
@@ -1,10 +1,12 @@
 // Playing with a Tree containing variables of type character
 // Author: Rene Brun
 void cernstaff () {
-   if (gSystem->AccessPathName("cernstaff.root")) {
+   TString dir = gSystem->DirName(gInterpreter->GetCurrentMacroName());
+   if (gSystem->AccessPathName(dir+"/cernstaff.root")) {
+      gROOT->SetMacroPath(dir);
       gROOT->ProcessLine(".x cernbuild.C");
    }
-   TFile *f = new TFile("cernstaff.root");
+   TFile *f = new TFile(dir+"/cernstaff.root");
    TTree *T = (TTree*)f->Get("T");
    TCanvas *c1 = new TCanvas("c1","CERN staff",10,10,1000,750);
    c1->SetFillColor(17);
-- 
GitLab