blob: c334109e1deefe76352c41b4cadfee341c8aa4a2 [file] [log] [blame]
Daniel Dunbarfb15e592009-09-08 05:31:18 +00001class LitConfig:
2 """LitConfig - Configuration data for a 'lit' test runner instance, shared
3 across all tests.
4
5 The LitConfig object is also used to communicate with client configuration
6 files, it is always passed in as the global variable 'lit' so that
7 configuration files can access common functionality and internal components
8 easily.
9 """
10
11 # Provide access to built-in formats.
12 import LitFormats as formats
13
14 # Provide access to built-in utility functions.
15 import Util as util
16
17 def __init__(self, progname, path, quiet,
18 useValgrind, valgrindArgs,
19 useTclAsSh,
20 noExecute, debug, isWindows):
21 # The name of the test runner.
22 self.progname = progname
23 # The items to add to the PATH environment variable.
24 self.path = list(map(str, path))
25 self.quiet = bool(quiet)
26 self.useValgrind = bool(useValgrind)
27 self.valgrindArgs = list(valgrindArgs)
28 self.useTclAsSh = bool(useTclAsSh)
29 self.noExecute = noExecute
30 self.debug = debug
31 self.isWindows = bool(isWindows)
Daniel Dunbarc62ebee2009-10-19 03:54:21 +000032 self.bashPath = None
Daniel Dunbarfb15e592009-09-08 05:31:18 +000033
34 self.numErrors = 0
35 self.numWarnings = 0
36
37 def load_config(self, config, path):
38 """load_config(config, path) - Load a config object from an alternate
39 path."""
40 from TestingConfig import TestingConfig
41 return TestingConfig.frompath(path, config.parent, self,
42 mustExist = True,
43 config = config)
44
Daniel Dunbarc62ebee2009-10-19 03:54:21 +000045 def getBashPath(self):
46 """getBashPath - Get the path to 'bash'"""
47 import os, Util
48
49 if self.bashPath is not None:
50 return self.bashPath
51
52 self.bashPath = Util.which('bash', os.pathsep.join(self.path))
53 if self.bashPath is None:
54 # Check some known paths.
55 for path in ('/bin/bash', '/usr/bin/bash'):
56 if os.path.exists(path):
57 self.bashPath = path
58 break
59
60 if self.bashPath is None:
61 self.warning("Unable to find 'bash', running Tcl tests internally.")
62 self.bashPath = ''
63
64 return self.bashPath
65
Daniel Dunbarfb15e592009-09-08 05:31:18 +000066 def _write_message(self, kind, message):
67 import inspect, os, sys
68
69 # Get the file/line where this message was generated.
70 f = inspect.currentframe()
71 # Step out of _write_message, and then out of wrapper.
72 f = f.f_back.f_back
73 file,line,_,_,_ = inspect.getframeinfo(f)
74 location = '%s:%d' % (os.path.basename(file), line)
75
76 print >>sys.stderr, '%s: %s: %s: %s' % (self.progname, location,
77 kind, message)
78
79 def note(self, message):
80 self._write_message('note', message)
81
82 def warning(self, message):
83 self._write_message('warning', message)
84 self.numWarnings += 1
85
86 def error(self, message):
87 self._write_message('error', message)
88 self.numErrors += 1
89
90 def fatal(self, message):
91 import sys
92 self._write_message('fatal', message)
93 sys.exit(2)