metacity r3746 - branches/test-system/test



Author: tthurman
Date: Mon Jun  2 03:16:14 2008
New Revision: 3746
URL: http://svn.gnome.org/viewvc/metacity?rev=3746&view=rev

Log:
considerable improvements

Modified:
   branches/test-system/test/metacity-test

Modified: branches/test-system/test/metacity-test
==============================================================================
--- branches/test-system/test/metacity-test	(original)
+++ branches/test-system/test/metacity-test	Mon Jun  2 03:16:14 2008
@@ -25,25 +25,71 @@
 import getopt
 import os
 import tempfile
+import commands
+import traceback
 
 class Test(object):
     """Grandfather of all tests.  (Yes, I know about the 'unittest'
     module; I think what we're doing here isn't terribly similar.)"""
     # If when we get this working I'm shown to be wrong, well,
     # that's fine too.
-    pass
+
+    def prerequisites(self):
+        return []
 
 tests_by_name = {}
 tests_by_bug_number = {}
 
 pristine_copy = '/usr/local/src/metacity'
+working_directory = pristine_copy
+homepath = os.getcwd ()
+
+def run(verb, command):
+    """Prints the verb, then executes the command.
+    It's here so we can toggle dry runs
+    (although this isn't currently implemented).
+    If the command is None, writes the command in brackets and exits.
+    """
+
+    if command is None:
+        sys.stdout.write('(%s) ' % verb)
+        return True
+
+    sys.stdout.write('%s ' % verb)
+    sys.stdout.flush()
+
+    os.chdir (working_directory)
+
+    (status, output) = commands.getstatusoutput(command)
+
+    os.chdir (homepath) # in case it matters to anyone
+
+    if status!=0:
+        (fd, name) = tempfile.mkstemp(suffix='.txt', text=True)
+
+        # Can't do this in one line.  No idea why not.
+        temp = os.fdopen(fd, 'w')
+        temp.write("%s - %s\n\n%s\n\nReturn result is: %d" % (verb, command, output, status))
+        del temp
+
+        sys.stdout.write('(See %s ): ' % name)
+        sys.stdout.flush()
+
+        return False
+    else:
+        return True
+
+
+class TestFailure(Exception):
+    "Houston, we have a problem."
+    def __init__(self, problem):
+        self.problem = problem
 
-def run(command):
-    "Executes a command.  It's here so we can toggle dry runs."
-    print 'Run %s' % command
-    result = os.system(command)
-    print 'Return result of %s was %d' % (command, result)
-    return result == 0
+    def __str__(self):
+        return self.problem
+
+    def message(self):
+        return self.problem
 
 #################
 #
@@ -57,6 +103,13 @@
 
 class BuildTest(Test):
     "Convenience class to build others around"
+    # Should this go in the included files, or the main file?
+
+    def executable_name(self):
+        name = self.__class__.__name__
+        if name.startswith('test_'):
+            name = name[5:]
+        return name
 
     def run_build(self, **params):
         """Generalised routine to attempt to build Metacity.
@@ -66,8 +119,6 @@
         autogen = (string) -- opts for autogen (or its kids)
         c = (string) -- C flags
         """
-        print 'Here we are.', params
-        print 'We would:'
         working_directory = pristine_copy
         if False:
             # This is an idea I had about copying everything into /tmp
@@ -75,53 +126,90 @@
             # It slows everything down to turn it on by default, though.
             # XXX allow people to turn it on.
             temp_directory = tempfile.mkdtemp(prefix='metatest_')
-            if run('cp -LpR %s %s' % (pristine_copy, temp_directory))!=0:
-                print 'There were errors during copying (your repository is probably'
-                print 'a little untidy).  Please go and tidy up and then come back.'
-                return False
+            if not run('copy', 'cp -LpR %s %s' % (pristine_copy, temp_directory)):
+                raise('There were errors during copying (your repository is probably '+\
+                 'a little untidy).  Please go and tidy up and then come back.')
             working_directory = temp_directory
 
         makefile = os.path.join(working_directory, 'Makefile')
 
-        os.chdir (working_directory)
+        targetdir = os.path.abspath ('.built')
+
+        # TODO -- if not run(...) raise TestFailure (...) is common and could be
+        # an extra param on run() instead.
 
         if os.path.lexists (makefile):
-            if not run ("make distclean"):
-                print 'Could not clean up; this is bad'
-                return False
+            if not run ('clean', "make distclean"):
+                raise TestFailure('Could not clean up; this is bad')
         else:
-            print 'No need to distclean'
+            run('clean', None)
 
         autogen_opts = ''
         if params.has_key ('autogen'):
             autogen_opts = params['autogen']
 
-        if not run('./autogen.sh %s' % autogen_opts):
-            print 'Autogen failed; can\'t really go on from here.'
-            return False
+        if not run('config', './autogen.sh %s' % autogen_opts):
+            raise TestFailure('Autogen failed; can\'t really go on from here.')
+
+        flags = []
+        if params.has_key ('cflags'):
+            flags.append ('CFLAGS=%s' % params['cflags'].replace(' ','\ '))
+
+        command = ''
+        if params.has_key ('action'):
+            command = params['action']
+
+        if not run('make', 'env %s make %s' % (' '.join(flags), command)):
+            raise TestFailure('Build failed; can\'t really go on from here.')
+
+        binary = 'src/metacity' # or 'metacity/src/metacity' sometimes. hmm....
+
+        if not os.path.lexists(binary):
+            raise TestFailure('Binary was not built.')
+
+        output = commands.getoutput("env LANG=C %s --version" % binary)
+
+        if not output.startswith('metacity '):
+            raise TestFailure('Built program fails to identify itself: ['+output+']')
+
+        # Should also test what it says about its flags
+        # (and make it show its flags)
+
+        if not run ('recopy', 'cp %s %s/metacity-%s' % (binary, homepath, self.executable_name())):
+            raise TestFailure('Couldn\'t copy binary somewhere safe')
+
+        # Should clear up build if it's temp directory
 
         return True
 
 class test_ansi(BuildTest):
-    def run(self, **params):
+    def run(self):
         return self.run_build(c='ansi')
 
 class test_gconfoff(BuildTest):
-    def run(self, **params):
+    def run(self):
         return self.run_build(autogen='--disable-gconf')
 
 class test_compositoroff(BuildTest):
-    def run(self, **params):
+    def run(self):
         return self.run_build(autogen='--disable-compositor')
 
 class test_teston(BuildTest):
-    def run(self, **params):
+    def run(self):
         return self.run_build(autogen='--enable-testing')
 
 class test_distcheck(BuildTest):
-    def run(self, **params):
+    def run(self):
         return self.run_build(action='distcheck')
 
+class test_warningerrors(BuildTest):
+    def run(self):
+        return self.run_build(cflags='-Wall')
+
+class test_pedantic(BuildTest):
+    def run(self):
+        return self.run_build(cflags='-Wall -Werror -pedantic')
+
 # Populate tests_by_name by introspection
 for (name, klass) in inspect.getmembers(sys.modules['__main__']):
     if not name.startswith('test_'): continue
@@ -195,6 +283,9 @@
 
         switch_polarity = 0
 
+        if not os.path.lexists('.built'):
+            os.mkdir ('.built')
+
         for test in testlist:
             if test in ('all', 'allbut'):
                 switch_polarity = 1
@@ -226,9 +317,12 @@
                     print 'PASS'
                 else:
                     print 'FAIL'
-            except Exception, e:
+            except TestFailure, tf:
+                print 'FAIL (%s)' % tf
+            except:
                 # obviously not good
-                print 'FAIL (%s)' % e
+                print 'FAIL'
+                traceback.print_exception(*sys.exc_info())
             
 
 if __name__=='__main__':



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]