Commits

Douglas Creager committed b765026

Use relative paths in patch command

GNU patch 2.7 no longer accepts absolute paths in the diff text passed into
patch. cram now uses bare filenames in the diffs that it generates, and runs
the patch command from within the directory containing the test script.

  • Participants
  • Parent commits 48d46b6

Comments (0)

Files changed (2)

             postout.append(indent + line)
     postout += after.pop(pos, [])
 
-    diff = unified_diff(refout, postout, abspath, abspath + '.err')
+    diffpath = os.path.basename(abspath)
+    diff = unified_diff(refout, postout, diffpath, diffpath + '.err')
     for firstline in diff:
         return refout, postout, itertools.chain([firstline], diff)
     return refout, postout, []
         sys.stdout.write(msg)
         sys.stdout.flush()
 
-def patch(cmd, diff):
+def patch(cmd, diff, path):
     """Run echo [lines from diff] | cmd -p0"""
     p = subprocess.Popen([cmd, '-p0'], bufsize=-1, stdin=subprocess.PIPE,
                          universal_newlines=True,
                          preexec_fn=makeresetsigpipe(),
+                         cwd=path,
                          close_fds=os.name == 'posix')
     p.communicate(''.join(diff))
     return p.returncode == 0
                         log(line)
                     if (patchcmd and
                         prompt('Accept this change?', 'yN', answer) == 'y'):
-                        if patch(patchcmd, diff):
+                        if patch(patchcmd, diff, os.path.dirname(abspath)):
                             log(None, '%s: merged output\n' % path, verbose)
                             os.remove(errpath)
                         else:
     for p in os.environ['PATH'].split(os.pathsep):
         path = os.path.join(p, cmd)
         if os.path.isfile(path) and os.access(path, os.X_OK):
-            return path
+            return os.path.abspath(path)
     return None
 
 def expandpath(path):
 
   $ cram -n -i examples/fail.t
   !
-  --- */examples/fail.t (glob)
-  +++ */examples/fail.t.err (glob)
+  --- fail.t
+  +++ fail.t.err
   @@ -1,18 +1,18 @@
    Output needing escaping:
    
   $ cp examples/fail.t examples/fail.t.orig
   $ cram -y -i examples/fail.t
   !
-  --- */examples/fail.t (glob)
-  +++ */examples/fail.t.err (glob)
+  --- fail.t
+  +++ fail.t.err
   @@ -1,18 +1,18 @@
    Output needing escaping:
    
      
      \d (re)
   Accept this change? [yN] y
-  patching file */fail.t (glob)
+  patching file fail.t
   
   # Ran 1 tests, 0 skipped, 1 failed.
   [1]
 
   $ printf 'bad\nn\n' | cram -v -i examples/fail.t
   examples/fail.t: failed
-  --- */examples/fail.t (glob)
-  +++ */examples/fail.t.err (glob)
+  --- fail.t
+  +++ fail.t.err
   @@ -1,18 +1,18 @@
    Output needing escaping:
    
   .*\b7a23dfa85773c77648f619ad0f9df554\b.* (re)
   $ printf 'bad\n\n' | cram -v -i examples/fail.t
   examples/fail.t: failed
-  --- */examples/fail.t (glob)
-  +++ */examples/fail.t.err (glob)
+  --- fail.t
+  +++ fail.t.err
   @@ -1,18 +1,18 @@
    Output needing escaping:
    
   $ cp examples/fail.t examples/fail.t.orig
   $ printf 'bad\ny\n' | cram -v -i examples/fail.t
   examples/fail.t: failed
-  --- */examples/fail.t (glob)
-  +++ */examples/fail.t.err (glob)
+  --- fail.t
+  +++ fail.t.err
   @@ -1,18 +1,18 @@
    Output needing escaping:
    
   +  foo
      
      \d (re)
-  Accept this change? [yN] Accept this change? [yN] patching file */fail.t (glob)
+  Accept this change? [yN] Accept this change? [yN] patching file fail.t
   examples/fail.t: merged output
   # Ran 1 tests, 0 skipped, 1 failed.
   [1]
   $ chmod +x patch
   $ PATH=. cram -y -i examples/fail.t
   !
-  --- */examples/fail.t (glob)
-  +++ */examples/fail.t.err (glob)
+  --- fail.t
+  +++ fail.t.err
   @@ -1,18 +1,18 @@
    Output needing escaping:
    
   $ echo "  $ echo 1" > fixed.t
   $ cram fixed.t
   !
-  --- */fixed.t (glob)
-  +++ */fixed.t.err (glob)
+  --- fixed.t
+  +++ fixed.t.err
   @@ -1,1 +1,2 @@
      $ echo 1
   +  1
   $ GREP_OPTIONS=foo; export GREP_OPTIONS
   $ cram -E examples/env.t
   !
-  \-\-\- .*/examples/env\.t\s* (re)
-  \+\+\+ .*/examples/env\.t\.err\s* (re)
+  \-\-\- env\.t\s* (re)
+  \+\+\+ env\.t\.err\s* (re)
   @@ -7,13 +7,13 @@
      $ echo "$LANGUAGE"
      C