tests: Run each file in a separate directory

Avoid cross-contamination between test files by creating a new
working directory for each file, and setting it as the current
directory before starting the tests in that file.

Rename the test output as tNNN.{base,log,diff,mk} where NNN is
a test number starting with 001 for the first test.  It is
slightly more annoying to find diff files since you can't use
autocomplete directly but it is simpler to match things.

Detect the source directory as the location of the test_driver.pl
script, so remove the separate -srcdir option.

* Makefile.am: Remove hacks to create symlinks when building
out-of-tree, and remove -srcdir option from run_make_tests.
* tests/test_driver.pl: Locate $srcpath based on __FILE__, then
compute $toppath as its parent.  Set $scriptpath under $srcpath
and $workpath under the current directory.  Toss $*_filename
and modify get_logfile() etc. to use the suffix directly.  Add
a chdir() around the invocation of the test.
* tests/run_make_tests.pl: Throw out the -srcdir option and use
$srcpath set in test_driver.pl.  The #WORK# helper is no longer
useful so remove it.  Set #PWD# to the current working dir. Always
search the local directory and $srcpath for config-flags.pm.
Use $srcpath for finding the thelp.pl script.
* tests/scripts/features/vpath: Don't put things in work/ as it
is no longer a subdirectory.
* tests/scripts/features/vpathgpath: Ditto.
* tests/scripts/features/vpathplus: Ditto.
* tests/scripts/misc/general1: Ditto.
* tests/scripts/misc/general2: Ditto.
* tests/scripts/options/dash-k: Ditto.
* tests/scripts/options/symlinks: Use $testpath as the working
directory.
* tests/scripts/variables/GNUMAKEFLAGS: Use the test helper to
display env var values (grepping for GNUMAKEFLAGS finds extra things
now that it is our current working directory).
This commit is contained in:
Paul Smith
2023-04-02 17:32:09 -04:00
parent fdd61fc068
commit 971b02d58e
11 changed files with 126 additions and 185 deletions

View File

@@ -4,18 +4,20 @@ $description = "Test vpath for particular classes of filenames.";
$details = "";
@files_to_touch = ("$workdir${pathsep}main.c","$workdir${pathsep}defs.h",
"$workdir${pathsep}kbd.c","$workdir${pathsep}command.h",
"$workdir${pathsep}commands.c","$workdir${pathsep}display.c",
"$workdir${pathsep}buffer.h","$workdir${pathsep}insert.c",
"$workdir${pathsep}command.c");
mkdir('work');
@files_to_touch = ("work${pathsep}main.c","work${pathsep}defs.h",
"work${pathsep}kbd.c","work${pathsep}command.h",
"work${pathsep}commands.c","work${pathsep}display.c",
"work${pathsep}buffer.h","work${pathsep}insert.c",
"work${pathsep}command.c");
&touch(@files_to_touch);
run_make_test(q!
vpath %.c foo
vpath %.c #WORK#
vpath %.h #WORK#
vpath %.c work
vpath %.h work
objects = main.o kbd.o commands.o display.o insert.o
edit: $(objects) ; @echo cc -o $@ $^
main.o : main.c defs.h ; @echo cc -c $(firstword $^)
@@ -24,7 +26,7 @@ commands.o : command.c defs.h command.h ; @echo cc -c commands.c
display.o : display.c defs.h buffer.h ; @echo cc -c display.c
insert.o : insert.c defs.h buffer.h ; @echo cc -c insert.c
!,
'', "cc -c $workdir${pathsep}main.c\ncc -c kbd.c\ncc -c commands.c\n"
'', "cc -c work${pathsep}main.c\ncc -c kbd.c\ncc -c commands.c\n"
."cc -c display.c\ncc -c insert.c\n"
."cc -o edit main.o kbd.o commands.o display.o insert.o\n");
@@ -50,11 +52,11 @@ rmdir('vpath-d');
# Test VPATH vs vpath
run_make_test(q!
VPATH = #WORK#:#PWD#
VPATH = work:#PWD#
vpath %.c foo
vpath %.c #WORK#
vpath %.c work
vpath %.c #PWD#
vpath %.h #WORK#
vpath %.h work
vpath %.c
vpath
all: ; @echo ALL IS WELL

View File

@@ -3,7 +3,9 @@ $description = "Tests VPATH+/GPATH functionality.";
$details = "";
$VP = "$workdir$pathsep";
mkdir('work');
$VP = "work$pathsep";
open(MAKEFILE,"> $makefile");

View File

@@ -3,7 +3,9 @@ $description = "Tests the new VPATH+ functionality added in 3.76.";
$details = "";
$VP = "$workdir$pathsep";
mkdir('work');
$VP = "work$pathsep";
@touchedfiles = ();

View File

@@ -8,7 +8,7 @@ It also tests the simple definition of VPATH.";
open(MAKEFILE,"> $makefile");
print MAKEFILE <<EOF;
VPATH = $workdir
VPATH = work
edit: main.o kbd.o commands.o display.o \\
insert.o
\t\@echo cc -o edit main.o kbd.o commands.o display.o \\
@@ -28,11 +28,12 @@ EOF
close(MAKEFILE);
@files_to_touch = ("$workdir${pathsep}main.c","$workdir${pathsep}defs.h",
"$workdir${pathsep}kbd.c","$workdir${pathsep}command.h",
"$workdir${pathsep}commands.c","$workdir${pathsep}display.c",
"$workdir${pathsep}buffer.h","$workdir${pathsep}insert.c",
"$workdir${pathsep}command.c");
mkdir('work');
@files_to_touch = ("work${pathsep}main.c","work${pathsep}defs.h",
"work${pathsep}kbd.c","work${pathsep}command.h",
"work${pathsep}commands.c","work${pathsep}display.c",
"work${pathsep}buffer.h","work${pathsep}insert.c",
"work${pathsep}command.c");
&touch(@files_to_touch);

View File

@@ -10,7 +10,7 @@ open(MAKEFILE,"> $makefile");
# The contents of the Makefile ...
print MAKEFILE <<EOF;
VPATH = $workdir
VPATH = work
objects = main.o kbd.o commands.o display.o insert.o
edit: \$(objects)
\t\@echo cc -o edit \$(objects)
@@ -29,11 +29,12 @@ EOF
close(MAKEFILE);
@files_to_touch = ("$workdir${pathsep}main.c","$workdir${pathsep}defs.h",
"$workdir${pathsep}kbd.c","$workdir${pathsep}command.h",
"$workdir${pathsep}commands.c","$workdir${pathsep}display.c",
"$workdir${pathsep}buffer.h","$workdir${pathsep}insert.c",
"$workdir${pathsep}command.c");
mkdir('work');
@files_to_touch = ("work${pathsep}main.c","work${pathsep}defs.h",
"work${pathsep}kbd.c","work${pathsep}command.h",
"work${pathsep}commands.c","work${pathsep}display.c",
"work${pathsep}buffer.h","work${pathsep}insert.c",
"work${pathsep}command.c");
&touch(@files_to_touch);

View File

@@ -16,7 +16,7 @@ open(MAKEFILE,"> $makefile");
# The Contents of the MAKEFILE ...
print MAKEFILE <<EOF;
VPATH = $workdir
VPATH = work
edit: main.o kbd.o commands.o display.o
\t\@echo cc -o edit main.o kbd.o commands.o display.o
@@ -38,11 +38,12 @@ EOF
close(MAKEFILE);
@files_to_touch = ("$workdir${pathsep}main.c","$workdir${pathsep}defs.h",
"$workdir${pathsep}command.h",
"$workdir${pathsep}commands.c","$workdir${pathsep}display.c",
"$workdir${pathsep}buffer.h",
"$workdir${pathsep}command.c");
mkdir('work');
@files_to_touch = ("work${pathsep}main.c","work${pathsep}defs.h",
"work${pathsep}command.h",
"work${pathsep}commands.c","work${pathsep}display.c",
"work${pathsep}buffer.h",
"work${pathsep}command.c");
&touch(@files_to_touch);

View File

@@ -15,8 +15,9 @@ use File::Spec;
&utouch(-10, 'dep');
&utouch(-5, 'targ');
$dirnm = (File::Spec->splitdir($cwddir))[-1];
symlink(File::Spec->catfile(File::Spec->updir(), $dirnm, 'dep'), 'sym');
my $dirnm = (File::Spec->splitdir($testpath))[-1];
my $dep = File::Spec->catfile(File::Spec->updir(), $dirnm, 'dep');
symlink($dep, 'sym') or die "Cannot create symlink sym -> $dep\n";
# Without -L, nothing should happen
# With -L, it should update targ

View File

@@ -41,13 +41,13 @@ unlink('x.mk');
# Ensure that we don't add GNUMAKEFLAGS to the environment if it's not there
run_make_test(q!
all: ; @env | grep GNUMAKEFLAGS; true
all: ; @#HELPER# env GNUMAKEFLAGS
!,
'', '');
'', 'GNUMAKEFLAGS=<unset>');
$ENV{GNUMAKEFLAGS} = '-Itst/bad';
run_make_test(q!
all: ; @env | grep GNUMAKEFLAGS; true
all: ; @#HELPER# env GNUMAKEFLAGS
!,
'', 'GNUMAKEFLAGS=');