commit c1bab46bdf01943ae2ffe73803b584d8a9646530
Author: Michael Simacek <msimacek(a)redhat.com>
Date: Thu Nov 7 16:17:39 2013 +0100
[test] more tests for rpm macros
test/data/mvn_build/singleton_00001.xml | 12 ++
test/data/mvn_build/singleton_00002.xml | 16 +++
test/data/mvn_build/singleton_00003.xml | 15 +++
test/data/mvn_config/multiline_00001.xml | 16 +++
test/mvn_macros_test.py | 174 +++++++++++++++++++++++++++++-
test/test_rpmbuild.py | 18 +++-
6 files changed, 245 insertions(+), 6 deletions(-)
---
diff --git a/test/data/mvn_build/singleton_00001.xml
b/test/data/mvn_build/singleton_00001.xml
new file mode 100644
index 0000000..67cc726
--- /dev/null
+++ b/test/data/mvn_build/singleton_00001.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" ?>
+<configuration
xmlns="http://fedorahosted.org/xmvn/CONFIG/0.6.0">
+
+
+
+ <!--XMvn configuration file generated by javapackages.xmvn_config (part of
javapackages-tools)-->
+ <installerSettings>
+ <packageName>
+ test_mvn_build_singleton
+ </packageName>
+ </installerSettings>
+</configuration>
diff --git a/test/data/mvn_build/singleton_00002.xml
b/test/data/mvn_build/singleton_00002.xml
new file mode 100644
index 0000000..ad650f0
--- /dev/null
+++ b/test/data/mvn_build/singleton_00002.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" ?>
+<configuration
xmlns="http://fedorahosted.org/xmvn/CONFIG/0.6.0">
+
+
+
+ <!--XMvn configuration file generated by javapackages.xmvn_config (part of
javapackages-tools)-->
+ <artifactManagement>
+ <rule>
+ <artifactGlob>
+ <classifier>*?</classifier>
+ </artifactGlob>
+ <optional>true</optional>
+ <targetPackage>__noinstall</targetPackage>
+ </rule>
+ </artifactManagement>
+</configuration>
diff --git a/test/data/mvn_build/singleton_00003.xml
b/test/data/mvn_build/singleton_00003.xml
new file mode 100644
index 0000000..260bbab
--- /dev/null
+++ b/test/data/mvn_build/singleton_00003.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" ?>
+<configuration
xmlns="http://fedorahosted.org/xmvn/CONFIG/0.6.0">
+
+
+
+ <!--XMvn configuration file generated by javapackages.xmvn_config (part of
javapackages-tools)-->
+ <artifactManagement>
+ <rule>
+ <artifactGlob>
+ <artifactId>{*}</artifactId>
+ </artifactGlob>
+ <targetPackage>@1</targetPackage>
+ </rule>
+ </artifactManagement>
+</configuration>
diff --git a/test/data/mvn_config/multiline_00001.xml
b/test/data/mvn_config/multiline_00001.xml
new file mode 100644
index 0000000..a7a7b1e
--- /dev/null
+++ b/test/data/mvn_config/multiline_00001.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" ?>
+<configuration
xmlns="http://fedorahosted.org/xmvn/CONFIG/0.6.0">
+
+
+
+ <!--XMvn configuration file generated by javapackages.xmvn_config (part of
javapackages-tools)-->
+ <a>
+ <b>
+ <c>
+ <bla>
+ bla
+ </bla>
+ </c>
+ </b>
+ </a>
+</configuration>
diff --git a/test/mvn_macros_test.py b/test/mvn_macros_test.py
index 4b609fe..5281b02 100644
--- a/test/mvn_macros_test.py
+++ b/test/mvn_macros_test.py
@@ -101,7 +101,7 @@ class MvnMacrosTest(unittest.TestCase):
_, stderr, return_value = pack.run_prep()
self.assertEqual(return_value, 0, stderr)
confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d')
- filelist = os.listdir(confpath)
+ filelist = sorted(os.listdir(confpath))
self.assertEquals(len(filelist), 2)
for i in range(2):
actfile = os.path.join(confpath, filelist[i])
@@ -110,3 +110,175 @@ class MvnMacrosTest(unittest.TestCase):
report = compare_xml_files(actfile, expfile, ['artifactGlob'])
self.assertEquals(report, '', report)
+ @rpm_test()
+ def test_mvn_file_simple(self, pack):
+ pack.append_to_prep('%mvn_file :x file')
+ _, stderr, return_value = pack.run_prep()
+ self.assertEqual(return_value, 0, stderr)
+ confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d')
+ filelist = os.listdir(confpath)
+ self.assertEquals(len(filelist), 1)
+ actfile = os.path.join(confpath, filelist[0])
+ expfile = os.path.join(DIRPATH, 'data', 'mvn_file',
'simple_00001.xml')
+ report = compare_xml_files(actfile, expfile, ['artifactGlob'])
+ self.assertEquals(report, '', report)
+
+ @rpm_test()
+ def test_mvn_file_symlinks(self, pack):
+ pack.append_to_prep('%mvn_file :a file sym1 sym2 sym3')
+ _, stderr, return_value = pack.run_prep()
+ self.assertEqual(return_value, 0, stderr)
+ confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d')
+ filelist = os.listdir(confpath)
+ self.assertEquals(len(filelist), 1)
+ actfile = os.path.join(confpath, filelist[0])
+ expfile = os.path.join(DIRPATH, 'data', 'mvn_file',
+ 'symlinks_00001.xml')
+ report = compare_xml_files(actfile, expfile, ['artifactGlob'])
+ self.assertEquals(report, '', report)
+
+ @rpm_test()
+ def test_mvn_file_no_args(self, pack):
+ pack.append_to_prep('%mvn_file')
+ _, stderr, return_value = pack.run_prep()
+ self.assertNotEqual(return_value, 0)
+ self.assertNotEqual(stderr, '')
+
+ @rpm_test()
+ def test_mvn_file_single_arg(self, pack):
+ pack.append_to_prep('%mvn_file "aaa:bbb"')
+ _, stderr, return_value = pack.run_prep()
+ self.assertNotEqual(return_value, 0)
+ self.assertNotEqual(stderr, '')
+
+ @rpm_test()
+ def test_mvn_compat_version_simple(self, pack):
+ pack.append_to_prep('%mvn_compat_version aaa:bbb 1')
+ _, stderr, return_value = pack.run_prep()
+ self.assertEqual(return_value, 0, stderr)
+ confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d')
+ filelist = os.listdir(confpath)
+ self.assertEquals(len(filelist), 1)
+ actfile = os.path.join(confpath, filelist[0])
+ expfile = os.path.join(DIRPATH, 'data', 'mvn_compat_version',
+ 'simple_00001.xml')
+ report = compare_xml_files(actfile, expfile, ['artifactGlob'])
+ self.assertEquals(report, '', report)
+
+ @rpm_test()
+ def test_mvn_compat_version_no_args(self, pack):
+ pack.append_to_prep('%mvn_compat_version')
+ _, stderr, return_value = pack.run_prep()
+ self.assertNotEqual(return_value, 0)
+ self.assertNotEqual(stderr, '')
+
+ @rpm_test()
+ def test_mvn_compat_version_single(self, pack):
+ pack.append_to_prep('%mvn_compat_version "aaa:bbb"')
+ _, stderr, return_value = pack.run_prep()
+ self.assertNotEqual(return_value, 0)
+ self.assertNotEqual(stderr, '')
+
+ @rpm_test()
+ def test_mvn_package_simple(self, pack):
+ pack.append_to_prep('%mvn_package aaa:bbb pack')
+ _, stderr, return_value = pack.run_prep()
+ self.assertEqual(return_value, 0, stderr)
+ confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d')
+ filelist = os.listdir(confpath)
+ self.assertEquals(len(filelist), 1)
+ actfile = os.path.join(confpath, filelist[0])
+ expfile = os.path.join(DIRPATH, 'data', 'mvn_package',
+ 'simple_00001.xml')
+ report = compare_xml_files(actfile, expfile, ['artifactGlob'])
+ self.assertEquals(report, '', report)
+
+ @rpm_test()
+ def test_mvn_package_no_args(self, pack):
+ pack.append_to_prep('%mvn_package')
+ _, stderr, return_value = pack.run_prep()
+ self.assertNotEqual(return_value, 0)
+ self.assertNotEqual(stderr, '')
+
+ @rpm_test()
+ def test_mvn_package_single(self, pack):
+ pack.append_to_prep('%mvn_package aaa:bbb')
+ _, stderr, return_value = pack.run_prep()
+ self.assertEqual(return_value, 0, stderr)
+ confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d')
+ filelist = os.listdir(confpath)
+ self.assertEquals(len(filelist), 1)
+ actfile = os.path.join(confpath, filelist[0])
+ expfile = os.path.join(DIRPATH, 'data', 'mvn_package',
+ 'single_00001.xml')
+ report = compare_xml_files(actfile, expfile, ['artifactGlob'])
+ self.assertEquals(report, '', report)
+
+ @rpm_test()
+ def test_mvn_config_no_args(self, pack):
+ pack.append_to_prep('%mvn_config')
+ _, stderr, return_value = pack.run_prep()
+ self.assertNotEqual(return_value, 0)
+ self.assertNotEqual(stderr, '')
+
+ @rpm_test()
+ def test_mvn_config_single(self, pack):
+ pack.append_to_prep('%mvn_config')
+ _, stderr, return_value = pack.run_prep()
+ self.assertNotEqual(return_value, 0)
+ self.assertNotEqual(stderr, '')
+
+ @rpm_test()
+ def test_mvn_config_path(self, pack):
+ pack.append_to_prep('%mvn_config a/b/c xxx')
+ _, stderr, return_value = pack.run_prep()
+ self.assertEqual(return_value, 0, stderr)
+ confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d')
+ filelist = os.listdir(confpath)
+ self.assertEquals(len(filelist), 1)
+ actfile = os.path.join(confpath, filelist[0])
+ expfile = os.path.join(DIRPATH, 'data', 'mvn_config',
+ 'path_00001.xml')
+ report = compare_xml_files(actfile, expfile, ['artifactGlob'])
+ self.assertEquals(report, '', report)
+
+ @rpm_test()
+ def test_mvn_config_multiline(self, pack):
+ pack.append_to_prep("""%mvn_config a/b/c "
+ <bla>
+ bla
+ </bla>
+ " """)
+ _, stderr, return_value = pack.run_prep()
+ self.assertEqual(return_value, 0, stderr)
+ confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d')
+ filelist = os.listdir(confpath)
+ self.assertEquals(len(filelist), 1)
+ actfile = os.path.join(confpath, filelist[0])
+ expfile = os.path.join(DIRPATH, 'data', 'mvn_config',
+ 'multiline_00001.xml')
+ report = compare_xml_files(actfile, expfile, ['artifactGlob'])
+ self.assertEquals(report, '', report)
+
+ @rpm_test()
+ def test_mvn_build_singleton(self, pack):
+ pack.append_to_build('%mvn_build -s')
+ _, stderr, return_value = pack.run_build()
+ self.assertEqual(return_value, 0, stderr)
+ confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d')
+ filelist = sorted(os.listdir(confpath))
+ self.assertEquals(len(filelist), 3)
+ for i in range(3):
+ actfile = os.path.join(confpath, filelist[i])
+ filename = 'singleton_0000{i}.xml'.format(i=i + 1)
+ expfile = os.path.join(DIRPATH, 'data', 'mvn_build',
filename)
+ report = compare_xml_files(actfile, expfile, ['artifactGlob'])
+ self.assertEquals(report, '', report)
+
+ expfile = os.path.join(pack.buildpath, '.xmvn', 'out')
+ actfile = os.path.join(DIRPATH, 'data', 'mvn_build',
+ 'singleton_out')
+ with open(actfile, 'r') as act:
+ with open(expfile, 'r') as exp:
+ self.assertEquals(act.read(), exp.read())
+
diff --git a/test/test_rpmbuild.py b/test/test_rpmbuild.py
index 59f1d03..bef4f82 100644
--- a/test/test_rpmbuild.py
+++ b/test/test_rpmbuild.py
@@ -23,6 +23,11 @@ class Package(object):
self.__prep = ''
self.__build = ''
self.buildpath = os.path.join('rpmbuild', 'BUILD', name +
'-1')
+ self.__env = dict(os.environ)
+ self.__env['HOME'] = os.getcwd()
+ self.__env['PYTHONPATH'] = os.path.join(DIRPATH, '..',
'python')
+ self.__env['PATH'] = '{mock}:{path}'.format(mock=DIRPATH,
+ path=self.__env['PATH'])
def add_source(self, sourcepath, newname=None):
"""Add source file to a package
@@ -60,16 +65,13 @@ class Package(object):
return self.__invoke_rpmbuild(['-bb'])
def __invoke_rpmbuild(self, args):
- env = dict(os.environ)
- env['HOME'] = os.getcwd()
- env['PYTHONPATH'] = os.path.join(DIRPATH, '..',
'python')
outfile = open("tmpout", 'w')
errfile = open("tmperr", 'w')
topdir = '--define=_topdir {cwd}/rpmbuild'.format(cwd=os.getcwd())
proc = subprocess.Popen(['rpmbuild', topdir,
os.path.join('rpmbuild', 'SPECS',
self.__name + '.spec')]
- + args, shell=False, env=env,
+ + args, shell=False, env=self.__env,
stdout=outfile, stderr=errfile)
ret = proc.wait()
outfile = open("tmpout", 'r+')
@@ -80,6 +82,9 @@ class Package(object):
os.remove('tmperr')
return (out, err, ret)
+ def set_env(self, name, value):
+ self.__env[name] = value
+
def __prepare_all(self):
try:
os.mkdir('rpmbuild')
@@ -117,6 +122,7 @@ class Package(object):
""")
prep_section = dedent("""\
+
%prep
mkdir %{name}-%{version}
cd %{name}-%{version}
@@ -126,9 +132,11 @@ class Package(object):
prep_section += self.__prep
build_section = dedent("""\
- %build
+ %build
+ cd %{name}-%{version}
""")
+ build_section += self.__build
specpath = os.path.join('rpmbuild', 'SPECS', self.__name +
'.spec')
with open(specpath, 'w') as specfile: