diff options
author | Mats Wichmann <mats@linux.com> | 2020-06-18 00:49:48 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2020-06-19 18:45:48 (GMT) |
commit | fb051bdc215244d352c2067d93d30ea64200e71f (patch) | |
tree | bf329cb8d20466db9797b0e4b55a4348672e61df | |
parent | df1e47c805c0fd1c6d5e60ea00b465188db6163e (diff) | |
download | SCons-fb051bdc215244d352c2067d93d30ea64200e71f.zip SCons-fb051bdc215244d352c2067d93d30ea64200e71f.tar.gz SCons-fb051bdc215244d352c2067d93d30ea64200e71f.tar.bz2 |
Fix testing subdir usage
Various tests called subdir several times with the same directory,
which is pointless. In previous code, this emitted a message
though it did not fail. Stop doing that.
The dir_fixture() method did some convoluted things to make sure
the directories to write to exist, change this around to simplify.
The subdir() method already combines the testdir, so dir_fixture
doesn't need to. Also handle more cleanly the case of the target
directory being an absolute path, which seems to have been intended,
but would not work.
Also clean up file_fixture() along the same principles.
Change the subdir() method to not need to be given an ordered
list of directories; instead call os.makedirs on each so
intermediate steps are made automatically. Along the way,
the print about making a directory that already existed vanishes.
Tests which did os.path.join on directory pieces when calling
file_fixture no longer do so, since file_fixture (and dir_fixture)
do joining on an arg which is a list of paths like many other scons
functions.
The testing doc was updated to fix some wording and reflect
the above changes.
Signed-off-by: Mats Wichmann <mats@linux.com>
47 files changed, 246 insertions, 216 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index d2ecca6..83ebd93 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -185,6 +185,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER different doc format, should that choice be made); significant rewordings in manpage. Manpage Examples moved to an external repository / website (scons-cookbook.readthedocs.io). + - Clean up test harness and tests' use of subdir, file_fixture and + dir_fixture. RELEASE 3.1.2 - Mon, 17 Dec 2019 02:06:27 +0000 diff --git a/test/AS/AS.py b/test/AS/AS.py index 380afe3..56a1498 100644 --- a/test/AS/AS.py +++ b/test/AS/AS.py @@ -40,7 +40,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myas.py')) +test.file_fixture(['fixture', 'myas.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/AS/ASFLAGS.py b/test/AS/ASFLAGS.py index 79fde8c..52f44af 100644 --- a/test/AS/ASFLAGS.py +++ b/test/AS/ASFLAGS.py @@ -35,7 +35,7 @@ test = TestSCons.TestSCons() _exe = TestSCons._exe test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myas_args.py')) +test.file_fixture(['fixture', 'myas_args.py']) o = ' -x' o_c = ' -x -c' diff --git a/test/AS/ASPP.py b/test/AS/ASPP.py index 18c067f..64e1080 100644 --- a/test/AS/ASPP.py +++ b/test/AS/ASPP.py @@ -35,7 +35,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myas.py')) +test.file_fixture(['fixture', 'myas.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/AS/ASPPFLAGS.py b/test/AS/ASPPFLAGS.py index 254a458..5dd9a38 100644 --- a/test/AS/ASPPFLAGS.py +++ b/test/AS/ASPPFLAGS.py @@ -35,7 +35,7 @@ test = TestSCons.TestSCons() _exe = TestSCons._exe test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myas_args.py')) +test.file_fixture(['fixture', 'myas_args.py']) o = ' -x' o_c = ' -x -c' diff --git a/test/CC/CCVERSION.py b/test/CC/CCVERSION.py index 20d8616..7e829f0 100644 --- a/test/CC/CCVERSION.py +++ b/test/CC/CCVERSION.py @@ -37,7 +37,7 @@ if sys.platform == 'win32': test.skip_test('CCVERSION not set with MSVC, skipping test.') test.dir_fixture('CCVERSION-fixture') -test.file_fixture(os.path.join('CC-fixture', 'foo.c')) +test.file_fixture(['CC-fixture', 'foo.c']) test.write('SConstruct', """ cc = Environment().Dictionary('CC') diff --git a/test/Fortran/F03.py b/test/Fortran/F03.py index 61688c3..989d878 100644 --- a/test/Fortran/F03.py +++ b/test/Fortran/F03.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/Fortran/F03FILESUFFIXES.py b/test/Fortran/F03FILESUFFIXES.py index 9f1a031..5620a2d 100644 --- a/test/Fortran/F03FILESUFFIXES.py +++ b/test/Fortran/F03FILESUFFIXES.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) # Test default file suffix: .f90/.F90 for F90 test.write('SConstruct', """ diff --git a/test/Fortran/F03FILESUFFIXES2.py b/test/Fortran/F03FILESUFFIXES2.py index d84b089..6073aab 100644 --- a/test/Fortran/F03FILESUFFIXES2.py +++ b/test/Fortran/F03FILESUFFIXES2.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) # Test non-default file suffix: .f/.F for F03 test.write('SConstruct', """ diff --git a/test/Fortran/F03FLAGS.py b/test/Fortran/F03FLAGS.py index a031005..54b8083 100644 --- a/test/Fortran/F03FLAGS.py +++ b/test/Fortran/F03FLAGS.py @@ -33,7 +33,7 @@ test = TestSCons.TestSCons() _exe = TestSCons._exe test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran_flags.py')) +test.file_fixture(['fixture', 'myfortran_flags.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/Fortran/F08.py b/test/Fortran/F08.py index 3b08f6e..f60509c 100644 --- a/test/Fortran/F08.py +++ b/test/Fortran/F08.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/Fortran/F08FILESUFFIXES.py b/test/Fortran/F08FILESUFFIXES.py index 5b078b1..989d685 100644 --- a/test/Fortran/F08FILESUFFIXES.py +++ b/test/Fortran/F08FILESUFFIXES.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) # Test default file suffix: .f90/.F90 for F90 test.write('SConstruct', """ diff --git a/test/Fortran/F08FILESUFFIXES2.py b/test/Fortran/F08FILESUFFIXES2.py index 955d64a..0d99225 100644 --- a/test/Fortran/F08FILESUFFIXES2.py +++ b/test/Fortran/F08FILESUFFIXES2.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) # Test non-default file suffix: .f/.F for F08 test.write('SConstruct', """ diff --git a/test/Fortran/F08FLAGS.py b/test/Fortran/F08FLAGS.py index f91765b..015fb0b 100644 --- a/test/Fortran/F08FLAGS.py +++ b/test/Fortran/F08FLAGS.py @@ -33,7 +33,7 @@ test = TestSCons.TestSCons() _exe = TestSCons._exe test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran_flags.py')) +test.file_fixture(['fixture', 'myfortran_flags.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/Fortran/F77.py b/test/Fortran/F77.py index cea0485..ed5d33f 100644 --- a/test/Fortran/F77.py +++ b/test/Fortran/F77.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/Fortran/F77FILESUFFIXES.py b/test/Fortran/F77FILESUFFIXES.py index 26cf30c..c289e10 100644 --- a/test/Fortran/F77FILESUFFIXES.py +++ b/test/Fortran/F77FILESUFFIXES.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) # Test default file suffix: .f77/.F77 for F77 test.write('SConstruct', """ diff --git a/test/Fortran/F77FILESUFFIXES2.py b/test/Fortran/F77FILESUFFIXES2.py index 7a000fe..1f26012 100644 --- a/test/Fortran/F77FILESUFFIXES2.py +++ b/test/Fortran/F77FILESUFFIXES2.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) # Test non-default file suffix: .f/.F for F77 test.write('SConstruct', """ diff --git a/test/Fortran/F77FLAGS.py b/test/Fortran/F77FLAGS.py index d4e6e8a..caf291d 100644 --- a/test/Fortran/F77FLAGS.py +++ b/test/Fortran/F77FLAGS.py @@ -33,7 +33,7 @@ test = TestSCons.TestSCons() _exe = TestSCons._exe test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran_flags.py')) +test.file_fixture(['fixture', 'myfortran_flags.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/Fortran/F90.py b/test/Fortran/F90.py index 817a735..d76af07 100644 --- a/test/Fortran/F90.py +++ b/test/Fortran/F90.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/Fortran/F90FILESUFFIXES.py b/test/Fortran/F90FILESUFFIXES.py index a747570..d91c4c8 100644 --- a/test/Fortran/F90FILESUFFIXES.py +++ b/test/Fortran/F90FILESUFFIXES.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) # Test default file suffix: .f90/.F90 for F90 test.write('SConstruct', """ diff --git a/test/Fortran/F90FILESUFFIXES2.py b/test/Fortran/F90FILESUFFIXES2.py index 111c42b..3efc52c 100644 --- a/test/Fortran/F90FILESUFFIXES2.py +++ b/test/Fortran/F90FILESUFFIXES2.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) # Test non-default file suffix: .f/.F for F90 test.write('SConstruct', """ diff --git a/test/Fortran/F90FLAGS.py b/test/Fortran/F90FLAGS.py index 607ef60..f748e5d 100644 --- a/test/Fortran/F90FLAGS.py +++ b/test/Fortran/F90FLAGS.py @@ -34,7 +34,7 @@ test = TestSCons.TestSCons() _exe = TestSCons._exe test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran_flags.py')) +test.file_fixture(['fixture', 'myfortran_flags.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/Fortran/F95.py b/test/Fortran/F95.py index 07d1dc3..8e6d0b9 100644 --- a/test/Fortran/F95.py +++ b/test/Fortran/F95.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/Fortran/F95FILESUFFIXES.py b/test/Fortran/F95FILESUFFIXES.py index ac563cc..427c881 100644 --- a/test/Fortran/F95FILESUFFIXES.py +++ b/test/Fortran/F95FILESUFFIXES.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) # Test default file suffix: .f90/.F90 for F90 test.write('SConstruct', """ diff --git a/test/Fortran/F95FILESUFFIXES2.py b/test/Fortran/F95FILESUFFIXES2.py index c6691e8..a0ee1cf 100644 --- a/test/Fortran/F95FILESUFFIXES2.py +++ b/test/Fortran/F95FILESUFFIXES2.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) # Test non-default file suffix: .f/.F for F95 test.write('SConstruct', """ diff --git a/test/Fortran/F95FLAGS.py b/test/Fortran/F95FLAGS.py index dd542f1..203aee1 100644 --- a/test/Fortran/F95FLAGS.py +++ b/test/Fortran/F95FLAGS.py @@ -33,7 +33,7 @@ test = TestSCons.TestSCons() _exe = TestSCons._exe test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran_flags.py')) +test.file_fixture(['fixture', 'myfortran_flags.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/Fortran/FORTRAN.py b/test/Fortran/FORTRAN.py index 379dfe9..721d48f 100644 --- a/test/Fortran/FORTRAN.py +++ b/test/Fortran/FORTRAN.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/Fortran/FORTRANFILESUFFIXES.py b/test/Fortran/FORTRANFILESUFFIXES.py index 5294836..ec659a1 100644 --- a/test/Fortran/FORTRANFILESUFFIXES.py +++ b/test/Fortran/FORTRANFILESUFFIXES.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) # Test default file suffix: .f/.F for FORTRAN test.write('SConstruct', """ diff --git a/test/Fortran/FORTRANFILESUFFIXES2.py b/test/Fortran/FORTRANFILESUFFIXES2.py index 4c3f679..6dda07d 100644 --- a/test/Fortran/FORTRANFILESUFFIXES2.py +++ b/test/Fortran/FORTRANFILESUFFIXES2.py @@ -33,7 +33,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) # Test non default file suffix: .f, .f90 and .f95 for FORTRAN test.write('SConstruct', """ diff --git a/test/Fortran/FORTRANFLAGS.py b/test/Fortran/FORTRANFLAGS.py index 6ef2d72..316f67c 100644 --- a/test/Fortran/FORTRANFLAGS.py +++ b/test/Fortran/FORTRANFLAGS.py @@ -33,7 +33,7 @@ test = TestSCons.TestSCons() _exe = TestSCons._exe test.file_fixture('mylink.py') -test.file_fixture(os.path.join('fixture', 'myfortran_flags.py')) +test.file_fixture(['fixture', 'myfortran_flags.py']) test.write('SConstruct', """ env = Environment(LINK = r'%(_python_)s mylink.py', diff --git a/test/Fortran/SHF03.py b/test/Fortran/SHF03.py index 5327c4c..0ab2cc9 100644 --- a/test/Fortran/SHF03.py +++ b/test/Fortran/SHF03.py @@ -33,7 +33,7 @@ obj_ = TestSCons.shobj_ test = TestSCons.TestSCons() -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) test.write('SConstruct', """ env = Environment(SHF03 = r'%(_python_)s myfortran.py g03', diff --git a/test/Fortran/SHF08.py b/test/Fortran/SHF08.py index 10f9314..8147b79 100644 --- a/test/Fortran/SHF08.py +++ b/test/Fortran/SHF08.py @@ -33,7 +33,7 @@ obj_ = TestSCons.shobj_ test = TestSCons.TestSCons() -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) test.write('SConstruct', """ env = Environment(SHF08 = r'%(_python_)s myfortran.py g08', diff --git a/test/Fortran/SHF77.py b/test/Fortran/SHF77.py index ba3ac2e..1b0e180 100644 --- a/test/Fortran/SHF77.py +++ b/test/Fortran/SHF77.py @@ -33,7 +33,7 @@ obj_ = TestSCons.shobj_ test = TestSCons.TestSCons() -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) test.write('SConstruct', """ env = Environment(SHF77 = r'%(_python_)s myfortran.py g77', diff --git a/test/Fortran/SHF77FLAGS.py b/test/Fortran/SHF77FLAGS.py index e3f78a8..19d40b6 100644 --- a/test/Fortran/SHF77FLAGS.py +++ b/test/Fortran/SHF77FLAGS.py @@ -33,7 +33,7 @@ _obj = TestSCons._shobj obj_ = TestSCons.shobj_ test = TestSCons.TestSCons() -test.file_fixture(os.path.join('fixture', 'myfortran_flags.py')) +test.file_fixture(['fixture', 'myfortran_flags.py']) test.write('SConstruct', """ env = Environment(SHF77 = r'%(_python_)s myfortran_flags.py g77') diff --git a/test/Fortran/SHF90.py b/test/Fortran/SHF90.py index c56772e..1524bf3 100644 --- a/test/Fortran/SHF90.py +++ b/test/Fortran/SHF90.py @@ -33,7 +33,7 @@ obj_ = TestSCons.shobj_ test = TestSCons.TestSCons() -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) test.write('SConstruct', """ env = Environment(SHF90 = r'%(_python_)s myfortran.py g90', diff --git a/test/Fortran/SHF90FLAGS.py b/test/Fortran/SHF90FLAGS.py index 6f7ee00..947bf4b 100644 --- a/test/Fortran/SHF90FLAGS.py +++ b/test/Fortran/SHF90FLAGS.py @@ -33,7 +33,7 @@ _obj = TestSCons._shobj obj_ = TestSCons.shobj_ test = TestSCons.TestSCons() -test.file_fixture(os.path.join('fixture', 'myfortran_flags.py')) +test.file_fixture(['fixture', 'myfortran_flags.py']) test.write('SConstruct', """ env = Environment(SHF90 = r'%(_python_)s myfortran_flags.py g90', diff --git a/test/Fortran/SHF95.py b/test/Fortran/SHF95.py index ff0604b..27d9a76 100644 --- a/test/Fortran/SHF95.py +++ b/test/Fortran/SHF95.py @@ -33,7 +33,7 @@ obj_ = TestSCons.shobj_ test = TestSCons.TestSCons() -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) test.write('SConstruct', """ env = Environment(SHF95 = r'%(_python_)s myfortran.py g95', diff --git a/test/Fortran/SHF95FLAGS.py b/test/Fortran/SHF95FLAGS.py index 45c37bc..d1fbe3f 100644 --- a/test/Fortran/SHF95FLAGS.py +++ b/test/Fortran/SHF95FLAGS.py @@ -33,7 +33,7 @@ _obj = TestSCons._shobj obj_ = TestSCons.shobj_ test = TestSCons.TestSCons() -test.file_fixture(os.path.join('fixture', 'myfortran_flags.py')) +test.file_fixture(['fixture', 'myfortran_flags.py']) test.write('SConstruct', """ env = Environment(SHF95 = r'%(_python_)s myfortran_flags.py g95', diff --git a/test/Fortran/SHFORTRAN.py b/test/Fortran/SHFORTRAN.py index 2155736..f4850d7 100644 --- a/test/Fortran/SHFORTRAN.py +++ b/test/Fortran/SHFORTRAN.py @@ -33,7 +33,7 @@ obj_ = TestSCons.shobj_ test = TestSCons.TestSCons() -test.file_fixture(os.path.join('fixture', 'myfortran.py')) +test.file_fixture(['fixture', 'myfortran.py']) test.write('SConstruct', """ env = Environment(SHFORTRAN = r'%(_python_)s myfortran.py fortran') diff --git a/test/Fortran/SHFORTRANFLAGS.py b/test/Fortran/SHFORTRANFLAGS.py index 70c353b..ac2abd8 100644 --- a/test/Fortran/SHFORTRANFLAGS.py +++ b/test/Fortran/SHFORTRANFLAGS.py @@ -32,7 +32,7 @@ _obj = TestSCons._shobj obj_ = TestSCons.shobj_ test = TestSCons.TestSCons() -test.file_fixture(os.path.join('fixture', 'myfortran_flags.py')) +test.file_fixture(['fixture', 'myfortran_flags.py']) test.write('SConstruct', """ env = Environment(SHFORTRAN = r'%(_python_)s myfortran_flags.py fortran') diff --git a/test/QT/QTFLAGS.py b/test/QT/QTFLAGS.py index 61a1d87..aa142f5 100644 --- a/test/QT/QTFLAGS.py +++ b/test/QT/QTFLAGS.py @@ -35,28 +35,31 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() -test.subdir( 'qt', ['qt', 'bin'], ['qt', 'include'], ['qt', 'lib'], - 'work1', 'work2') - test.Qt_dummy_installation() +test.subdir('work1', 'work2') -test.run(chdir=test.workpath('qt','lib'), arguments = '.', - stderr=TestSCons.noisy_ar, - match=TestSCons.match_re_dotall) +test.run( + chdir=test.workpath('qt', 'lib'), + arguments='.', + stderr=TestSCons.noisy_ar, + match=TestSCons.match_re_dotall, +) QT = test.workpath('qt') QT_LIB = 'myqt' -QT_MOC = '%s %s' % (_python_, test.workpath('qt','bin','mymoc.py')) -QT_UIC = '%s %s' % (_python_, test.workpath('qt','bin','myuic.py')) - -def createSConstruct(test,place,overrides): - test.write(place, """ -env = Environment(QTDIR = r'%s', - QT_LIB = r'%s', - QT_MOC = r'%s', - QT_UIC = r'%s', - %s - tools=['default','qt']) +QT_MOC = '%s %s' % (_python_, test.workpath('qt', 'bin', 'mymoc.py')) +QT_UIC = '%s %s' % (_python_, test.workpath('qt', 'bin', 'myuic.py')) + +def createSConstruct(test, place, overrides): + test.write(place, """\ +env = Environment( + tools=['default','qt'], + QTDIR = r'%s', + QT_LIB = r'%s', + QT_MOC = r'%s', + QT_UIC = r'%s', + %s # last because 'overrides' may add comma +) if ARGUMENTS.get('variant_dir', 0): if ARGUMENTS.get('chdir', 0): SConscriptChdir(1) @@ -67,7 +70,7 @@ if ARGUMENTS.get('variant_dir', 0): else: sconscript = File('SConscript') Export("env") -SConscript( sconscript ) +SConscript(sconscript) """ % (QT, QT_LIB, QT_MOC, QT_UIC, overrides)) diff --git a/test/packaging/place-files-in-subdirectory.py b/test/packaging/place-files-in-subdirectory.py index 511f27a..838d6b8 100644 --- a/test/packaging/place-files-in-subdirectory.py +++ b/test/packaging/place-files-in-subdirectory.py @@ -29,6 +29,8 @@ Test the requirement to place files in a given subdirectory before archiving. """ import os +import subprocess + import TestSCons python = TestSCons.python @@ -44,68 +46,73 @@ if not tar: # TEST: subdir creation and file copying # test.subdir('src') - test.write('src/main.c', '') -test.write('SConstruct', """ +test.write('SConstruct', """\ env = Environment(tools=['packaging', 'filesystem', 'zip']) -env.Package( NAME = 'libfoo', - PACKAGEROOT = 'libfoo', - PACKAGETYPE = 'src_zip', - VERSION = '1.2.3', - source = [ 'src/main.c', 'SConstruct' ] ) +env.Package( + NAME='libfoo', + PACKAGEROOT='libfoo', + PACKAGETYPE='src_zip', + VERSION='1.2.3', + source=['src/main.c', 'SConstruct'], +) """) -test.run(arguments='libfoo-1.2.3.zip', stderr = None) +test.run(arguments='libfoo-1.2.3.zip', stderr=None) -test.must_exist( 'libfoo' ) -test.must_exist( 'libfoo/SConstruct' ) -test.must_exist( 'libfoo/src/main.c' ) +test.must_exist('libfoo') +test.must_exist('libfoo/SConstruct') +test.must_exist('libfoo/src/main.c') # # TEST: subdir guessing and file copying. # -test.subdir('src') - +#test.subdir('src') # already created above test.write('src/main.c', '') -test.write('SConstruct', """ +test.write('SConstruct', """\ env = Environment(tools=['packaging', 'filesystem', 'zip']) -env.Package( NAME = 'libfoo', - VERSION = '1.2.3', - PACKAGETYPE = 'src_zip', - TARGET = 'src.zip', - source = [ 'src/main.c', 'SConstruct' ] ) +env.Package( + NAME='libfoo', + VERSION='1.2.3', + PACKAGETYPE='src_zip', + TARGET='src.zip', + source=['src/main.c', 'SConstruct'], +) """) -test.run(stderr = None) +test.run(stderr=None) -test.must_exist( 'libfoo-1.2.3' ) -test.must_exist( 'libfoo-1.2.3/SConstruct' ) -test.must_exist( 'libfoo-1.2.3/src/main.c' ) +test.must_exist('libfoo-1.2.3') +test.must_exist('libfoo-1.2.3/SConstruct') +test.must_exist('libfoo-1.2.3/src/main.c') # # TEST: unpacking without the buildir. # -test.subdir('src') +#test.subdir('src') # already created above test.subdir('temp') - test.write('src/main.c', '') -test.write('SConstruct', """ +test.write('SConstruct', """\ env = Environment(tools=['packaging', 'filesystem', 'tar']) -env.Package( NAME = 'libfoo', - VERSION = '1.2.3', - PACKAGETYPE = 'src_targz', - source = [ 'src/main.c', 'SConstruct' ] ) +env.Package( + NAME='libfoo', + VERSION='1.2.3', + PACKAGETYPE='src_targz', + source=['src/main.c', 'SConstruct'], +) """) -test.run(stderr = None) - -with os.popen('%s -tzf %s'%(tar,test.workpath('libfoo-1.2.3.tar.gz'))) as p: - str = p.read() -test.fail_test(str != "libfoo-1.2.3/src/main.c\nlibfoo-1.2.3/SConstruct\n") +test.run(stderr=None) +cp = subprocess.run( + [tar, '-tzf', test.workpath('libfoo-1.2.3.tar.gz')], + stdout=subprocess.PIPE, + universal_newlines=True, +) +test.fail_test(cp.stdout != "libfoo-1.2.3/src/main.c\nlibfoo-1.2.3/SConstruct\n") test.pass_test() # Local Variables: diff --git a/test/packaging/sandbox-test/sandbox-test.py b/test/packaging/sandbox-test/sandbox-test.py index c6d2140..f43a80e 100644 --- a/test/packaging/sandbox-test/sandbox-test.py +++ b/test/packaging/sandbox-test/sandbox-test.py @@ -35,17 +35,16 @@ python = TestSCons.python test = TestSCons.TestSCons() tar = test.detect('TAR', 'tar') - if not tar: test.skip_test('tar not found, skipping test\n') -test.dir_fixture('src','src') +test.dir_fixture('src', dstdir='src') test.file_fixture('SConstruct') test.run(stderr=None) -test.must_exist( 'libfoobar-1.2.3.tar.gz' ) -test.must_exist( 'libfoobar-1.2.3.zip' ) +test.must_exist('libfoobar-1.2.3.tar.gz') +test.must_exist('libfoobar-1.2.3.zip') test.pass_test() diff --git a/test/packaging/use-builddir.py b/test/packaging/use-builddir.py index 86a8219..f6acb5f 100644 --- a/test/packaging/use-builddir.py +++ b/test/packaging/use-builddir.py @@ -51,15 +51,16 @@ test.write("src/main.c", "") test.write("SConstruct", """\ VariantDir('build', 'src') DefaultEnvironment(tools=[]) -env=Environment(tools=['packaging', 'filesystem', 'zip']) -env.Package( NAME = 'libfoo', - PACKAGEROOT = 'build/libfoo', - VERSION = '1.2.3', - PACKAGETYPE = 'src_zip', - target = 'build/libfoo-1.2.3.zip', - source = [ 'src/main.c', 'SConstruct' ] ) -""", +env = Environment(tools=['packaging', 'filesystem', 'zip']) +env.Package( + NAME='libfoo', + PACKAGEROOT='build/libfoo', + VERSION='1.2.3', + PACKAGETYPE='src_zip', + target='build/libfoo-1.2.3.zip', + source=['src/main.c', 'SConstruct'], ) +""") test.run(stderr=None) @@ -68,8 +69,8 @@ test.must_exist("build/libfoo-1.2.3.zip") # TEST: builddir not placed in archive # XXX: VariantDir should be stripped. # -test.subdir("src") -test.subdir("build") +#test.subdir("src") # already created above +#test.subdir("build") # already created above test.subdir("temp") test.write("src/main.c", "") @@ -77,13 +78,14 @@ test.write("src/main.c", "") test.write("SConstruct", """\ DefaultEnvironment(tools=[]) VariantDir('build', 'src') -env=Environment(tools=['packaging', 'filesystem', 'tar']) -env.Package( NAME = 'libfoo', - VERSION = '1.2.3', - PAKCAGETYPE = 'src_targz', - source = [ 'src/main.c', 'SConstruct' ] ) -""", +env = Environment(tools=['packaging', 'filesystem', 'tar']) +env.Package( + NAME='libfoo', + VERSION='1.2.3', + PAKCAGETYPE='src_targz', + source=['src/main.c', 'SConstruct'], ) +""") test.run(stderr=None) diff --git a/testing/framework/TestCmd.py b/testing/framework/TestCmd.py index 613f0e4..f0051ba 100644 --- a/testing/framework/TestCmd.py +++ b/testing/framework/TestCmd.py @@ -1326,23 +1326,23 @@ class TestCmd: return result def dir_fixture(self, srcdir, dstdir=None): - """ Copies the contents of the fixture dir to the test dir. + """ Copies the contents of the fixture directory to the test directory. If srcdir is an absolute path, it is tried directly, else - the fixture_dirs are prepended to it and tried in succession. - To tightly control the search order, the harness can be called - with FIXTURE_DIRS also including the test source directory - in the desired place, it will otherwise be tried last. + the fixture_dirs are searched in order to find the named fixture + directory. To tightly control the search order, the harness may + be called with FIXTURE_DIRS set including the test source directory + in the desired position, else it will be tried last. - srcdir may be a list, in which case the elements are first - joined into a pathname. + If dstdir not an absolute path, it is taken as a destination under + the working dir (if omitted of the default None indicates '.', + aka the test dir). dstdir is created automatically if needed. - If a dstdir is supplied, it is taken to be under the temporary - working dir. dstdir is created automatically if needed. + srcdir or dstdir may be a list, in which case the elements are first + joined into a pathname. """ if is_List(srcdir): srcdir = os.path.join(*srcdir) - spath = srcdir if srcdir and self.fixture_dirs and not os.path.isabs(srcdir): for dir in self.fixture_dirs: @@ -1352,20 +1352,18 @@ class TestCmd: else: spath = srcdir - if dstdir: - dstdir = self.canonicalize(dstdir) + if not dstdir or dstdir == '.': + dstdir = self.workdir else: - dstdir = '.' - - if dstdir != '.' and not os.path.exists(dstdir): - dstlist = self.parse_path(dstdir) - if len(dstlist) > 0 and dstlist[0] == ".": - dstlist = dstlist[1:] - for idx in range(len(dstlist)): - self.subdir(dstlist[:idx + 1]) - - if dstdir and self.workdir: - dstdir = os.path.join(self.workdir, dstdir) + if is_List(dstdir): + dstdir = os.path.join(*dstdir) + if os.path.isabs(dstdir): + os.makedirs(dstdir, exist_ok=True) + else: + dstlist = self.parse_path(dstdir) + if dstlist and dstlist[0] == ".": + dstdir = os.path.join(dstlist[1:]) + self.subdir(dstdir) for entry in os.listdir(spath): epath = os.path.join(spath, entry) @@ -1377,20 +1375,21 @@ class TestCmd: shutil.copy(epath, dpath) def file_fixture(self, srcfile, dstfile=None): - """ Copies a fixture file to the test dir, optionally renaming. + """ Copies a fixture file to the test directory, optionally renaming. If srcfile is an absolute path, it is tried directly, else - the fixture_dirs are prepended to it and tried in succession. - To tightly control the search order, the harness can be called - with FIXTURE_DIRS also including the test source directory + the fixture_dirs are searched in order to find the named fixture + file. To tightly control the search order, the harness may + be called with FIXTURE_DIRS also including the test source directory in the desired place, it will otherwise be tried last. - srcfile may be a list, in which case the elements are first - joined into a pathname. + dstfile is the name to give the copied file; if the argument + is omitted the basename of srcfile is used. If dstfile is not + an absolute path name. Any directory components of dstfile are + created automatically if needed. - dstfile is assumed to be under the temporary working directory - unless it is an absolute path name. Any directory components - of dstfile are created automatically if needed. + srcfile or dstfile may be a list, in which case the elements are first + joined into a pathname. """ if is_List(srcfile): srcfile = os.path.join(*srcfile) @@ -1411,15 +1410,21 @@ class TestCmd: else: return else: - dstpath, dsttail = os.path.split(dstfile) - if dstpath: - if not os.path.exists(os.path.join(self.workdir, dstpath)): - dstlist = self.parse_path(dstpath) - if len(dstlist) > 0 and dstlist[0] == ".": - dstlist = dstlist[1:] - for idx in range(len(dstlist)): - self.subdir(dstlist[:idx + 1]) - dpath = os.path.join(self.workdir, dstfile) + dstdir, dsttail = os.path.split(dstfile) + if dstdir: + # if dstfile has a dir part, and is not abspath, create + if os.path.isabs(dstdir): + os.makedirs(dstdir, exist_ok=True) + dpath = dstfile + else: + dstlist = self.parse_path(dstdir) + if dstlist and dstlist[0] == ".": + # strip leading ./ if present + dstdir = os.path.join(dstlist[1:]) + self.subdir(dstdir) + dpath = os.path.join(self.workdir, dstfile) + else: + dpath = os.path.join(self.workdir, dstfile) shutil.copy(spath, dpath) @@ -1653,13 +1658,11 @@ class TestCmd: """Creates new subdirectories under the temporary working directory. Creates a subdir for each argument. An argument may be a list, - in which case the list elements are concatenated using the - os.path.join() method. Subdirectories multiple levels deep - must be created using a separate argument for each level: + in which case the list elements are joined into a path. - test.subdir('sub', ['sub', 'dir'], ['sub', 'dir', 'ectory']) - - Returns the number of subdirectories actually created. + Returns the number of directories created, not including + intermediate directories, for historical reasons. A directory + which already existed is counted as "created". """ count = 0 for sub in subdirs: @@ -1669,14 +1672,15 @@ class TestCmd: sub = os.path.join(*sub) new = os.path.join(self.workdir, sub) try: - os.mkdir(new) + # okay to exist, we just do this for counting + os.makedirs(new, exist_ok=True) + count = count + 1 except OSError as e: - print("Got error creating dir: %s :%s" % (sub, e)) pass - else: - count = count + 1 + return count + def symlink(self, target, link): """Creates a symlink to the specified target. diff --git a/testing/framework/TestCmdTests.py b/testing/framework/TestCmdTests.py index 730f4a1..7017d2c 100644 --- a/testing/framework/TestCmdTests.py +++ b/testing/framework/TestCmdTests.py @@ -2725,33 +2725,46 @@ sys.stderr.write("run2 STDERR second line\\n") assert output == "run1 STDOUT ['foo', 'bar']\nrun1 STDOUT second line\n", output - class subdir_TestCase(TestCmdTestCase): def test_subdir(self): """Test subdir()""" - test = TestCmd.TestCmd(workdir = '', subdir = ['no', 'such', 'subdir']) - assert not os.path.exists(test.workpath('no')) + # intermediate directories are created + test = TestCmd.TestCmd(workdir='', subdir=['no', 'such', 'subdir']) + assert os.path.exists(test.workpath('no')) - test = TestCmd.TestCmd(workdir = '', subdir = 'foo') - assert test.subdir('bar') == 1 - assert test.subdir(['foo', 'succeed']) == 1 - if os.name != "nt": - os.chmod(test.workpath('foo'), 0o500) - assert test.subdir(['foo', 'fail']) == 0 - assert test.subdir(['sub', 'dir', 'ectory'], 'sub') == 1 - assert test.subdir('one', - UserList(['one', 'two']), - ['one', 'two', 'three']) == 3 + test = TestCmd.TestCmd(workdir='', subdir='foo') assert os.path.isdir(test.workpath('foo')) + + # single subdir + assert test.subdir('bar') assert os.path.isdir(test.workpath('bar')) + + # subdir "works" even if existing + assert test.subdir('bar') + + # single subdir as a list + assert test.subdir(['foo', 'succeed']) assert os.path.isdir(test.workpath('foo', 'succeed')) + if os.name != "nt": assert not os.path.exists(test.workpath('foo', 'fail')) + + # subdir creation without write permissions fails + if os.name != "nt": + os.chmod(test.workpath('foo'), 0o500) + assert not test.subdir(['foo', 'fail']) + + # create descended path + assert test.subdir(['sub', 'dir', 'ectory']) assert os.path.isdir(test.workpath('sub')) - assert not os.path.exists(test.workpath('sub', 'dir')) - assert not os.path.exists(test.workpath('sub', 'dir', 'ectory')) - assert os.path.isdir(test.workpath('one', 'two', 'three')) + assert os.path.exists(test.workpath('sub', 'dir')) + assert os.path.exists(test.workpath('sub', 'dir', 'ectory')) + # test multiple subdirs in one call, each should "succeed" + assert ( + test.subdir('one', UserList(['one', 'two']), ['one', 'two', 'three']) == 3 + ) + assert os.path.isdir(test.workpath('one', 'two', 'three')) class symlink_TestCase(TestCmdTestCase): diff --git a/testing/framework/test-framework.rst b/testing/framework/test-framework.rst index 8cac1fb..dca4684 100644 --- a/testing/framework/test-framework.rst +++ b/testing/framework/test-framework.rst @@ -335,9 +335,9 @@ The test harness method ``dir_fixture(srcdir, [dstdir])`` copies the contents of the specified directory ``srcdir`` from the directory of the called test script to the current temporary test directory. The ``srcdir`` name may be a list, in which case the elements -are concatenated into a path first. The ``dstdir`` -is assumed to be under the temporary working directory, it gets created -automatically, if it does not already exist. +are concatenated into a path first. The optional ``dstdir`` is +used as a destination path under the temporary working directory. +``distdir`` is created automatically, if it does not already exist. If ``srcdir`` represents an absolute path, it is used as-is. Otherwise, if the harness was invoked with the environment variable @@ -361,14 +361,15 @@ To see a real example for this in action, refer to the test named File fixtures ------------- -Similarly, the method ``file_fixture(srcfile, [dstfile])`` -copies the file ``srcfile`` from the directory of the called script, -to the temporary test directory. The ``srcfile`` name may be a list, -in which case the elements are concatenated into a path first. -The ``dstfile`` is assumed to be under the temporary working directory, -unless it is an absolute path name. -If ``dstfile`` is specified, its target directory gets created -automatically if it doesn't already exist. +The method ``file_fixture(srcfile, [dstfile])`` +copies the file ``srcfile`` from the directory of the called script +to the temporary test directory. +The optional ``dstfile`` is used as a destination file name +under the temporary working directory, unless it is an absolute path name. +If ``dstfile`` includes directory elements, they are +created automatically if they don't already exist. +The ``srcfile`` and ``dstfile`` parameters may each be a list, +which will be concatenated into a path. If ``srcfile`` represents an absolute path, it is used as-is. Otherwise, any passed in fixture directories are used as additional places to @@ -378,16 +379,16 @@ With the following code:: test = TestSCons.TestSCons() test.file_fixture('SConstruct') - test.file_fixture(['src','main.cpp'],['src','main.cpp']) + test.file_fixture(['src', 'main.cpp'], ['src', 'main.cpp']) test.run() The files ``SConstruct`` and ``src/main.cpp`` are copied to the -temporary test directory. Notice the second ``file_fixture`` line +temporary test directory. Notice the second ``file_fixture`` call preserves the path of the original, otherwise ``main.cpp`` would have been placed in the top level of the test directory. Again, a reference example can be found in the current revision -of SCons, it is ``test/packaging/sandbox-test/sandbox-test.py``. +of SCons, see ``test/packaging/sandbox-test/sandbox-test.py``. For even more examples you should check out one of the external Tools, e.g. the *Qt4* Tool at @@ -401,12 +402,11 @@ How to convert old tests to use fixures Tests using the inline ``TestSCons.write()`` method can fairly easily be converted to the fixture based approach. For this, we need to get at the files as they are written to each temporary test directory, -which we can do by taking advantage of a debugging aid: - -``runtest.py`` checks for the existence of an environment +which we can do by taking advantage of an existing debugging aid, +namely that ``runtest.py`` checks for the existence of an environment variable named ``PRESERVE``. If it is set to a non-zero value, the testing framework preserves the test directory instead of deleting it, and prints -its name to the screen. +a message about its name to the screen. So, you should be able to give the commands:: @@ -418,29 +418,27 @@ assuming Linux and a bash-like shell. For a Windows ``cmd`` shell, use The output will then look something like this:: - 1/1 (100.00%) /usr/bin/python -tt test/packaging/sandbox-test.py - pASSED + 1/1 (100.00%) /usr/bin/python test/packaging/sandbox-test.py + PASSED preserved directory /tmp/testcmd.4060.twlYNI You can now copy the files from that directory to your new *fixture* directory. Then, in the test script you simply remove all the -tedious ``TestSCons.write()`` statements and replace them by a single -``TestSCons.dir_fixture()``. - -Finally, don't forget to clean up and remove the temporary test -directory. ``;)`` +tedious ``TestSCons.write()`` statements and replace them with a single +``TestSCons.dir_fixture()`` call. For more complex testing scenarios you can use ``file_fixture`` with -the option to rename (that is, supplying a second argument, which is -the name to give the fixture file being copied). For example some test -files write multiple ``SConstruct`` files across the full run. -These files can be given different names - perhaps using a sufffix - -and then sucessively copied to the final name as needed:: +the optional second argument (or the keyword arg ``dstfile``) to assign +a name to the file being copied. For example, some tests need to +write multiple ``SConstruct`` files across the full run. +These files can be given different names in the source (perhaps using a +sufffix to distinguish them), and then be sucessively copied to the +final name as needed:: test.file_fixture('fixture/SConstruct.part1', 'SConstruct') # more setup, then run test test.file_fixture('fixture/SConstruct.part2', 'SConstruct') - # etc. + # run new test When not to use a fixture @@ -457,11 +455,13 @@ kind of usage that does not lend itself to a fixture:: test.write('SConstruct', """ cc = Environment().Dictionary('CC') - env = Environment(LINK=r'%(_python_)s mylink.py', - LINKFLAGS=[], - CC=r'%(_python_)s mycc.py', - CXX=cc, - CXXFLAGS=[]) + env = Environment( + LINK=r'%(_python_)s mylink.py', + LINKFLAGS=[], + CC=r'%(_python_)s mycc.py', + CXX=cc, + CXXFLAGS=[], + ) env.Program(target='test1', source='test1.c') """ % locals()) @@ -469,7 +469,7 @@ Here the value of ``_python_`` is picked out of the script's ``locals`` dictionary - which works because we've set it above - and interpolated using a mapping key into the string that will be written to ``SConstruct``. A fixture would be hard to use -here because we don't know the value of `_python_` until runtime. +here because we don't know the value of ``_python_`` until runtime. The other files created in this test may still be candidates for use as fixture files, however. |