Add a unit test for install_umask.

This test copies a src tree using umask of 002, then runs the build and
install under umask 027. It ensures that the default install_umask of
022 is still applied to all files and directories in the install tree.
pull/3225/head
Filipe Brandenburger 7 years ago
parent b0382733d8
commit 59b0fa9722
  1. 68
      run_unittests.py
  2. 1
      test cases/unit/24 install umask/datafile.cat
  3. 7
      test cases/unit/24 install umask/meson.build
  4. 17
      test cases/unit/24 install umask/myinstall.py
  5. 1
      test cases/unit/24 install umask/prog.1
  6. 3
      test cases/unit/24 install umask/prog.c
  7. 6
      test cases/unit/24 install umask/sample.h
  8. 1
      test cases/unit/24 install umask/subdir/datafile.dog
  9. 2
      test cases/unit/24 install umask/subdir/sayhello

@ -2669,6 +2669,74 @@ class LinuxlikeTests(BasePlatformTests):
# The chown failed nonfatally if we're not root
self.assertEqual(0, statf.st_uid)
def test_install_umask(self):
'''
Test that files are installed with correct permissions using default
install umask of 022, regardless of the umask at time the worktree
was checked out or the build was executed.
'''
# Copy source tree to a temporary directory and change permissions
# there to simulate a checkout with umask 002.
orig_testdir = os.path.join(self.unit_test_dir, '24 install umask')
# Create a new testdir under tmpdir.
tmpdir = os.path.realpath(tempfile.mkdtemp())
self.addCleanup(windows_proof_rmtree, tmpdir)
testdir = os.path.join(tmpdir, '24 install umask')
# Copy the tree using shutil.copyfile, which will use the current umask
# instead of preserving permissions of the old tree.
save_umask = os.umask(0o002)
self.addCleanup(os.umask, save_umask)
shutil.copytree(orig_testdir, testdir, copy_function=shutil.copyfile)
# Preserve the executable status of subdir/sayhello though.
os.chmod(os.path.join(testdir, 'subdir', 'sayhello'), 0o775)
self.init(testdir)
# Run the build under a 027 umask now.
os.umask(0o027)
self.build()
# And keep umask 027 for the install step too.
self.install()
for executable in [
'bin/prog',
'share/subdir/sayhello',
]:
f = os.path.join(self.installdir, 'usr', *executable.split('/'))
found_mode = stat.filemode(os.stat(f).st_mode)
want_mode = '-rwxr-xr-x'
self.assertEqual(want_mode, found_mode,
msg=('Expected file %s to have mode %s but found %s instead.' %
(executable, want_mode, found_mode)))
for directory in [
'usr',
'usr/bin',
'usr/include',
'usr/share',
'usr/share/man',
'usr/share/man/man1',
'usr/share/subdir',
]:
f = os.path.join(self.installdir, *directory.split('/'))
found_mode = stat.filemode(os.stat(f).st_mode)
want_mode = 'drwxr-xr-x'
self.assertEqual(want_mode, found_mode,
msg=('Expected directory %s to have mode %s but found %s instead.' %
(directory, want_mode, found_mode)))
for datafile in [
'include/sample.h',
'share/datafile.cat',
'share/file.dat',
'share/man/man1/prog.1.gz',
'share/subdir/datafile.dog',
]:
f = os.path.join(self.installdir, 'usr', *datafile.split('/'))
found_mode = stat.filemode(os.stat(f).st_mode)
want_mode = '-rw-r--r--'
self.assertEqual(want_mode, found_mode,
msg=('Expected file %s to have mode %s but found %s instead.' %
(datafile, want_mode, found_mode)))
def test_cpp_std_override(self):
testdir = os.path.join(self.unit_test_dir, '6 std override')
self.init(testdir)

@ -0,0 +1 @@
Installed cat is installed.

@ -0,0 +1,7 @@
project('install umask', 'c')
executable('prog', 'prog.c', install : true)
install_headers('sample.h')
install_man('prog.1')
install_data('datafile.cat', install_dir : get_option('prefix') + '/share')
install_subdir('subdir', install_dir : get_option('prefix') + '/share')
meson.add_install_script('myinstall.py', 'share', 'file.dat')

@ -0,0 +1,17 @@
#!/usr/bin/env python3
import os
import sys
prefix = os.environ['MESON_INSTALL_DESTDIR_PREFIX']
dirname = os.path.join(prefix, sys.argv[1])
try:
os.makedirs(dirname)
except FileExistsError:
if not os.path.isdir(dirname):
raise
with open(os.path.join(dirname, sys.argv[2]), 'w') as f:
f.write('')

@ -0,0 +1,3 @@
int main(int argc, char **arv) {
return 0;
}

@ -0,0 +1,6 @@
#ifndef SAMPLE_H
#define SAMPLE_H
int wackiness();
#endif

@ -0,0 +1,2 @@
#!/bin/sh
echo 'Hello, World!'
Loading…
Cancel
Save