[PATCH] tests: introduce c-style conditional sections in .t tests

Adrian Buehlmann adrian at cadifra.com
Sun Jun 3 11:54:41 CDT 2012


On 2012-06-03 18:14, Adrian Buehlmann wrote:
> On 2012-06-03 15:29, Mads Kiilerich wrote:
>> # HG changeset patch
>> # User Mads Kiilerich <mads at kiilerich.com>
>> # Date 1338510312 -7200
>> # Node ID 55b24b85074d21e14c2d92ac1552f15d85c586a5
>> # Parent  7b460b49bf7b75c5a4ab444915c52802c9f97f33
>> tests: introduce c-style conditional sections in .t tests
>>
>> This makes it possible to have conditional sections like:
>>
>> #if windows
>>   $ echo foo
>>   foo
>> #else
>>   $ echo bar
>>   bar
>> #endif
>>
>> The directives and skipped sections are treated like comments, so don't
>> interleave them with commands and their output.
>>
>> The parameters to #if are evaluated while preparing the test by passing them
>> over to hghave. Requirements can thus be negated with 'no-' prefix, and
>> multiple requirements must all be true to return true.
>>
>> diff --git a/tests/run-tests.py b/tests/run-tests.py
>> --- a/tests/run-tests.py
>> +++ b/tests/run-tests.py
>> @@ -594,6 +594,19 @@
>>      # can generate the surrounding doctest magic
>>      inpython = False
>>  
>> +    # True or False when in a true or false conditional section
>> +    skipping = None
>> +
>> +    def hghave(reqs):
>> +        # TODO: do something smarter when all other uses of hghave is gone
>> +        proc = Popen4('%s -c "%s/hghave %s"' %
>> +                      (options.shell, TESTDIR, ' '.join(reqs)), TESTDIR, 0)
> 
> Doesn't work here on Windows 7 with MSYS: ret is always 127, and the
> output of the process is (example):
> 
> 'sh: C:Usersadihgreposhg-maintests/hghave: No such file or directory\n'
> 
> It works, if I do:
> 
>         tdir = TESTDIR.replace('\\', '/')
>         proc = Popen4('%s -c "%s/hghave %s"' %
>                       (options.shell, tdir, ' '.join(reqs)), TESTDIR, 0)
> 
> Otherwise pretty neat.
> 
> Could you please include that fix and resend? Thanks. (Or I'll do it on
> your behalf, if you don't mind).

Or maybe we should fix that more centrally:

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1240,7 +1240,7 @@
             del os.environ[k]

     global TESTDIR, HGTMP, INST, BINDIR, PYTHONDIR, COVERAGE_FILE
-    TESTDIR = os.environ["TESTDIR"] = os.getcwd()
+    TESTDIR = os.environ["TESTDIR"] = os.getcwd().replace('\\', '/')
     if options.tmpdir:
         options.keep_tmpdir = True
         tmpdir = options.tmpdir

to make sure it can't possibly make troubles anywhere else anymore.

I'll probably send a separate patch for that. Mads' #if patch can then
be taken as is.


More information about the Mercurial-devel mailing list