Debian Codegraph @

doc/source/cookbook/test-modulefiles.rst

raw
1 .. _test-modulefiles:
2
3 Testing Modulefiles
4 ===================
5
6 The following is an example for a ``ModulesTest`` subroutine of a Modulefile and its output.
7 It checks whether the :file:`TESTDIR` is a directory, checks that it can enter it,
8 and whether a file :file:`TESTFILE` can successfully be created there.
9
10 This code gets executed when you use the :subcmd:`module test modulefile<test>` command.
11
12 Code
13 ----
14
15 .. literalinclude:: ../../example/test-modulefiles/modulefiles/test_dir_and_file
16 :language: tcl
17 :caption: test_dir_and_file
18
19
20 Usage example
21 -------------
22
23 Enable the modulepath where the example modulefiles are located::
24
25 $ module use example/test-modulefiles/modulefiles
26
27 Run the test both with the test directory not existing and existing::
28
29 $ module test test_dir_and_file
30 -------------------------------------------------------------------
31 Module Specific Test for .../modulefiles/test_dir_and_file:
32
33 Running ModulesTest for directory existence...
34 ERROR: Is not a directory: /tmp/testuser/testdir
35 Running ModulesTest for directory existence...done
36 Running ModulesTest for directory permissions...
37 ERROR: Was not able to enter directory /tmp/testuser/testdir: couldn't change working directory to "/tmp/testuser/testdir": no such file or directory
38 Running ModulesTest for directory permissions...done
39 Running ModulesTest for file creation...
40 ERROR: Was not able to create file /tmp/testuser/testdir/testfile: couldn't open "/tmp/testuser/testdir/testfile": no such file or directory
41 Running ModulesTest for file creation...done
42 Test result: FAIL
43 -------------------------------------------------------------------
44 $ mkdir /tmp/$USER/testdir
45 $ module test test_dir_and_file
46 -------------------------------------------------------------------
47 Module Specific Test for .../modulefiles/test_dir_and_file:
48
49 Running ModulesTest for directory existence...
50 Is a directory: /tmp/testuser/testdir
51 Running ModulesTest for directory existence...done
52 Running ModulesTest for directory permissions...
53 Was able to enter directory /tmp/testuser/testdir
54 Running ModulesTest for directory permissions...done
55 Running ModulesTest for file creation...
56 Was able to create file /tmp/testuser/testdir/testfile
57 Running ModulesTest for file creation...done
58 Test result: PASS
59 -------------------------------------------------------------------
60
61 .. vim:set tabstop=2 shiftwidth=2 expandtab autoindent: