diff options
author | Mats Wichmann <mats@linux.com> | 2024-10-06 17:34:37 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2024-10-19 14:25:14 (GMT) |
commit | 80ff4c7530e9b01afa896423fa025f15fe91cb4a (patch) | |
tree | 756fc950159ca568bf1691343e8dae4a2ebad0bd /test | |
parent | cc8ea0f91830a0a4d1ae5582343df58cc1bb126b (diff) | |
download | SCons-80ff4c7530e9b01afa896423fa025f15fe91cb4a.zip SCons-80ff4c7530e9b01afa896423fa025f15fe91cb4a.tar.gz SCons-80ff4c7530e9b01afa896423fa025f15fe91cb4a.tar.bz2 |
Adjust tests in case running as root
Although validation tests are not normally run as root, there may be
cicrumstances when it happens - one known case is when the test suite
is run as part of a particular Linux distros package construction.
It isn't too hard to avoid the few places where we counted on something
failing because of permissions, which don't if the user is root -
added a few skips.
Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/Install/Install.py | 21 | ||||
-rw-r--r-- | test/VariantDir/errors.py | 16 |
2 files changed, 24 insertions, 13 deletions
diff --git a/test/Install/Install.py b/test/Install/Install.py index 2857c72..65725ba 100644 --- a/test/Install/Install.py +++ b/test/Install/Install.py @@ -131,16 +131,21 @@ test.must_match(['work', 'f2.out'], "f2.in\n", mode='r') # if a target can not be unlinked before building it: test.write(['work', 'f1.in'], "f1.in again again\n") -os.chmod(test.workpath('work', 'export'), 0o555) -with open(f1_out, 'rb'): - expect = [ - "Permission denied", - "The process cannot access the file because it is being used by another process", - "Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird", - ] +# This test is not designed to work if running as root +try: + IS_ROOT = os.geteuid() == 0 +except AttributeError: + IS_ROOT = False +if not IS_ROOT: + os.chmod(test.workpath('work', 'export'), 0o555) + with open(f1_out, 'rb'): + expect = [ + "Permission denied", + "The process cannot access the file because it is being used by another process", + "Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird", + ] test.run(chdir='work', arguments=f1_out, stderr=None, status=2) - test.must_contain_any_line(test.stderr(), expect) test.pass_test() diff --git a/test/VariantDir/errors.py b/test/VariantDir/errors.py index 26ef4a2..531beea 100644 --- a/test/VariantDir/errors.py +++ b/test/VariantDir/errors.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Validate successful handling of errors when duplicating things in @@ -37,6 +36,13 @@ import TestSCons test = TestSCons.TestSCons() +try: + IS_ROOT = os.geteuid() == 0 +except AttributeError: + IS_ROOT = False +if IS_ROOT: + test.skip_test('SConscript permissions meaningless when running as root; skipping test.\n') + for dir in ['normal', 'ro-dir', 'ro-SConscript', 'ro-src']: test.subdir(dir, [dir, 'src']) @@ -44,7 +50,7 @@ for dir in ['normal', 'ro-dir', 'ro-SConscript', 'ro-src']: import os.path VariantDir('build', 'src') SConscript(os.path.join('build', 'SConscript')) -""") +""") test.write([dir, 'src', 'SConscript'], """\ def fake_scan(node, env, target): |