-- -*- lua -*-
local testName = "cached_loads"

testdescript = {
   owner   = "rtm",
   product = "modules",
   description = [[
	 Test cached loads
   ]],
   keywords = {testName },

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

   runScript = [[

     . $(projectDir)/rt/common_funcs.sh

     unsetMT
     initStdEnvVars
     MODULEPATH_ROOT=$(outputDir)/mf;  export MODULEPATH_ROOT
     MODULEPATH=$MODULEPATH_ROOT/Core; export MODULEPATH

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


     
     runLmod --version              # 1

     cp -r $(testDir)/mf .
     export LMOD_CACHED_LOADS=1
     runLmod load  C openfoam       # 2
     unset LMOD_CACHED_LOADS
     runLmod purge                  # 3

     mkdir -p $HOME/.lmod.d/.cache
     buildSpiderT $MODULEPATH > $HOME/.lmod.d/.cache/spiderT.lua

     mkdir mf/Core/B
     cp    mf/Core/A/1.0.lua mf/Core/B

     runLmod load   A               # 4
     runLmod load   B               # 5
     runLmod list                   # 6
     runLmod unload B               # 7

     export LMOD_CACHED_LOADS=1
     runLmod load   B               # 8
     runLmod list                   # 9

     export LMOD_IGNORE_CACHE=1
     runLmod load   B               #10
     runLmod list                   #11
    


     HOME=$ORIG_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'},
   },

}
