-- -*- lua -*-

testdescript = {
   owner   = "rtm",
   product = "modules",
   description = [[
	 Test initial module load
   ]],
   keywords = {"load" },

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

   runScript = [[

     . $(projectDir)/rt/common_funcs.sh

     SED=sed
     osType=`uname -s`
     if [ ${osType:-} = "Darwin" ]; then
       SED=gsed
     fi

     unsetMT
     initStdEnvVars
     MODULEPATH_ROOT=$(testDir)/mf;  export MODULEPATH_ROOT

     rm -fr _stderr.* _stdout.* err.* out.* .lmod.d .lmodrc.lua mf
     cp $(projectDir)/init/lmodrc.lua .lmodrc.lua
     mkdir -p mf/bad_symlink
     ln -s 1.0.lua mf/bad_symlink/2.0.lua

     runLmod --version                                      #  1
     runLmod use -a $testDir/mf/Core $testDir/mf/Beta       #  2
     runLmod use $testDir/mf/notDir  $outputDir/mf          #  3
     runLmod load admin PrgEnv                              #  4
     runLmod load gotoblas/1.30-beta                        #  5
     runLmod rm   gotoblas/1.30-beta                        #  6
     runLmod try-add gotoblas123 intel                      #  7
     runLmod load gotoblas                                  #  8
     runLmod load multi                                     #  9
     runLmod unload multi                                   # 10
     runLmod load boost                                     # 11
     runLmod use -a $testDir/mf/Core2                       # 12
     runLmod load _a                                        # 13
     runLmod load __b                                       # 14
     runLmod avail                                          # 15
     runLmod -d avail                                       # 16
     runLmod unload boost                                   # 17
     runLmod load boost/1.33.0                              # 18
     runLmod load boost/1.57.0                              # 19
     runLmod load boost                                     # 20
     runLmod load alex                                      # 21
     runLmod load D                                         # 22
     runLmod --latest load rtm_intel                        # 23
     runLmod list                                           # 24
     runLmod use    $testDir/mf/Share                       # 25
     runLmod use -a $testDir/mf/Scratch                     # 26
     runLmod -r avail A B                                   # 27
     runLmod load  A B                                      # 28
     runLmod list                                           # 29
     runLmod load  DoesNotExist                             # 30
     runLmod list                                           # 31
     runLmod tablelist                                      # 32
     runLmod avail                                          # 33
     runLmod avail C                                        # 34
     runLmod load C                                         # 35
     runLmod list                                           # 36
     runLmod load rtm_intel                                 # 37
     runLmod load go                                        # 38
     runLmod load bad_symlink                               # 39
     runLmod load empty                                     # 40
     runLmod load version_only                              # 41
     runLmod load dflt                                      # 42
     runLmod list                                           # 43
     runLmod load noweb/2.10c.lua                           # 44
     runLmod load   Try/1.0                                 # 45
     runLmod load   Try/2.0                                 # 46
     runLmod unload B/2.3.4                                 # 47
     runLmod list                                           # 48


     export LMOD_DISABLE_SAME_NAME_AUTOSWAP=yes
     runLmod load moduleA/1.0                               # 49
     runLmod load moduleB/1.0                               # 50
     
     runLmod purge                                          # 51
     unsetMT
     export MODULEPATH=$(testDir)/mf2/Core 
     runLmod --show_hidden avail                            # 52
     runLmod load .eb_builder/default                       # 53
     runLmod load a/default                                 # 54
     runLmod load b/default                                 # 55
     runLmod list                                           # 56
                                                               
     runLmod purge                                          # 57
     unsetMT
     export MODULEPATH=$(testDir)/mf3
     runLmod load A                                         # 58
     runLmod load A/1.0                                     # 59
     runLmod load B                                         # 60
     runLmod load B/2.0                                     # 61
     runLmod load tex                                       # 62
     export LMOD_QUARANTINE_VARS=RTM_A:RTM_B:RTM_C             
     export RTM_A="I like this variable the way it is"
     export RTM_B="You can't change me"
     export RTM_B="You are not the boss of me"
     runLmod load rtmTest                                   # 63

     export PATH=$(testDir):$PATH
     runLmod load MakeSystemCall                            # 64
     runLmod list                                           # 65

     runLmod purge                                          # 66
     unsetMT
     export MODULEPATH=$(testDir)/mf4
     env | sort >  start.env.txt
     runLmod load   compiler/intel                          # 67
     runLmod unload compiler/intel                          # 68
     env | sort > end.env.txt
     diff start.env.txt end.env.txt | $SED \
          -e 's/^.*_ModuleTable.*//'       \
          -e 's/^[0-9]\+[ac][0-9]\+.*//'      \
          -e '/^ *$/d'                     \
          > diff.env.txt

     runBase cat diff.env.txt                               # 69



     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'},
   },

}
