-- -*- lua -*-
inactiveTbl = { Darwin = 1, }
_G._DEBUG   = false               -- Required by the new lua posix
local function isActive()
   local posix  = require("posix")
   local osName = posix.uname("%s")
   return (not inactiveTbl[osName])
end

testdescript = {
   owner   = "rtm",
   product = "modules",
   description = [[
	 Test initial module load
   ]],
   keywords = {"default","setdefault", "getdefault","setgetdefault","getsetdefault" },

   active = 1,
   testName = "saverestore",
   job_submit_method = "INTERACTIVE",

   runScript = [[

     . $(projectDir)/rt/common_funcs.sh

     unsetMT
     initStdEnvVars
     MODULEPATH=$(testDir)/TACC;        export MODULEPATH
     MODULEPATH_ROOT=$(testDir);        export MODULEPATH_ROOT
     LMOD_PACKAGE_PATH=$(testDir);      export LMOD_PACKAGE_PATH

     rm -fr _stderr.* _stdout.* err.* out.* .lmod.d Core

     LMOD_PACKAGE_PATH=$(testDir);      export LMOD_PACKAGE_PATH
     runLmod --version               # 1
     runLmod load TACC               # 2
     runLmod load pgi/7.2-5          # 3
     runLmod list                    # 4
     runLmod save default            # 5
     unset OMP_NUM_THREADS
     runLmod restore                 # 6
     runLmod list                    # 7
     runLmod use $(testDir)/TACC2    # 8
     runLmod load a                  # 9
     runLmod list                    #10
     runLmod save                    #11
     runLmod describe                #12

     runLmod purge                   #13
     unsetMT
     MODULEPATH=$(testDir)/TACC

     runLmod restore                 #14
     runLmod list                    #15
     runLmod spider                  #16

     runLmod purge                   #17
     unsetMT
     MODULEPATH=$(outputDir)/Core
     mkdir      $(outputDir)/Core
     (cd $(testDir)/Core; tar cf - . | (cd $(outputDir)/Core && tar xBf -))
     sed -e 's|@outputDir@|$(outputDir)|g'  < $(testDir)/.lmod.d/stdenv > $(outputDir)/.lmod.d/stdenv
     runLmod restore stdenv          #18
     sed -e 's/--#%#//g'  < $(outputDir)/Core/StdEnv.lua > $(outputDir)/Core/StdEnv.new
     mv $(outputDir)/Core/StdEnv.new $(outputDir)/Core/StdEnv.lua
     runLmod restore stdenv          #19

     runLmod purge                   #20
     runLmod use $(testDir)/PREREQ   #21
     runLmod load M T A              #22
     runLmod list                    #23
     runLmod save                    #24
     runLmod restore                 #25
     runLmod list                    #26
     runLmod purge                   #27
     runLmod load a b                #28
     runLmod save                    #29
     rm Core/a/default
     ln -s 3.0 Core/a/default
     runLmod restore                 #30
     runLmod list                    #31
     export LMOD_PIN_VERSIONS=yes
     runLmod purge                   #32
     runLmod restore                 #33
     runLmod list                    #34

     runLmod purge                   #35
     runLmod use $(testDir)/EB       #36
     runLmod load gcc/5.4            #37
     runLmod list                    #38
     runLmod save    foss            #39
     runLmod restore foss            #40
     runLmod list                    #41
     runLmod purge                   #42
     unsetMT

     MODULEPATH=$(testDir)/Core     
     export LMOD_CACHED_LOADS=yes
     mkdir -p $HOME/.lmod.d/.cache
     buildSpiderT $MODULEPATH > $HOME/.lmod.d/.cache/spiderT.lua

     runLmod load a                  #43
     runLmod save my_A               #44
     runLmod purge                   #45
     runLmod restore my_A            #46

     runLmod purge                   #47
     runLmod load icc ifort          #48
     runLmod save my_intel           #49
     runLmod purge                   #50
     runLmod restore my_intel        #51

     HOME=$ORIG_HOME
     export HOME
     cat _stdout.[0-9][0-9][0-9] > _stdout.orig
     joinBase64Results -bash _stdout.orig _stdout.new
     cleanUp _stdout.new out.txt

     cat _stderr.[0-9][0-9][0-9] > _stderr.orig
     cleanUp _stderr.orig err.txt

     rm -f results.csv

     wrapperDiff --csv results.csv $(testDir)/out.txt out.txt
     wrapperDiff --csv results.csv $(testDir)/err.txt err.txt
     testFinish -r $(resultFn) -t $(runtimeFn) results.csv
   ]],


   blessScript = [[
         # perform what is needed
   ]],

   tests = {
      { id='t1'},
   },

}
