summaryrefslogtreecommitdiff
path: root/config/tests
diff options
context:
space:
mode:
authorPale Moon <git-repo@palemoon.org>2016-09-01 13:39:08 +0200
committerPale Moon <git-repo@palemoon.org>2016-09-01 13:39:08 +0200
commit3d8ce1a11a7347cc94a937719c4bc8df46fb8d14 (patch)
tree8c26ca375a6312751c00a27e1653fb6f189f0463 /config/tests
parente449bdb1ec3a82f204bffdd9c3c54069d086eee3 (diff)
downloadpalemoon-gre-3d8ce1a11a7347cc94a937719c4bc8df46fb8d14.tar.gz
Base import of Tycho code (warning: huge commit)
Diffstat (limited to 'config/tests')
-rw-r--r--config/tests/makefiles/autodeps/Makefile.in8
-rw-r--r--config/tests/makefiles/autodeps/check_mkdir.tpy4
-rw-r--r--config/tests/makefiles/autodeps/testor.tmpl1
-rw-r--r--config/tests/src-simple/Makefile.in22
-rw-r--r--config/tests/src-simple/moz.build1
-rw-r--r--config/tests/unit-Expression.py82
-rw-r--r--config/tests/unit-JarMaker.py305
-rw-r--r--config/tests/unit-LineEndings.py46
-rw-r--r--config/tests/unit-Preprocessor.py577
-rw-r--r--config/tests/unit-buildlist.py84
-rw-r--r--config/tests/unit-expandlibs.py107
-rw-r--r--config/tests/unit-mozunit.py12
-rwxr-xr-xconfig/tests/unit-writemozinfo.py194
13 files changed, 83 insertions, 1360 deletions
diff --git a/config/tests/makefiles/autodeps/Makefile.in b/config/tests/makefiles/autodeps/Makefile.in
index f0c717274..ea21c5a8e 100644
--- a/config/tests/makefiles/autodeps/Makefile.in
+++ b/config/tests/makefiles/autodeps/Makefile.in
@@ -12,13 +12,6 @@ PYTEST = $(PYTHON) -E
# python -B not supported by older interpreters
export PYTHONDONTWRITEBYTECODE=1
-DEPTH = @DEPTH@
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk
autotgt_tests = .deps/autotargets.mk.ts
@@ -29,7 +22,6 @@ tgts =\
$(NULL)
export MAKE
-export .PYMAKE
##------------------_##
##---] TARGETS [---##
diff --git a/config/tests/makefiles/autodeps/check_mkdir.tpy b/config/tests/makefiles/autodeps/check_mkdir.tpy
index 2b3f0d751..ad633c781 100644
--- a/config/tests/makefiles/autodeps/check_mkdir.tpy
+++ b/config/tests/makefiles/autodeps/check_mkdir.tpy
@@ -98,8 +98,8 @@ def checkMkdir(work, debug=False):
logging.debug("Testing: checkMkdir")
- # On Windows + Pymake, don't convert paths to POSIX
- skipposix = sys.platform == "win32" and os.environ.get(".PYMAKE") == "1"
+ # On Windows, don't convert paths to POSIX
+ skipposix = sys.platform == "win32"
if skipposix:
path = os.path.abspath(__file__)
dirname_fun = os.path.dirname
diff --git a/config/tests/makefiles/autodeps/testor.tmpl b/config/tests/makefiles/autodeps/testor.tmpl
index d216e6e27..3134277e6 100644
--- a/config/tests/makefiles/autodeps/testor.tmpl
+++ b/config/tests/makefiles/autodeps/testor.tmpl
@@ -43,6 +43,7 @@ MKDIR ?= mkdir -p
TOUCH ?= touch
INCLUDED_CONFIG_MK = 1
+MOZILLA_DIR := $(topsrcdir)
include $(topsrcdir)/config/rules.mk
##-------------------##
diff --git a/config/tests/src-simple/Makefile.in b/config/tests/src-simple/Makefile.in
index 1d34012c9..aa5de0b0e 100644
--- a/config/tests/src-simple/Makefile.in
+++ b/config/tests/src-simple/Makefile.in
@@ -3,18 +3,14 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-DEPTH = @DEPTH@
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
LOCALE_SRCDIR = $(srcdir)/l10n
-include $(DEPTH)/config/autoconf.mk
+EXTERNALLY_MANAGED_MAKE_FILE := 1
+STANDALONE_MAKEFILE := 1
+JAR_MANIFEST := $(srcdir)/jar.mn
include $(topsrcdir)/config/config.mk
-STANDALONE_MAKEFILE := 1
-
XPI_NAME = test_jar_mn
DEFINES += \
@@ -27,18 +23,16 @@ REF_MANIFEST = $(if $(USE_EXTENSION_MANIFEST),chrome.manifest,test.manifest)
check-%::
if test -d $(FINAL_TARGET); then rm -rf $(FINAL_TARGET); fi;
$(MAKE) realchrome MOZ_CHROME_FILE_FORMAT=$*
- @echo "Comparing manifests..."
+ @echo 'Comparing manifests...'
@if ! sort $(MY_MANIFEST) | diff --text -U 0 $(srcdir)/../$(REF_MANIFEST).$* - ; then \
- echo "TEST-UNEXPECTED-FAIL | config/tests/$(REF_MANIFEST).$* | differing content in manifest!" ; \
+ echo 'TEST-UNEXPECTED-FAIL | config/tests/$(REF_MANIFEST).$* | differing content in manifest!' ; \
false; \
fi
- @if [ $* = "jar" ]; then \
+ @if [ $* = 'jar' ]; then \
$(UNZIP) -d $(FINAL_TARGET)/chrome/test $(FINAL_TARGET)/chrome/test.jar; \
fi
- @echo "Comparing packages..."
+ @echo 'Comparing packages...'
@if ! diff -ur $(srcdir)/../ref-simple $(FINAL_TARGET)/chrome/test ; then\
- echo "TEST-UNEXPECTED-FAIL | config/tests/ref-simple | different content in jar" ; \
+ echo 'TEST-UNEXPECTED-FAIL | config/tests/ref-simple | different content in jar' ; \
false; \
fi
-
-include $(topsrcdir)/config/rules.mk
diff --git a/config/tests/src-simple/moz.build b/config/tests/src-simple/moz.build
index 895d11993..c97072bba 100644
--- a/config/tests/src-simple/moz.build
+++ b/config/tests/src-simple/moz.build
@@ -4,3 +4,4 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+JAR_MANIFESTS += ['jar.mn'] \ No newline at end of file
diff --git a/config/tests/unit-Expression.py b/config/tests/unit-Expression.py
deleted file mode 100644
index d153211e9..000000000
--- a/config/tests/unit-Expression.py
+++ /dev/null
@@ -1,82 +0,0 @@
-import unittest
-
-import sys
-import os.path
-import mozunit
-
-from Expression import Expression, Context
-
-class TestContext(unittest.TestCase):
- """
- Unit tests for the Context class
- """
-
- def setUp(self):
- self.c = Context()
- self.c['FAIL'] = 'PASS'
-
- def test_string_literal(self):
- """test string literal, fall-through for undefined var in a Context"""
- self.assertEqual(self.c['PASS'], 'PASS')
-
- def test_variable(self):
- """test value for defined var in the Context class"""
- self.assertEqual(self.c['FAIL'], 'PASS')
-
- def test_in(self):
- """test 'var in context' to not fall for fallback"""
- self.assert_('FAIL' in self.c)
- self.assert_('PASS' not in self.c)
-
-class TestExpression(unittest.TestCase):
- """
- Unit tests for the Expression class
- evaluate() is called with a context {FAIL: 'PASS'}
- """
-
- def setUp(self):
- self.c = Context()
- self.c['FAIL'] = 'PASS'
-
- def test_string_literal(self):
- """Test for a string literal in an Expression"""
- self.assertEqual(Expression('PASS').evaluate(self.c), 'PASS')
-
- def test_variable(self):
- """Test for variable value in an Expression"""
- self.assertEqual(Expression('FAIL').evaluate(self.c), 'PASS')
-
- def test_not(self):
- """Test for the ! operator"""
- self.assert_(Expression('!0').evaluate(self.c))
- self.assert_(not Expression('!1').evaluate(self.c))
-
- def test_equals(self):
- """ Test for the == operator"""
- self.assert_(Expression('FAIL == PASS').evaluate(self.c))
-
- def test_notequals(self):
- """ Test for the != operator"""
- self.assert_(Expression('FAIL != 1').evaluate(self.c))
-
- def test_logical_and(self):
- """ Test for the && operator"""
- self.assertTrue(Expression('PASS == PASS && PASS != NOTPASS').evaluate(self.c))
-
- def test_logical_or(self):
- """ Test for the || operator"""
- self.assertTrue(Expression('PASS == NOTPASS || PASS != NOTPASS').evaluate(self.c))
-
- def test_logical_ops(self):
- """ Test for the && and || operators precedence"""
- # Would evaluate to false if precedence was wrong
- self.assertTrue(Expression('PASS == PASS || PASS != NOTPASS && PASS == NOTPASS').evaluate(self.c))
-
- def test_defined(self):
- """ Test for the defined() value"""
- self.assertTrue(Expression('defined(FAIL)').evaluate(self.c))
- self.assertTrue(Expression('!defined(PASS)').evaluate(self.c))
-
-
-if __name__ == '__main__':
- mozunit.main()
diff --git a/config/tests/unit-JarMaker.py b/config/tests/unit-JarMaker.py
deleted file mode 100644
index 51d97462b..000000000
--- a/config/tests/unit-JarMaker.py
+++ /dev/null
@@ -1,305 +0,0 @@
-from __future__ import print_function
-import unittest
-
-import os, sys, os.path, time, inspect
-from filecmp import dircmp
-from tempfile import mkdtemp
-from shutil import rmtree, copy2
-from StringIO import StringIO
-from zipfile import ZipFile
-import mozunit
-from JarMaker import JarMaker
-
-if sys.platform == "win32":
- import ctypes
- from ctypes import POINTER, WinError
- DWORD = ctypes.c_ulong
- LPDWORD = POINTER(DWORD)
- HANDLE = ctypes.c_void_p
- GENERIC_READ = 0x80000000
- FILE_SHARE_READ = 0x00000001
- OPEN_EXISTING = 3
- MAX_PATH = 260
-
- class FILETIME(ctypes.Structure):
- _fields_ = [("dwLowDateTime", DWORD),
- ("dwHighDateTime", DWORD)]
-
- class BY_HANDLE_FILE_INFORMATION(ctypes.Structure):
- _fields_ = [("dwFileAttributes", DWORD),
- ("ftCreationTime", FILETIME),
- ("ftLastAccessTime", FILETIME),
- ("ftLastWriteTime", FILETIME),
- ("dwVolumeSerialNumber", DWORD),
- ("nFileSizeHigh", DWORD),
- ("nFileSizeLow", DWORD),
- ("nNumberOfLinks", DWORD),
- ("nFileIndexHigh", DWORD),
- ("nFileIndexLow", DWORD)]
-
- # http://msdn.microsoft.com/en-us/library/aa363858
- CreateFile = ctypes.windll.kernel32.CreateFileA
- CreateFile.argtypes = [ctypes.c_char_p, DWORD, DWORD, ctypes.c_void_p,
- DWORD, DWORD, HANDLE]
- CreateFile.restype = HANDLE
-
- # http://msdn.microsoft.com/en-us/library/aa364952
- GetFileInformationByHandle = ctypes.windll.kernel32.GetFileInformationByHandle
- GetFileInformationByHandle.argtypes = [HANDLE, POINTER(BY_HANDLE_FILE_INFORMATION)]
- GetFileInformationByHandle.restype = ctypes.c_int
-
- # http://msdn.microsoft.com/en-us/library/aa364996
- GetVolumePathName = ctypes.windll.kernel32.GetVolumePathNameA
- GetVolumePathName.argtypes = [ctypes.c_char_p, ctypes.c_char_p, DWORD]
- GetVolumePathName.restype = ctypes.c_int
-
- # http://msdn.microsoft.com/en-us/library/aa364993
- GetVolumeInformation = ctypes.windll.kernel32.GetVolumeInformationA
- GetVolumeInformation.argtypes = [ctypes.c_char_p, ctypes.c_char_p, DWORD,
- LPDWORD, LPDWORD, LPDWORD, ctypes.c_char_p,
- DWORD]
- GetVolumeInformation.restype = ctypes.c_int
-
-def symlinks_supported(path):
- if sys.platform == "win32":
- # Add 1 for a trailing backslash if necessary, and 1 for the terminating
- # null character.
- volpath = ctypes.create_string_buffer(len(path) + 2)
- rv = GetVolumePathName(path, volpath, len(volpath))
- if rv == 0:
- raise WinError()
-
- fsname = ctypes.create_string_buffer(MAX_PATH + 1)
- rv = GetVolumeInformation(volpath, None, 0, None, None, None, fsname,
- len(fsname))
- if rv == 0:
- raise WinError()
-
- # Return true only if the fsname is NTFS
- return fsname.value == "NTFS"
- else:
- return True
-
-def _getfileinfo(path):
- """Return information for the given file. This only works on Windows."""
- fh = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, None, OPEN_EXISTING, 0, None)
- if fh is None:
- raise WinError()
- info = BY_HANDLE_FILE_INFORMATION()
- rv = GetFileInformationByHandle(fh, info)
- if rv == 0:
- raise WinError()
- return info
-
-def is_symlink_to(dest, src):
- if sys.platform == "win32":
- # Check if both are on the same volume and have the same file ID
- destinfo = _getfileinfo(dest)
- srcinfo = _getfileinfo(src)
- return (destinfo.dwVolumeSerialNumber == srcinfo.dwVolumeSerialNumber and
- destinfo.nFileIndexHigh == srcinfo.nFileIndexHigh and
- destinfo.nFileIndexLow == srcinfo.nFileIndexLow)
- else:
- # Read the link and check if it is correct
- if not os.path.islink(dest):
- return False
- target = os.path.abspath(os.readlink(dest))
- abssrc = os.path.abspath(src)
- return target == abssrc
-
-class _TreeDiff(dircmp):
- """Helper to report rich results on difference between two directories.
- """
- def _fillDiff(self, dc, rv, basepath="{0}"):
- rv['right_only'] += map(lambda l: basepath.format(l), dc.right_only)
- rv['left_only'] += map(lambda l: basepath.format(l), dc.left_only)
- rv['diff_files'] += map(lambda l: basepath.format(l), dc.diff_files)
- rv['funny'] += map(lambda l: basepath.format(l), dc.common_funny)
- rv['funny'] += map(lambda l: basepath.format(l), dc.funny_files)
- for subdir, _dc in dc.subdirs.iteritems():
- self._fillDiff(_dc, rv, basepath.format(subdir + "/{0}"))
- def allResults(self, left, right):
- rv = {'right_only':[], 'left_only':[],
- 'diff_files':[], 'funny': []}
- self._fillDiff(self, rv)
- chunks = []
- if rv['right_only']:
- chunks.append('{0} only in {1}'.format(', '.join(rv['right_only']),
- right))
- if rv['left_only']:
- chunks.append('{0} only in {1}'.format(', '.join(rv['left_only']),
- left))
- if rv['diff_files']:
- chunks.append('{0} differ'.format(', '.join(rv['diff_files'])))
- if rv['funny']:
- chunks.append("{0} don't compare".format(', '.join(rv['funny'])))
- return '; '.join(chunks)
-
-class TestJarMaker(unittest.TestCase):
- """
- Unit tests for JarMaker.py
- """
- debug = False # set to True to debug failing tests on disk
- def setUp(self):
- self.tmpdir = mkdtemp()
- self.srcdir = os.path.join(self.tmpdir, 'src')
- os.mkdir(self.srcdir)
- self.builddir = os.path.join(self.tmpdir, 'build')
- os.mkdir(self.builddir)
- self.refdir = os.path.join(self.tmpdir, 'ref')
- os.mkdir(self.refdir)
- self.stagedir = os.path.join(self.tmpdir, 'stage')
- os.mkdir(self.stagedir)
-
- def tearDown(self):
- if self.debug:
- print(self.tmpdir)
- elif sys.platform != "win32":
- # can't clean up on windows
- rmtree(self.tmpdir)
-
- def _jar_and_compare(self, infile, **kwargs):
- jm = JarMaker(outputFormat='jar')
- jardir = os.path.join(self.builddir, 'chrome')
- if 'topsourcedir' not in kwargs:
- kwargs['topsourcedir'] = self.srcdir
- for attr in ('topsourcedir', 'sourcedirs'):
- if attr in kwargs:
- setattr(jm, attr, kwargs[attr])
- jm.makeJar(infile, jardir)
- cwd = os.getcwd()
- os.chdir(self.builddir)
- try:
- # expand build to stage
- for path, dirs, files in os.walk('.'):
- stagedir = os.path.join(self.stagedir, path)
- if not os.path.isdir(stagedir):
- os.mkdir(stagedir)
- for file in files:
- if file.endswith('.jar'):
- # expand jar
- stagepath = os.path.join(stagedir, file)
- os.mkdir(stagepath)
- zf = ZipFile(os.path.join(path, file))
- # extractall is only in 2.6, do this manually :-(
- for entry_name in zf.namelist():
- segs = entry_name.split('/')
- fname = segs.pop()
- dname = os.path.join(stagepath, *segs)
- if not os.path.isdir(dname):
- os.makedirs(dname)
- if not fname:
- # directory, we're done
- continue
- _c = zf.read(entry_name)
- open(os.path.join(dname, fname), 'wb').write(_c)
- zf.close()
- else:
- copy2(os.path.join(path, file), stagedir)
- # compare both dirs
- os.chdir('..')
- td = _TreeDiff('ref', 'stage')
- return td.allResults('reference', 'build')
- finally:
- os.chdir(cwd)
-
- def _create_simple_setup(self):
- # create src content
- jarf = open(os.path.join(self.srcdir, 'jar.mn'), 'w')
- jarf.write('''test.jar:
- dir/foo (bar)
-''')
- jarf.close()
- open(os.path.join(self.srcdir,'bar'),'w').write('content\n')
- # create reference
- refpath = os.path.join(self.refdir, 'chrome', 'test.jar', 'dir')
- os.makedirs(refpath)
- open(os.path.join(refpath, 'foo'), 'w').write('content\n')
-
- def test_a_simple_jar(self):
- '''Test a simple jar.mn'''
- self._create_simple_setup()
- # call JarMaker
- rv = self._jar_and_compare(os.path.join(self.srcdir,'jar.mn'),
- sourcedirs = [self.srcdir])
- self.assertTrue(not rv, rv)
-
- def test_a_simple_symlink(self):
- '''Test a simple jar.mn with a symlink'''
- if not symlinks_supported(self.srcdir):
- return
-
- self._create_simple_setup()
- jm = JarMaker(outputFormat='symlink')
- jm.sourcedirs = [self.srcdir]
- jm.topsourcedir = self.srcdir
- jardir = os.path.join(self.builddir, 'chrome')
- jm.makeJar(os.path.join(self.srcdir,'jar.mn'), jardir)
- # All we do is check that srcdir/bar points to builddir/chrome/test/dir/foo
- srcbar = os.path.join(self.srcdir, 'bar')
- destfoo = os.path.join(self.builddir, 'chrome', 'test', 'dir', 'foo')
- self.assertTrue(is_symlink_to(destfoo, srcbar),
- "{0} is not a symlink to {1}".format(destfoo, srcbar))
-
-
-class Test_relativesrcdir(unittest.TestCase):
- def setUp(self):
- self.jm = JarMaker()
- self.jm.topsourcedir = '/TOPSOURCEDIR'
- self.jm.relativesrcdir = 'browser/locales'
- self.fake_empty_file = StringIO()
- self.fake_empty_file.name = 'fake_empty_file'
- def tearDown(self):
- del self.jm
- del self.fake_empty_file
- def test_en_US(self):
- jm = self.jm
- jm.makeJar(self.fake_empty_file, '/NO_OUTPUT_REQUIRED')
- self.assertEquals(jm.localedirs,
- [
- os.path.join(os.path.abspath('/TOPSOURCEDIR'),
- 'browser/locales', 'en-US')
- ])
- def test_l10n_no_merge(self):
- jm = self.jm
- jm.l10nbase = '/L10N_BASE'
- jm.makeJar(self.fake_empty_file, '/NO_OUTPUT_REQUIRED')
- self.assertEquals(jm.localedirs, [os.path.join('/L10N_BASE', 'browser')])
- def test_l10n_merge(self):
- jm = self.jm
- jm.l10nbase = '/L10N_BASE'
- jm.l10nmerge = '/L10N_MERGE'
- jm.makeJar(self.fake_empty_file, '/NO_OUTPUT_REQUIRED')
- self.assertEquals(jm.localedirs,
- [os.path.join('/L10N_MERGE', 'browser'),
- os.path.join('/L10N_BASE', 'browser'),
- os.path.join(os.path.abspath('/TOPSOURCEDIR'),
- 'browser/locales', 'en-US')
- ])
- def test_override(self):
- jm = self.jm
- jm.outputFormat = 'flat' # doesn't touch chrome dir without files
- jarcontents = StringIO('''en-US.jar:
-relativesrcdir dom/locales:
-''')
- jarcontents.name = 'override.mn'
- jm.makeJar(jarcontents, '/NO_OUTPUT_REQUIRED')
- self.assertEquals(jm.localedirs,
- [
- os.path.join(os.path.abspath('/TOPSOURCEDIR'),
- 'dom/locales', 'en-US')
- ])
- def test_override_l10n(self):
- jm = self.jm
- jm.l10nbase = '/L10N_BASE'
- jm.outputFormat = 'flat' # doesn't touch chrome dir without files
- jarcontents = StringIO('''en-US.jar:
-relativesrcdir dom/locales:
-''')
- jarcontents.name = 'override.mn'
- jm.makeJar(jarcontents, '/NO_OUTPUT_REQUIRED')
- self.assertEquals(jm.localedirs, [os.path.join('/L10N_BASE', 'dom')])
-
-
-if __name__ == '__main__':
- mozunit.main()
diff --git a/config/tests/unit-LineEndings.py b/config/tests/unit-LineEndings.py
deleted file mode 100644
index 56914aae9..000000000
--- a/config/tests/unit-LineEndings.py
+++ /dev/null
@@ -1,46 +0,0 @@
-import unittest
-
-from StringIO import StringIO
-import os
-import sys
-import os.path
-import mozunit
-
-from Preprocessor import Preprocessor
-
-class TestLineEndings(unittest.TestCase):
- """
- Unit tests for the Context class
- """
-
- def setUp(self):
- self.pp = Preprocessor()
- self.pp.out = StringIO()
- self.tempnam = os.tempnam('.')
-
- def tearDown(self):
- os.remove(self.tempnam)
-
- def createFile(self, lineendings):
- f = open(self.tempnam, 'wb')
- for line, ending in zip(['a', '#literal b', 'c'], lineendings):
- f.write(line+ending)
- f.close()
-
- def testMac(self):
- self.createFile(['\x0D']*3)
- self.pp.do_include(self.tempnam)
- self.assertEquals(self.pp.out.getvalue(), 'a\nb\nc\n')
-
- def testUnix(self):
- self.createFile(['\x0A']*3)
- self.pp.do_include(self.tempnam)
- self.assertEquals(self.pp.out.getvalue(), 'a\nb\nc\n')
-
- def testWindows(self):
- self.createFile(['\x0D\x0A']*3)
- self.pp.do_include(self.tempnam)
- self.assertEquals(self.pp.out.getvalue(), 'a\nb\nc\n')
-
-if __name__ == '__main__':
- mozunit.main()
diff --git a/config/tests/unit-Preprocessor.py b/config/tests/unit-Preprocessor.py
deleted file mode 100644
index 9ca640b20..000000000
--- a/config/tests/unit-Preprocessor.py
+++ /dev/null
@@ -1,577 +0,0 @@
-import unittest
-
-from StringIO import StringIO
-import os
-import sys
-import os.path
-from mozunit import main, MockedOpen
-
-from Preprocessor import Preprocessor
-
-def NamedIO(name, content):
- with open(name, 'w') as f:
- f.write(content)
- return name
-
-class TestPreprocessor(unittest.TestCase):
- """
- Unit tests for the Context class
- """
-
- def setUp(self):
- self.pp = Preprocessor()
- self.pp.out = StringIO()
-
- def test_conditional_if_0(self):
- f = NamedIO("conditional_if_0.in", """#if 0
-FAIL
-#else
-PASS
-#endif
-""")
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_no_marker(self):
- no_marker = """#if 0
-PASS
-#endif
-"""
- f = NamedIO("no_marker.in", no_marker)
- self.pp.setMarker(None)
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), no_marker)
-
- def test_string_value(self):
- f = NamedIO("string_value.in", """#define FOO STRING
-#if FOO
-string value is true
-#else
-string value is false
-#endif
-""")
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "string value is false\n")
-
- def test_number_value(self):
- f = NamedIO("string_value.in", """#define FOO 1
-#if FOO
-number value is true
-#else
-number value is false
-#endif
-""")
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "number value is true\n")
-
- def test_conditional_if_0_elif_1(self):
- f = NamedIO('conditional_if_0_elif_1.in', '''#if 0
-#elif 1
-PASS
-#else
-FAIL
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_conditional_if_1(self):
- f = NamedIO('conditional_if_1.in', '''#if 1
-PASS
-#else
-FAILE
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_conditional_if_1_elif_1_else(self):
- f = NamedIO('conditional_if_1_elif_1_else.in', '''#if 1
-PASS
-#elif 1
-FAIL
-#else
-FAIL
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_conditional_if_1_if_1(self):
- f = NamedIO('conditional_if_1_if_1.in', '''#if 1
-#if 1
-PASS
-#else
-FAIL
-#endif
-#else
-FAIL
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_conditional_not_0(self):
- f = NamedIO('conditional_not_0.in', '''#if !0
-PASS
-#else
-FAIL
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_conditional_not_1(self):
- f = NamedIO('conditional_not_1.in', '''#if !1
-FAIL
-#else
-PASS
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_conditional_not_emptyval(self):
- f = NamedIO('conditional_not_emptyval.in', '''#define EMPTYVAL
-#if !EMPTYVAL
-FAIL
-#else
-PASS
-#endif
-#if EMPTYVAL
-PASS
-#else
-FAIL
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\nPASS\n")
-
- def test_conditional_not_nullval(self):
- f = NamedIO('conditional_not_nullval.in', '''#define NULLVAL 0
-#if !NULLVAL
-PASS
-#else
-FAIL
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_expand(self):
- f = NamedIO('expand.in', '''#define ASVAR AS
-#expand P__ASVAR__S
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_undef_defined(self):
- f = NamedIO('undef_defined.in', '''#define BAR
-#undef BAR
-BAR
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "BAR\n")
-
- def test_undef_undefined(self):
- f = NamedIO('undef_undefined.in', '''#undef VAR
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "")
-
- def test_filter_attemptSubstitution(self):
- f = NamedIO('filter_attemptSubstitution.in', '''#filter attemptSubstitution
-@PASS@
-#unfilter attemptSubstitution
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "@PASS@\n")
-
- def test_filter_emptyLines(self):
- f = NamedIO('filter_emptyLines.in', '''lines with a
-
-blank line
-#filter emptyLines
-lines with
-
-no blank lines
-#unfilter emptyLines
-yet more lines with
-
-blank lines
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), '''lines with a
-
-blank line
-lines with
-no blank lines
-yet more lines with
-
-blank lines
-''')
-
- def test_filter_slashslash(self):
- f = NamedIO('filter_slashslash.in', '''#filter slashslash
-PASS//FAIL // FAIL
-#unfilter slashslash
-PASS // PASS
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\nPASS // PASS\n")
-
- def test_filter_spaces(self):
- f = NamedIO('filter_spaces.in', '''#filter spaces
-You should see two nice ascii tables
- +-+-+-+
- | | | |
- +-+-+-+
-#unfilter spaces
-+-+---+
-| | |
-+-+---+
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), """You should see two nice ascii tables
-+-+-+-+
-| | | |
-+-+-+-+
-+-+---+
-| | |
-+-+---+
-""")
-
- def test_filter_substitution(self):
- f = NamedIO('filter_substitution.in', '''#define VAR ASS
-#filter substitution
-P@VAR@
-#unfilter substitution
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_error(self):
- f = NamedIO('error.in', '''#error spit this message out
-''')
- caught_msg = None
- try:
- self.pp.do_include(f)
- except Preprocessor.Error, e:
- caught_msg = e.args[0][-1]
- self.assertEqual(caught_msg, 'spit this message out')
-
- def test_javascript_line(self):
- f = NamedIO('javascript_line.js.in', '''// Line 1
-#if 0
-// line 3
-#endif
-// line 5
-# comment
-// line 7
-// line 8
-// line 9
-# another comment
-// line 11
-#define LINE 1
-// line 13, given line number overwritten with 2
-''')
- self.pp.do_include(f)
- out = """// Line 1
-//@line 5 "CWDjavascript_line.js.in"
-// line 5
-//@line 7 "CWDjavascript_line.js.in"
-// line 7
-// line 8
-// line 9
-//@line 11 "CWDjavascript_line.js.in"
-// line 11
-//@line 2 "CWDjavascript_line.js.in"
-// line 13, given line number overwritten with 2
-"""
- out = out.replace('CWD', os.getcwd() + os.path.sep)
- self.assertEqual(self.pp.out.getvalue(), out)
-
- def test_literal(self):
- f = NamedIO('literal.in', '''#literal PASS
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_var_directory(self):
- f = NamedIO('var_directory.in', '''#ifdef DIRECTORY
-PASS
-#else
-FAIL
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_var_file(self):
- f = NamedIO('var_file.in', '''#ifdef FILE
-PASS
-#else
-FAIL
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_var_if_0(self):
- f = NamedIO('var_if_0.in', '''#define VAR 0
-#if VAR
-FAIL
-#else
-PASS
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_var_if_0_elifdef(self):
- f = NamedIO('var_if_0_elifdef.in', '''#if 0
-#elifdef FILE
-PASS
-#else
-FAIL
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_var_if_0_elifndef(self):
- f = NamedIO('var_if_0_elifndef.in', '''#if 0
-#elifndef VAR
-PASS
-#else
-FAIL
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_var_ifdef_0(self):
- f = NamedIO('var_ifdef_0.in', '''#define VAR 0
-#ifdef VAR
-PASS
-#else
-FAIL
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_var_ifdef_undef(self):
- f = NamedIO('var_ifdef_undef.in', '''#define VAR 0
-#undef VAR
-#ifdef VAR
-FAIL
-#else
-PASS
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_var_ifndef_0(self):
- f = NamedIO('var_ifndef_0.in', '''#define VAR 0
-#ifndef VAR
-FAIL
-#else
-PASS
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_var_ifndef_undef(self):
- f = NamedIO('var_ifndef_undef.in', '''#define VAR 0
-#undef VAR
-#ifndef VAR
-PASS
-#else
-FAIL
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_var_line(self):
- f = NamedIO('var_line.in', '''#ifdef LINE
-PASS
-#else
-FAIL
-#endif
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_lineEndings(self):
- f = NamedIO('lineEndings.in', '''first
-#literal second
-''')
- self.pp.setLineEndings('cr')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "first\rsecond\r")
-
- def test_filterDefine(self):
- f = NamedIO('filterDefine.in', '''#filter substitution
-#define VAR AS
-#define VAR2 P@VAR@
-@VAR2@S
-''')
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "PASS\n")
-
- def test_number_value_equals(self):
- f = NamedIO("number_value_equals.in", """#define FOO 1000
-#if FOO == 1000
-number value is equal
-#else
-number value is not equal
-#endif
-""")
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "number value is equal\n")
-
- def test_number_value_equals_defines(self):
- f = NamedIO("number_value_equals_defines.in", """#if FOO == 1000
-number value is equal
-#else
-number value is not equal
-#endif
-""")
- self.pp.handleCommandLine(["-DFOO=1000"])
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "number value is equal\n")
-
- def test_octal_value_equals(self):
- f = NamedIO("octal_value_equals.in", """#define FOO 0100
-#if FOO == 0100
-octal value is equal
-#else
-octal value is not equal
-#endif
-""")
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "octal value is equal\n")
-
- def test_octal_value_equals_defines(self):
- f = NamedIO("octal_value_equals_defines.in", """#if FOO == 0100
-octal value is equal
-#else
-octal value is not equal
-#endif
-""")
- self.pp.handleCommandLine(["-DFOO=0100"])
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "octal value is equal\n")
-
- def test_value_quoted_expansion(self):
- """
- Quoted values on the commandline don't currently have quotes stripped.
- Pike says this is for compat reasons.
- """
- f = NamedIO("value_quoted_expansion.in", """#filter substitution
-@FOO@
-""")
- self.pp.handleCommandLine(['-DFOO="ABCD"'])
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), '"ABCD"\n')
-
- def test_octal_value_quoted_expansion(self):
- f = NamedIO("value_quoted_expansion.in", """#filter substitution
-@FOO@
-""")
- self.pp.handleCommandLine(['-DFOO="0100"'])
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), '"0100"\n')
-
- def test_number_value_not_equals_quoted_defines(self):
- f = NamedIO("number_value_not_equals_quoted_defines.in", """#if FOO == 1000
-number value is equal
-#else
-number value is not equal
-#endif
-""")
- self.pp.handleCommandLine(['-DFOO="1000"'])
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "number value is not equal\n")
-
- def test_octal_value_not_equals_quoted_defines(self):
- f = NamedIO("octal_value_not_equals_quoted_defines.in", """#if FOO == 0100
-octal value is equal
-#else
-octal value is not equal
-#endif
-""")
- self.pp.handleCommandLine(['-DFOO="0100"'])
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), "octal value is not equal\n")
-
- def test_undefined_variable(self):
- f = NamedIO("undefined_variable.in", """#filter substitution
-@foo@
-""")
- try:
- self.pp.do_include(f)
- except Preprocessor.Error, exception:
- self.assertEqual(exception.key, 'UNDEFINED_VAR')
- else:
- self.fail("Expected a Preprocessor.Error")
-
- def test_include(self):
- with MockedOpen({"foo/test": """#define foo foobarbaz
-#include @inc@
-@bar@
-""",
- "bar": """#define bar barfoobaz
-@foo@
-"""}):
- f = NamedIO("include.in", """#filter substitution
-#define inc ../bar
-#include foo/test""")
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), """foobarbaz
-barfoobaz
-""")
-
- def test_include_missing_file(self):
- f = NamedIO("include_missing_file.in", "#include foo")
- try:
- self.pp.do_include(f)
- except Preprocessor.Error, exception:
- self.assertEqual(exception.key, 'FILE_NOT_FOUND')
- else:
- self.fail("Expected a Preprocessor.Error")
-
- def test_include_undefined_variable(self):
- f = NamedIO("include_undefined_variable.in", """#filter substitution
-#include @foo@
-""")
- try:
- self.pp.do_include(f)
- except Preprocessor.Error, exception:
- self.assertEqual(exception.key, 'UNDEFINED_VAR')
- else:
- self.fail("Expected a Preprocessor.Error")
-
- def test_include_literal_at(self):
- with MockedOpen({"@foo@": "#define foo foobarbaz"}):
- f = NamedIO("include_literal_at.in", """#include @foo@
-#filter substitution
-@foo@
-""")
- self.pp.do_include(f)
- self.assertEqual(self.pp.out.getvalue(), """foobarbaz
-""")
-
- def test_command_line_literal_at(self):
- with MockedOpen({"@foo@.in": """@foo@
-"""}):
- self.pp.handleCommandLine(['-Fsubstitution', '-Dfoo=foobarbaz', '@foo@.in'])
- self.assertEqual(self.pp.out.getvalue(), """foobarbaz
-""")
-
-if __name__ == '__main__':
- main()
diff --git a/config/tests/unit-buildlist.py b/config/tests/unit-buildlist.py
deleted file mode 100644
index 4e87b6090..000000000
--- a/config/tests/unit-buildlist.py
+++ /dev/null
@@ -1,84 +0,0 @@
-import unittest
-
-import os, sys, os.path, time
-from tempfile import mkdtemp
-from shutil import rmtree
-import mozunit
-
-from buildlist import addEntriesToListFile
-
-class TestBuildList(unittest.TestCase):
- """
- Unit tests for buildlist.py
- """
- def setUp(self):
- self.tmpdir = mkdtemp()
-
- def tearDown(self):
- rmtree(self.tmpdir)
-
- # utility methods for tests
- def touch(self, file, dir=None):
- if dir is None:
- dir = self.tmpdir
- f = os.path.join(dir, file)
- open(f, 'w').close()
- return f
-
- def assertFileContains(self, filename, l):
- """Assert that the lines in the file |filename| are equal
- to the contents of the list |l|, in order."""
- l = l[:]
- f = open(filename, 'r')
- lines = [line.rstrip() for line in f.readlines()]
- f.close()
- for line in lines:
- self.assert_(len(l) > 0,
- "ran out of expected lines! (expected '{0}', got '{1}')"
- .format(l, lines))
- self.assertEqual(line, l.pop(0))
- self.assert_(len(l) == 0,
- "not enough lines in file! (expected '{0}',"
- " got '{1}'".format(l, lines))
-
- def test_basic(self):
- "Test that addEntriesToListFile works when file doesn't exist."
- testfile = os.path.join(self.tmpdir, "test.list")
- l = ["a", "b", "c"]
- addEntriesToListFile(testfile, l)
- self.assertFileContains(testfile, l)
- # ensure that attempting to add the same entries again doesn't change it
- addEntriesToListFile(testfile, l)
- self.assertFileContains(testfile, l)
-
- def test_append(self):
- "Test adding new entries."
- testfile = os.path.join(self.tmpdir, "test.list")
- l = ["a", "b", "c"]
- addEntriesToListFile(testfile, l)
- self.assertFileContains(testfile, l)
- l2 = ["x","y","z"]
- addEntriesToListFile(testfile, l2)
- l.extend(l2)
- self.assertFileContains(testfile, l)
-
- def test_append_some(self):
- "Test adding new entries mixed with existing entries."
- testfile = os.path.join(self.tmpdir, "test.list")
- l = ["a", "b", "c"]
- addEntriesToListFile(testfile, l)
- self.assertFileContains(testfile, l)
- addEntriesToListFile(testfile, ["a", "x", "c", "z"])
- self.assertFileContains(testfile, ["a", "b", "c", "x", "z"])
-
- def test_add_multiple(self):
- """Test that attempting to add the same entry multiple times results in
- only one entry being added."""
- testfile = os.path.join(self.tmpdir, "test.list")
- addEntriesToListFile(testfile, ["a","b","a","a","b"])
- self.assertFileContains(testfile, ["a","b"])
- addEntriesToListFile(testfile, ["c","a","c","b","c"])
- self.assertFileContains(testfile, ["a","b","c"])
-
-if __name__ == '__main__':
- mozunit.main()
diff --git a/config/tests/unit-expandlibs.py b/config/tests/unit-expandlibs.py
index 7a7f1866e..3c7e5a44d 100644
--- a/config/tests/unit-expandlibs.py
+++ b/config/tests/unit-expandlibs.py
@@ -36,7 +36,7 @@ config_unix = {
config = sys.modules['expandlibs_config'] = imp.new_module('expandlibs_config')
-from expandlibs import LibDescriptor, ExpandArgs, relativize, ExpandLibsDeps
+from expandlibs import LibDescriptor, ExpandArgs, relativize
from expandlibs_gen import generate
from expandlibs_exec import ExpandArgsMore, SectionFinder
@@ -186,33 +186,15 @@ class TestExpandArgs(TestExpandInit):
args = ExpandArgs(['foo', '-bar'] + self.arg_files + [self.tmpfile('liby', Lib('y'))])
self.assertRelEqual(args, ['foo', '-bar'] + self.files + self.liby_files + self.libx_files)
- # When a library exists at the same time as a descriptor, we just use
- # the library
+ # When a library exists at the same time as a descriptor, we still use
+ # the descriptor.
self.touch([self.tmpfile('libx', Lib('x'))])
args = ExpandArgs(['foo', '-bar'] + self.arg_files + [self.tmpfile('liby', Lib('y'))])
- self.assertRelEqual(args, ['foo', '-bar'] + self.files + self.liby_files + [self.tmpfile('libx', Lib('x'))])
+ self.assertRelEqual(args, ['foo', '-bar'] + self.files + self.liby_files + self.libx_files)
self.touch([self.tmpfile('liby', Lib('y'))])
args = ExpandArgs(['foo', '-bar'] + self.arg_files + [self.tmpfile('liby', Lib('y'))])
- self.assertRelEqual(args, ['foo', '-bar'] + self.files + [self.tmpfile('liby', Lib('y'))])
-
-class TestExpandLibsDeps(TestExpandInit):
- def test_expandlibsdeps(self):
- '''Test library expansion for dependencies'''
- # Dependency list for a library with a descriptor is equivalent to
- # the arguments expansion, to which we add each descriptor
- args = self.arg_files + [self.tmpfile('liby', Lib('y'))]
- self.assertRelEqual(ExpandLibsDeps(args), ExpandArgs(args) + [self.tmpfile('libx', Lib('x') + config.LIBS_DESC_SUFFIX), self.tmpfile('liby', Lib('y') + config.LIBS_DESC_SUFFIX)])
-
- # When a library exists at the same time as a descriptor, the
- # descriptor is not a dependency
- self.touch([self.tmpfile('libx', Lib('x'))])
- args = self.arg_files + [self.tmpfile('liby', Lib('y'))]
- self.assertRelEqual(ExpandLibsDeps(args), ExpandArgs(args) + [self.tmpfile('liby', Lib('y') + config.LIBS_DESC_SUFFIX)])
-
- self.touch([self.tmpfile('liby', Lib('y'))])
- args = self.arg_files + [self.tmpfile('liby', Lib('y'))]
- self.assertRelEqual(ExpandLibsDeps(args), ExpandArgs(args))
+ self.assertRelEqual(args, ['foo', '-bar'] + self.files + self.liby_files + self.libx_files)
class TestExpandArgsMore(TestExpandInit):
def test_makelist(self):
@@ -250,7 +232,7 @@ class TestExpandArgsMore(TestExpandInit):
'''Test library extraction'''
# Divert subprocess.call
subprocess_call = subprocess.call
- extracted = {}
+ subprocess_check_output = subprocess.check_output
def call(args, **kargs):
if config.AR == 'lib':
self.assertEqual(args[:2], [config.AR, '-NOLOGO'])
@@ -294,31 +276,60 @@ class TestExpandArgsMore(TestExpandInit):
# ExpandArgsMore does the same as ExpandArgs
self.touch([self.tmpfile('liby', Lib('y'))])
- with ExpandArgsMore(['foo', '-bar'] + self.arg_files + [self.tmpfile('liby', Lib('y'))]) as args:
- self.assertRelEqual(args, ['foo', '-bar'] + self.files + [self.tmpfile('liby', Lib('y'))])
-
- # ExpandArgsMore also has an extra method extracting static libraries
- # when possible
- args.extract()
-
- files = self.files + self.liby_files + self.libx_files
- # With AR_EXTRACT, it uses the descriptors when there are, and
- # actually
- # extracts the remaining libraries
- extracted_args = []
- for f in files:
- if f.endswith(config.LIB_SUFFIX):
- extracted_args.extend(sorted(extracted[os.path.splitext(os.path.basename(f))[0]]))
- else:
- extracted_args.append(f)
- self.assertRelEqual(args, ['foo', '-bar'] + extracted_args)
-
- tmp = args.tmp
- # Check that all temporary files are properly removed
- self.assertEqual(True, all([not os.path.exists(f) for f in tmp]))
-
- # Restore subprocess.call
+ for iteration in (1, 2):
+ with ExpandArgsMore(['foo', '-bar'] + self.arg_files + [self.tmpfile('liby', Lib('y'))]) as args:
+ files = self.files + self.liby_files + self.libx_files
+
+ self.assertRelEqual(args, ['foo', '-bar'] + files)
+
+ extracted = {}
+ # ExpandArgsMore also has an extra method extracting static libraries
+ # when possible
+ args.extract()
+
+ # With AR_EXTRACT, it uses the descriptors when there are, and
+ # actually
+ # extracts the remaining libraries
+ extracted_args = []
+ for f in files:
+ if f.endswith(config.LIB_SUFFIX):
+ base = os.path.splitext(os.path.basename(f))[0]
+ # On the first iteration, we test the behavior of
+ # extracting archives that don't have a copy of their
+ # contents next to them, which is to use the file
+ # extracted from the archive in a temporary directory.
+ # On the second iteration, we test extracting archives
+ # that do have a copy of their contents next to them,
+ # in which case those contents are used instead of the
+ # temporarily extracted files.
+ if iteration == 1:
+ extracted_args.extend(sorted(extracted[base]))
+ else:
+ dirname = os.path.dirname(f[len(self.tmpdir)+1:])
+ if base.endswith('f'):
+ dirname = os.path.join(dirname, 'foo', 'bar')
+ extracted_args.extend([self.tmpfile(dirname, Obj(base)), self.tmpfile(dirname, Obj(base + '2'))])
+ else:
+ extracted_args.append(f)
+ self.assertRelEqual(args, ['foo', '-bar'] + extracted_args)
+
+ tmp = args.tmp
+ # Check that all temporary files are properly removed
+ self.assertEqual(True, all([not os.path.exists(f) for f in tmp]))
+
+ # Create archives contents next to them for the second iteration.
+ base = os.path.splitext(Lib('_'))[0]
+ self.touch(self.tmpfile(Obj(base.replace('_', suffix))) for suffix in ('a', 'a2', 'd', 'd2'))
+ try:
+ os.makedirs(self.tmpfile('foo', 'bar'))
+ except:
+ pass
+ self.touch(self.tmpfile('foo', 'bar', Obj(base.replace('_', suffix))) for suffix in ('f', 'f2'))
+ self.touch(self.tmpfile('liby', Obj(base.replace('_', suffix))) for suffix in ('z', 'z2'))
+
+ # Restore subprocess.call and subprocess.check_output
subprocess.call = subprocess_call
+ subprocess.check_output = subprocess_check_output
class FakeProcess(object):
def __init__(self, out, err = ''):
diff --git a/config/tests/unit-mozunit.py b/config/tests/unit-mozunit.py
index 4e03c1936..69798f4ba 100644
--- a/config/tests/unit-mozunit.py
+++ b/config/tests/unit-mozunit.py
@@ -15,8 +15,15 @@ class TestMozUnit(unittest.TestCase):
with os.fdopen(fd, 'w') as file:
file.write('foobar');
+ self.assertFalse(os.path.exists('file1'))
+ self.assertFalse(os.path.exists('file2'))
+
with MockedOpen({'file1': 'content1',
'file2': 'content2'}):
+ self.assertTrue(os.path.exists('file1'))
+ self.assertTrue(os.path.exists('file2'))
+ self.assertFalse(os.path.exists('foo/file1'))
+
# Check the contents of the files given at MockedOpen creation.
self.assertEqual(open('file1', 'r').read(), 'content1')
self.assertEqual(open('file2', 'r').read(), 'content2')
@@ -24,6 +31,7 @@ class TestMozUnit(unittest.TestCase):
# Check that overwriting these files alters their content.
with open('file1', 'w') as file:
file.write('foo')
+ self.assertTrue(os.path.exists('file1'))
self.assertEqual(open('file1', 'r').read(), 'foo')
# ... but not until the file is closed.
@@ -38,13 +46,17 @@ class TestMozUnit(unittest.TestCase):
file.write('bar')
self.assertEqual(open('file1', 'r').read(), 'foobar')
+ self.assertFalse(os.path.exists('file3'))
+
# Opening a non-existing file ought to fail.
self.assertRaises(IOError, open, 'file3', 'r')
+ self.assertFalse(os.path.exists('file3'))
# Check that writing a new file does create the file.
with open('file3', 'w') as file:
file.write('baz')
self.assertEqual(open('file3', 'r').read(), 'baz')
+ self.assertTrue(os.path.exists('file3'))
# Check the content of the file created outside MockedOpen.
self.assertEqual(open(path, 'r').read(), 'foobar')
diff --git a/config/tests/unit-writemozinfo.py b/config/tests/unit-writemozinfo.py
deleted file mode 100755
index d310e3e7f..000000000
--- a/config/tests/unit-writemozinfo.py
+++ /dev/null
@@ -1,194 +0,0 @@
-#!/usr/bin/env python
-import unittest
-import json, os, sys, time, tempfile
-from StringIO import StringIO
-import mozunit
-
-from writemozinfo import build_dict, write_json
-
-class TestBuildDict(unittest.TestCase):
- def testMissing(self):
- """
- Test that missing required values raises.
- """
- self.assertRaises(Exception, build_dict, {'OS_TARGET':'foo'})
- self.assertRaises(Exception, build_dict, {'TARGET_CPU':'foo'})
- self.assertRaises(Exception, build_dict, {'MOZ_WIDGET_TOOLKIT':'foo'})
-
- def testWin(self):
- d = build_dict({'OS_TARGET':'WINNT',
- 'TARGET_CPU':'i386',
- 'MOZ_WIDGET_TOOLKIT':'windows'})
- self.assertEqual('win', d['os'])
- self.assertEqual('x86', d['processor'])
- self.assertEqual('windows', d['toolkit'])
- self.assertEqual(32, d['bits'])
-
- def testLinux(self):
- d = build_dict({'OS_TARGET':'Linux',
- 'TARGET_CPU':'i386',
- 'MOZ_WIDGET_TOOLKIT':'gtk2'})
- self.assertEqual('linux', d['os'])
- self.assertEqual('x86', d['processor'])
- self.assertEqual('gtk2', d['toolkit'])
- self.assertEqual(32, d['bits'])
-
- d = build_dict({'OS_TARGET':'Linux',
- 'TARGET_CPU':'x86_64',
- 'MOZ_WIDGET_TOOLKIT':'gtk2'})
- self.assertEqual('linux', d['os'])
- self.assertEqual('x86_64', d['processor'])
- self.assertEqual('gtk2', d['toolkit'])
- self.assertEqual(64, d['bits'])
-
- def testMac(self):
- d = build_dict({'OS_TARGET':'Darwin',
- 'TARGET_CPU':'i386',
- 'MOZ_WIDGET_TOOLKIT':'cocoa'})
- self.assertEqual('mac', d['os'])
- self.assertEqual('x86', d['processor'])
- self.assertEqual('cocoa', d['toolkit'])
- self.assertEqual(32, d['bits'])
-
- d = build_dict({'OS_TARGET':'Darwin',
- 'TARGET_CPU':'x86_64',
- 'MOZ_WIDGET_TOOLKIT':'cocoa'})
- self.assertEqual('mac', d['os'])
- self.assertEqual('x86_64', d['processor'])
- self.assertEqual('cocoa', d['toolkit'])
- self.assertEqual(64, d['bits'])
-
- def testMacUniversal(self):
- d = build_dict({'OS_TARGET':'Darwin',
- 'TARGET_CPU':'i386',
- 'MOZ_WIDGET_TOOLKIT':'cocoa',
- 'UNIVERSAL_BINARY': '1'})
- self.assertEqual('mac', d['os'])
- self.assertEqual('universal-x86-x86_64', d['processor'])
- self.assertEqual('cocoa', d['toolkit'])
- self.assertFalse('bits' in d)
-
- d = build_dict({'OS_TARGET':'Darwin',
- 'TARGET_CPU':'x86_64',
- 'MOZ_WIDGET_TOOLKIT':'cocoa',
- 'UNIVERSAL_BINARY': '1'})
- self.assertEqual('mac', d['os'])
- self.assertEqual('universal-x86-x86_64', d['processor'])
- self.assertEqual('cocoa', d['toolkit'])
- self.assertFalse('bits' in d)
-
- def testAndroid(self):
- d = build_dict({'OS_TARGET':'Android',
- 'TARGET_CPU':'arm',
- 'MOZ_WIDGET_TOOLKIT':'android'})
- self.assertEqual('android', d['os'])
- self.assertEqual('arm', d['processor'])
- self.assertEqual('android', d['toolkit'])
- self.assertEqual(32, d['bits'])
-
- def testX86(self):
- """
- Test that various i?86 values => x86.
- """
- d = build_dict({'OS_TARGET':'WINNT',
- 'TARGET_CPU':'i486',
- 'MOZ_WIDGET_TOOLKIT':'windows'})
- self.assertEqual('x86', d['processor'])
-
- d = build_dict({'OS_TARGET':'WINNT',
- 'TARGET_CPU':'i686',
- 'MOZ_WIDGET_TOOLKIT':'windows'})
- self.assertEqual('x86', d['processor'])
-
- def testARM(self):
- """
- Test that all arm CPU architectures => arm.
- """
- d = build_dict({'OS_TARGET':'Linux',
- 'TARGET_CPU':'arm',
- 'MOZ_WIDGET_TOOLKIT':'gtk2'})
- self.assertEqual('arm', d['processor'])
-
- d = build_dict({'OS_TARGET':'Linux',
- 'TARGET_CPU':'armv7',
- 'MOZ_WIDGET_TOOLKIT':'gtk2'})
- self.assertEqual('arm', d['processor'])
-
- def testUnknown(self):
- """
- Test that unknown values pass through okay.
- """
- d = build_dict({'OS_TARGET':'RandOS',
- 'TARGET_CPU':'cptwo',
- 'MOZ_WIDGET_TOOLKIT':'foobar'})
- self.assertEqual("randos", d["os"])
- self.assertEqual("cptwo", d["processor"])
- self.assertEqual("foobar", d["toolkit"])
- # unknown CPUs should not get a bits value
- self.assertFalse("bits" in d)
-
- def testDebug(self):
- """
- Test that debug values are properly detected.
- """
- d = build_dict({'OS_TARGET':'Linux',
- 'TARGET_CPU':'i386',
- 'MOZ_WIDGET_TOOLKIT':'gtk2'})
- self.assertEqual(False, d['debug'])
-
- d = build_dict({'OS_TARGET':'Linux',
- 'TARGET_CPU':'i386',
- 'MOZ_WIDGET_TOOLKIT':'gtk2',
- 'MOZ_DEBUG':'1'})
- self.assertEqual(True, d['debug'])
-
- def testCrashreporter(self):
- """
- Test that crashreporter values are properly detected.
- """
-
-class TestWriteJson(unittest.TestCase):
- """
- Test the write_json function.
- """
- def setUp(self):
- fd, self.f = tempfile.mkstemp()
- os.close(fd)
-
- def tearDown(self):
- os.unlink(self.f)
-
- def testBasic(self):
- """
- Test that writing to a file produces correct output.
- """
- write_json(self.f, env={'OS_TARGET':'WINNT',
- 'TARGET_CPU':'i386',
- 'TOPSRCDIR':'/tmp',
- 'MOZCONFIG':'foo',
- 'MOZ_WIDGET_TOOLKIT':'windows'})
- with open(self.f) as f:
- d = json.load(f)
- self.assertEqual('win', d['os'])
- self.assertEqual('x86', d['processor'])
- self.assertEqual('windows', d['toolkit'])
- self.assertEqual('/tmp', d['topsrcdir'])
- self.assertEqual(os.path.normpath('/tmp/foo'), d['mozconfig'])
- self.assertEqual(32, d['bits'])
-
- def testFileObj(self):
- """
- Test that writing to a file-like object produces correct output.
- """
- s = StringIO()
- write_json(s, env={'OS_TARGET':'WINNT',
- 'TARGET_CPU':'i386',
- 'MOZ_WIDGET_TOOLKIT':'windows'})
- d = json.loads(s.getvalue())
- self.assertEqual('win', d['os'])
- self.assertEqual('x86', d['processor'])
- self.assertEqual('windows', d['toolkit'])
- self.assertEqual(32, d['bits'])
-
-if __name__ == '__main__':
- mozunit.main()