[PATCH RFC] tests: require regexes in unified tests to be marked with " (re)"

Brodie Rao brodie at bitheap.org
Tue Sep 21 16:58:24 CDT 2010


On Tue, Sep 21, 2010 at 3:29 PM, Bill Barry <after.fallout at gmail.com> wrote:
> Brodie Rao wrote:
>>
>> @@ -528,12 +525,12 @@ def tsttest(test, options):
>>             if pos in expected and expected[pos]:
>>                 el = expected[pos].pop(0)
>>  -            if el == l: # perfect match (fast)
>> -                postout.append("  " + l)
>> -            elif el and rematch(el, l): # fallback regex match
>> -                postout.append("  " + el)
>> -            else: # mismatch - let diff deal with it
>> -                postout.append("  " + l)
>> +            if el and el.endswith(" (re)\n") and rematch(el[:-6], l):
>> +                postout.append("  " + el) # regex match
>> +            elif el and el.endswith(" (re) (plain)\n"):
>> +                postout.append("  " + l[:-1] + " (plain)\n") # disable
>> regex
>> +            else:
>> +                postout.append("  " + l) # let diff deal with it
>>
>
> There did seem to be some sense with the fast match path (if el == l:) being
> the first case of the if because it is likely that most cases would pass
> that test. Is there any significant time difference in running the tests
> with and without this check?

Not that I can see. I wrote a simple test that hits most of the
features (test-run-tests.t) of the format and used timeit to run
tsttest() on it 1000 times. I also timed running every unified test
with and without the patch.

Before the patch:

1000 loops, best of 3: 6.03 msec per loop
1000 loops, best of 3: 6 msec per loop
1000 loops, best of 3: 5.85 msec per loop

./run-tests.py test-run-tests.t  1.67s user 0.25s system 64% cpu 2.977 total
./run-tests.py test-run-tests.t  1.59s user 0.29s system 64% cpu 2.900 total
./run-tests.py test-run-tests.t  1.60s user 0.30s system 65% cpu 2.910 total
./run-tests.py test-run-tests.t  1.64s user 0.25s system 64% cpu 2.929 total
./run-tests.py test-run-tests.t  1.56s user 0.37s system 66% cpu 2.921 total
./run-tests.py test-run-tests.t  1.57s user 0.34s system 64% cpu 2.939 total
./run-tests.py test-run-tests.t  1.62s user 0.26s system 64% cpu 2.911 total
./run-tests.py test-run-tests.t  1.69s user 0.24s system 66% cpu 2.909 total
./run-tests.py test-run-tests.t  1.60s user 0.30s system 64% cpu 2.942 total
./run-tests.py test-run-tests.t  1.61s user 0.28s system 65% cpu 2.907 total

./run-tests.py *.t  338.44s user 68.74s system 97% cpu 6:57.31 total
./run-tests.py *.t  340.10s user 68.41s system 97% cpu 6:58.65 total
./run-tests.py -j8 *.t  599.51s user 100.63s system 599% cpu 1:56.84 total
./run-tests.py -j8 *.t  598.48s user 99.06s system 593% cpu 1:57.46 total
./run-tests.py -j8 *.t  597.27s user 100.19s system 592% cpu 1:57.70 total

After the patch:

1000 loops, best of 3: 5.92 msec per loop
1000 loops, best of 3: 5.91 msec per loop
1000 loops, best of 3: 6.01 msec per loop

./run-tests.py test-run-tests.t  1.63s user 0.31s system 66% cpu 2.936 total
./run-tests.py test-run-tests.t  1.68s user 0.26s system 66% cpu 2.911 total
./run-tests.py test-run-tests.t  1.60s user 0.30s system 65% cpu 2.905 total
./run-tests.py test-run-tests.t  1.56s user 0.33s system 64% cpu 2.931 total
./run-tests.py test-run-tests.t  1.58s user 0.28s system 64% cpu 2.904 total
./run-tests.py test-run-tests.t  1.63s user 0.29s system 65% cpu 2.949 total
./run-tests.py test-run-tests.t  1.65s user 0.28s system 66% cpu 2.921 total
./run-tests.py test-run-tests.t  1.66s user 0.26s system 65% cpu 2.929 total
./run-tests.py test-run-tests.t  1.61s user 0.39s system 68% cpu 2.931 total
./run-tests.py test-run-tests.t  1.62s user 0.28s system 65% cpu 2.911 total

./run-tests.py *.t  341.98s user 67.63s system 97% cpu 6:59.64 total
./run-tests.py *.t  337.73s user 68.23s system 97% cpu 6:56.77 total
./run-tests.py -j8 *.t  597.92s user 100.23s system 594% cpu 1:57.49 total
./run-tests.py -j8 *.t  600.01s user 99.37s system 591% cpu 1:58.19 total
./run-tests.py -j8 *.t  597.10s user 100.43s system 593% cpu 1:57.52 total

> I think there should also be a simple test demonstrating the use of the
> (plain) modifier. Something like:
>
>  $ echo "here is how (re) works"
>  here is how (re) works
>  $ echo "put ' (re)' at the end of a line like this to match as a regular
> expression:"
>  .* (re)
>  $ echo "you can validate lines that are supposed to end in (re) with
> (plain)"
>  you can validate lines that are supposed to end in (re) with (plain)
>  $ echo "like this (re)"
>  like this (re) (plain)

Good idea, I'll add that to the patch.


More information about the Mercurial-devel mailing list