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