1*5ae59decSJulio Merino 2*5ae59decSJulio MerinoThis directory contains regression tests for make(1). 3*5ae59decSJulio Merino 4*5ae59decSJulio MerinoTo invoke the tests, please refer to tests(7). 5*5ae59decSJulio Merino 6*5ae59decSJulio Merino---------------------------------------------------------------------------- 7*5ae59decSJulio Merino 8*5ae59decSJulio MerinoThe rest of this file is intended for developers. 9*5ae59decSJulio Merino 10*5ae59decSJulio MerinoThe tests are invoked via the test.sh script or prove(1) from p5-Test-Harness. 11*5ae59decSJulio MerinoTests are normally executed in a special test directory that is built under 12*5ae59decSJulio Merino/tmp. The reason for this is, that make tests are generally influenced by 13*5ae59decSJulio Merinoall file in a directory, by files in one of make's obscure object directories 14*5ae59decSJulio Merinoas well as in other directories make happens to look into. Therefor the 15*5ae59decSJulio Merinotest scripts build a clean environment in the temp directory and the 16*5ae59decSJulio Merinotests are executed by cd-ing into that directory and invoking make. The 17*5ae59decSJulio Merinooutput of the make run (standard output, standard error and the exit status) 18*5ae59decSJulio Merinoare written into files that are created in another directory. So the layout 19*5ae59decSJulio Merinofor the shell/builtin test looks like: 20*5ae59decSJulio Merino 21*5ae59decSJulio Merino ./shell/builtin/ - directory with test stuff 22*5ae59decSJulio Merino /tmp/make.${USER}/shell/builtin - actual test directory 23*5ae59decSJulio Merino /tmp/make.${USER}/shell/builtin.OUTPUT - output files 24*5ae59decSJulio Merino 25*5ae59decSJulio MerinoSo a full test consists of the following steps: 26*5ae59decSJulio Merino 27*5ae59decSJulio Merino setup - Set up the test environment by creating the test directory 28*5ae59decSJulio Merino and populating it with the needed files. If the test 29*5ae59decSJulio Merino directory already exists an error is printed. 30*5ae59decSJulio Merino 31*5ae59decSJulio Merino run - Run the test and produce the output into the output 32*5ae59decSJulio Merino directory. 33*5ae59decSJulio Merino 34*5ae59decSJulio Merino show - Show the result files on the screen. 35*5ae59decSJulio Merino 36*5ae59decSJulio Merino compare - Compare the results in the output directory with those 37*5ae59decSJulio Merino in the test source directory. This just prints whether 38*5ae59decSJulio Merino the test was ok or not in the format used by prove(1). 39*5ae59decSJulio Merino 40*5ae59decSJulio Merino diff - Diff the output files and the expected output files. 41*5ae59decSJulio Merino 42*5ae59decSJulio Merino reset - Reset the test to its initial state. 43*5ae59decSJulio Merino 44*5ae59decSJulio Merino clean - Remove both the test directory and the output directory. 45*5ae59decSJulio Merino 46*5ae59decSJulio MerinoEach of these steps can independently be invoked with the test script 47*5ae59decSJulio Merinocontained in each directory. These test scripts are called test.t. 48*5ae59decSJulio MerinoAdditionally the scripts understand the following commands: 49*5ae59decSJulio Merino 50*5ae59decSJulio Merino test - Run setup, run and compare. 51*5ae59decSJulio Merino 52*5ae59decSJulio Merino prove - Run setup, run, compare and clean. This is identically 53*5ae59decSJulio Merino to invoking the script without an argument. 54*5ae59decSJulio Merino 55*5ae59decSJulio Merino desc - Print a short test description. 56*5ae59decSJulio Merino 57*5ae59decSJulio Merino update - Update the expected results from the actual results. 58*5ae59decSJulio Merino 59*5ae59decSJulio MerinoThe test script has the following syntax: 60*5ae59decSJulio Merino 61*5ae59decSJulio Merino % test.t [-v] [-m path_to_make_binary] command 62*5ae59decSJulio Merino 63*5ae59decSJulio MerinoTo invoke it via prove(1) use: 64*5ae59decSJulio Merino 65*5ae59decSJulio Merino % [MAKE_PROG=path_to_make_binary] prove [options] [files/directories] 66*5ae59decSJulio Merino 67*5ae59decSJulio MerinoExample: 68*5ae59decSJulio Merino % sh test.t -m `pwd`/../obj/make run 69*5ae59decSJulio Merino % MAKE_PROG=/usr/obj/usr/src/usr.bin/make/make prove -r 70*5ae59decSJulio Merino 71*5ae59decSJulio MerinoThe test scripts use the following environment variables that can be set 72*5ae59decSJulio Merinoby the user in the test script's environment: 73*5ae59decSJulio Merino 74*5ae59decSJulio Merino WORK_BASE 75*5ae59decSJulio Merino - Base directory for working files. If not set 76*5ae59decSJulio Merino /tmp/make.${USER} is used. 77*5ae59decSJulio Merino 78*5ae59decSJulio Merino MAKE_PROG 79*5ae59decSJulio Merino - Path to the make program to test. If not set 80*5ae59decSJulio Merino /usr/bin/make is used. 81*5ae59decSJulio Merino 82*5ae59decSJulio MerinoThe following variables are available to test scripts: 83*5ae59decSJulio Merino 84*5ae59decSJulio Merino SRC_BASE 85*5ae59decSJulio Merino - test source base directory. This is determined by 86*5ae59decSJulio Merino repeatedly doing cd .. and checking for common.sh. 87*5ae59decSJulio Merino Therefor this can fail if a test source directory is 88*5ae59decSJulio Merino actually a symbolic link and is physically not located 89*5ae59decSJulio Merino below the directory containing common.sh. 90*5ae59decSJulio Merino 91*5ae59decSJulio Merino SUBDIR 92*5ae59decSJulio Merino - subdirectory below WORK_BASE and SRC_BASE for current test 93*5ae59decSJulio Merino 94*5ae59decSJulio Merino WORK_DIR 95*5ae59decSJulio Merino - ${WORK_BASE}/${SUBDIR} 96*5ae59decSJulio Merino 97*5ae59decSJulio Merino SRC_DIR 98*5ae59decSJulio Merino - ${SRC_BASE}/${SUBDIR} 99*5ae59decSJulio Merino 100*5ae59decSJulio MerinoThe following variables and functions may be defined by the test script. 101*5ae59decSJulio MerinoThis also lists special filenames. 102*5ae59decSJulio Merino 103*5ae59decSJulio Merino DESC 104*5ae59decSJulio Merino A one-line description of the test. 105*5ae59decSJulio Merino 106*5ae59decSJulio Merino TEST_MAKE_DIRS 107*5ae59decSJulio Merino A list of pairs of directory names and modes. These 108*5ae59decSJulio Merino directories are created during setup and reset. When 109*5ae59decSJulio Merino the directory already exists (during reset) only the 110*5ae59decSJulio Merino mode change is applied. 111*5ae59decSJulio Merino 112*5ae59decSJulio Merino TEST_MAKE_DIRS="subdir 775 subdir/sub 555" 113*5ae59decSJulio Merino 114*5ae59decSJulio Merino TEST_COPY_FILES 115*5ae59decSJulio Merino A list of pairs of file names and modes. These files 116*5ae59decSJulio Merino are copied from the source to the working directory 117*5ae59decSJulio Merino during setup and reset. When the file already exists 118*5ae59decSJulio Merino (during reset) only the mode change is applied. Files 119*5ae59decSJulio Merino may be copied from/to sub-directories. The sub-directory 120*5ae59decSJulio Merino in the working directory must already exists (see 121*5ae59decSJulio Merino TEST_MAKE_DIRS). 122*5ae59decSJulio Merino 123*5ae59decSJulio Merino TEST_COPY_FILES="libtest.a 444 subdir/libfoo.a 444" 124*5ae59decSJulio Merino 125*5ae59decSJulio Merino TEST_TOUCH 126*5ae59decSJulio Merino List of pairs of file names and arguments to touch(1). 127*5ae59decSJulio Merino During setup and reset for each list element touch(1) 128*5ae59decSJulio Merino is executed. 129*5ae59decSJulio Merino 130*5ae59decSJulio Merino TEST_TOUCH="file1 '-t 200501011257'" 131*5ae59decSJulio Merino 132*5ae59decSJulio Merino TEST_LINK 133*5ae59decSJulio Merino List of pairs of filenames. Each pair is passed to ln(1). 134*5ae59decSJulio Merino All names are prefixed with the working directory. 135*5ae59decSJulio Merino 136*5ae59decSJulio Merino Makefile 137*5ae59decSJulio Merino If a file with this name exists in the source directory 138*5ae59decSJulio Merino it is automatically copied to the working directory. 139*5ae59decSJulio Merino 140*5ae59decSJulio Merino setup_test() 141*5ae59decSJulio Merino If this function exists it is executed at the end of the 142*5ae59decSJulio Merino setup. 143*5ae59decSJulio Merino 144*5ae59decSJulio Merino reset_test() 145*5ae59decSJulio Merino If this function exists it is executed at the end of the 146*5ae59decSJulio Merino reset. 147*5ae59decSJulio Merino 148*5ae59decSJulio Merino TEST_CLEAN_FILES 149*5ae59decSJulio Merino A list of file to be deleted when resetting. 150*5ae59decSJulio Merino 151*5ae59decSJulio Merino TEST_N 152*5ae59decSJulio Merino Number of tests in this script. If not set this is assumed 153*5ae59decSJulio Merino to be 1. 154*5ae59decSJulio Merino 155*5ae59decSJulio Merino TEST_<number> 156*5ae59decSJulio Merino Arguments to make for test number <number>. If not set 157*5ae59decSJulio Merino the default argument of test<number> is used. To run a test 158*5ae59decSJulio Merino without argument to make, set TEST_<number> to the empty string. 159*5ae59decSJulio Merino 160*5ae59decSJulio Merino TEST_<number>_SKIP 161*5ae59decSJulio Merino To skip a test (for whatever reason) this should be set 162*5ae59decSJulio Merino to a string explaining the reason for skipping the test. 163*5ae59decSJulio Merino 164*5ae59decSJulio Merino TEST_<number>_TODO 165*5ae59decSJulio Merino For a test that should fail this is a short string describing 166*5ae59decSJulio Merino what the problem in make(1) is that should be fixed. 167*5ae59decSJulio Merino 168*5ae59decSJulio Merino run_test() 169*5ae59decSJulio Merino Function to run a test. This function gets a single argument 170*5ae59decSJulio Merino which is the number of the test to executed. The default 171*5ae59decSJulio Merino function evaluates the variable TEST_<number> and calls 172*5ae59decSJulio Merino make with the arguments in this variable. 173*5ae59decSJulio Merino 174