tests/run-tests.py
changeset 1367 b3bee8727631
parent 1366 987a80dec7db
child 1368 27b5b55ff3d3
equal deleted inserted replaced
1362:a5dabff2e764 1367:b3bee8727631
   131                 entries[line] = filename
   131                 entries[line] = filename
   132 
   132 
   133         f.close()
   133         f.close()
   134     return entries
   134     return entries
   135 
   135 
   136 def parseargs():
   136 def getparser():
   137     parser = optparse.OptionParser("%prog [options] [tests]")
   137     parser = optparse.OptionParser("%prog [options] [tests]")
   138 
   138 
   139     # keep these sorted
   139     # keep these sorted
   140     parser.add_option("--blacklist", action="append",
   140     parser.add_option("--blacklist", action="append",
   141         help="skip tests listed in the specified blacklist file")
   141         help="skip tests listed in the specified blacklist file")
   208                       help='run tests in random order')
   208                       help='run tests in random order')
   209 
   209 
   210     for option, (envvar, default) in defaults.items():
   210     for option, (envvar, default) in defaults.items():
   211         defaults[option] = type(default)(os.environ.get(envvar, default))
   211         defaults[option] = type(default)(os.environ.get(envvar, default))
   212     parser.set_defaults(**defaults)
   212     parser.set_defaults(**defaults)
   213     (options, args) = parser.parse_args()
   213 
       
   214     return parser
       
   215 
       
   216 def parseargs(args, parser):
       
   217     (options, args) = parser.parse_args(args)
   214 
   218 
   215     # jython is always pure
   219     # jython is always pure
   216     if 'java' in sys.platform or '__pypy__' in sys.modules:
   220     if 'java' in sys.platform or '__pypy__' in sys.modules:
   217         options.pure = True
   221         options.pure = True
   218 
   222 
   933                 if k in t:
   937                 if k in t:
   934                     break
   938                     break
   935                 else:
   939                 else:
   936                     return ignore("doesn't match keyword")
   940                     return ignore("doesn't match keyword")
   937 
   941 
   938     if not lctest.startswith("test-"):
   942     if not os.path.basename(lctest).startswith("test-"):
   939         return skip("not a test file")
   943         return skip("not a test file")
   940     for ext, func, out in testtypes:
   944     for ext, func, out in testtypes:
   941         if lctest.endswith(ext):
   945         if lctest.endswith(ext):
   942             runner = func
   946             runner = func
   943             ref = os.path.join(TESTDIR, test + out)
   947             ref = os.path.join(TESTDIR, test + out)
  1174         return 80
  1178         return 80
  1175 
  1179 
  1176 testtypes = [('.py', pytest, '.out'),
  1180 testtypes = [('.py', pytest, '.out'),
  1177              ('.t', tsttest, '')]
  1181              ('.t', tsttest, '')]
  1178 
  1182 
  1179 def main():
  1183 def main(args, parser=None):
  1180     (options, args) = parseargs()
  1184     parser = parser or getparser()
       
  1185     (options, args) = parseargs(args, parser)
  1181     os.umask(022)
  1186     os.umask(022)
  1182 
  1187 
  1183     checktools()
  1188     checktools()
  1184 
  1189 
  1185     if not args:
  1190     if not args:
  1190             args = stdout.strip('\0').split('\0')
  1195             args = stdout.strip('\0').split('\0')
  1191         else:
  1196         else:
  1192             args = os.listdir(".")
  1197             args = os.listdir(".")
  1193 
  1198 
  1194     tests = [t for t in args
  1199     tests = [t for t in args
  1195              if t.startswith("test-")
  1200              if os.path.basename(t).startswith("test-")
  1196              and (t.endswith(".py") or t.endswith(".t"))]
  1201                  and (t.endswith(".py") or t.endswith(".t"))]
  1197 
  1202 
  1198     if options.random:
  1203     if options.random:
  1199         random.shuffle(tests)
  1204         random.shuffle(tests)
  1200     else:
  1205     else:
  1201         # keywords for slow tests
  1206         # keywords for slow tests
  1226         tmpdir = options.tmpdir
  1231         tmpdir = options.tmpdir
  1227         if os.path.exists(tmpdir):
  1232         if os.path.exists(tmpdir):
  1228             # Meaning of tmpdir has changed since 1.3: we used to create
  1233             # Meaning of tmpdir has changed since 1.3: we used to create
  1229             # HGTMP inside tmpdir; now HGTMP is tmpdir.  So fail if
  1234             # HGTMP inside tmpdir; now HGTMP is tmpdir.  So fail if
  1230             # tmpdir already exists.
  1235             # tmpdir already exists.
  1231             sys.exit("error: temp dir %r already exists" % tmpdir)
  1236             print "error: temp dir %r already exists" % tmpdir
       
  1237             return 1
  1232 
  1238 
  1233             # Automatically removing tmpdir sounds convenient, but could
  1239             # Automatically removing tmpdir sounds convenient, but could
  1234             # really annoy anyone in the habit of using "--tmpdir=/tmp"
  1240             # really annoy anyone in the habit of using "--tmpdir=/tmp"
  1235             # or "--tmpdir=$HOME".
  1241             # or "--tmpdir=$HOME".
  1236             #vlog("# Removing temp dir", tmpdir)
  1242             #vlog("# Removing temp dir", tmpdir)
  1291     vlog("# Using HGTMP", HGTMP)
  1297     vlog("# Using HGTMP", HGTMP)
  1292     vlog("# Using PATH", os.environ["PATH"])
  1298     vlog("# Using PATH", os.environ["PATH"])
  1293     vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH])
  1299     vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH])
  1294 
  1300 
  1295     try:
  1301     try:
  1296         sys.exit(runtests(options, tests) or 0)
  1302         return runtests(options, tests) or 0
  1297     finally:
  1303     finally:
  1298         time.sleep(.1)
  1304         time.sleep(.1)
  1299         cleanup(options)
  1305         cleanup(options)
  1300 
  1306 
  1301 if __name__ == '__main__':
  1307 if __name__ == '__main__':
  1302     main()
  1308     sys.exit(main(sys.argv[1:]))