# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 2017-06-21 08:12:31
# Node ID 573baab2a7972a4ff8afa28d7792056727965c56
# Parent  02bca6dc5f417f499ae750d5aa4d7fb75a5d4a97

run-tests: fix -i when "#testcases" is used in .t test

The "#testcases" feature introduced by 7340465bd788 has issues with "-i"
because "-i" uses "test.name.endswith('.t')" to test if a test is .t or not.

test.name could now be something like "test-foo.t (caseA)" so the above
endswith test is no longer valid.

This patch changes the test to use "self.path" which won't have the issue.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1605,7 +1605,7 @@ class TestResult(unittest._TextTestResul
                     self.stream.write('Accept this change? [n] ')
                     answer = sys.stdin.readline().strip()
                     if answer.lower() in ('y', 'yes'):
-                        if test.name.endswith('.t'):
+                        if test.path.endswith(b'.t'):
                             rename(test.errpath, test.path)
                         else:
                             rename(test.errpath, '%s.out' % test.path)
diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t
--- a/tests/test-run-tests.t
+++ b/tests/test-run-tests.t
@@ -668,6 +668,58 @@ Race condition - test file was modified 
 
   $ rm test-race.t
 
+When "#testcases" is used in .t files
+
+  $ cat >> test-cases.t <<EOF
+  > #testcases a b
+  > #if a
+  >   $ echo 1
+  > #endif
+  > #if b
+  >   $ echo 2
+  > #endif
+  > EOF
+
+  $ cat <<EOF | rt -i test-cases.t 2>&1
+  > y
+  > y
+  > EOF
+  
+  --- $TESTTMP/test-cases.t
+  +++ $TESTTMP/test-cases.t.a.err
+  @@ -1,6 +1,7 @@
+   #testcases a b
+   #if a
+     $ echo 1
+  +  1
+   #endif
+   #if b
+     $ echo 2
+  Accept this change? [n] .
+  --- $TESTTMP/test-cases.t
+  +++ $TESTTMP/test-cases.t.b.err
+  @@ -5,4 +5,5 @@
+   #endif
+   #if b
+     $ echo 2
+  +  2
+   #endif
+  Accept this change? [n] .
+  # Ran 2 tests, 0 skipped, 0 failed.
+
+  $ cat test-cases.t
+  #testcases a b
+  #if a
+    $ echo 1
+    1
+  #endif
+  #if b
+    $ echo 2
+    2
+  #endif
+
+  $ rm test-cases.t
+
 (reinstall)
   $ mv backup test-failure.t