David Carr avatar David Carr committed 6cc9929

tests: avoid changing the current directory

Mercurial allows specifying which repository to use via the -R/--repository
option. Git allows a similar function using the --git-dir option. By using
these options, in many cases we can avoid checking the current directory.
This makes tests easier to understand, as you don't need to remember which
directory you're in to understand what's going on. It also makes tests easier
to write, as you don't need to remember to cd out of a directory when you're
done doing things there.

Thanks to Felipe Contreras for the patch which this was based on.

Comments (0)

Files changed (17)

tests/test-clone.t

   $ hg clone -r alpha gitrepo hgrepo-a | grep -v '^updating'
   importing git objects into hg
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ cd hgrepo-a
-  $ hg log --graph | egrep -v ': *(beta|master)'
+  $ hg -R hgrepo-a log --graph | egrep -v ': *(beta|master)'
   @  changeset:   0:3442585be8a6
      tag:         alpha
      tag:         default/master
      date:        Mon Jan 01 00:00:10 2007 +0000
      summary:     add alpha
   
-
-  $ cd ..
   $ echo % clone a branch
   % clone a branch
   $ hg clone -r beta gitrepo hgrepo-b | grep -v '^updating'
   importing git objects into hg
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ cd hgrepo-b
-  $ hg log --graph | egrep -v ': *(beta|master)'
+  $ hg -R hgrepo-b log --graph | egrep -v ': *(beta|master)'
   @  changeset:   1:7bcd915dc873
   |  tag:         default/beta
   |  tag:         tip
      date:        Mon Jan 01 00:00:10 2007 +0000
      summary:     add alpha
   
-
-
-  $ cd ..

tests/test-conflict-1.t

   $ hg clone gitrepo hgrepo2 | grep -v '^updating'
   importing git objects into hg
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ cd hgrepo2
   $ echo % expect the same revision ids as above
   % expect the same revision ids as above
-  $ hg log --graph --style compact | sed 's/\[.*\]//g'
+  $ hg -R hgrepo2 log --graph --style compact | sed 's/\[.*\]//g'
   @    3:1,2   6c53bc0f062f   1970-01-01 00:00 +0000   test
   |\     merge to C
   | |
   o  0   5d1a6b64f9d0   1970-01-01 00:00 +0000   test
        origin
   
-
-  $ cd ..

tests/test-conflict-2.t

   $ hg clone gitrepo hgrepo2 | grep -v '^updating'
   importing git objects into hg
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ cd hgrepo2
   $ echo % expect the same revision ids as above
   % expect the same revision ids as above
-  $ hg log --graph --style compact | sed 's/\[.*\]//g'
+  $ hg -R hgrepo2 log --graph --style compact | sed 's/\[.*\]//g'
   @    3:1,2   120385945d08   1970-01-01 00:00 +0000   test
   |\     merge to B
   | |
   o  0   5d1a6b64f9d0   1970-01-01 00:00 +0000   test
        origin
   
-
-  $ cd ..

tests/test-convergedmerge.t

   $ hg clone gitrepo hgrepo2 | grep -v '^updating'
   importing git objects into hg
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ cd hgrepo2
   $ echo % expect the same revision ids as above
   % expect the same revision ids as above
-  $ hg log --graph --style compact | sed 's/\[.*\]//g'
+  $ hg -R hgrepo2 log --graph --style compact | sed 's/\[.*\]//g'
   @    4:1,3   eaa21d002113   1970-01-01 00:00 +0000   test
   |\     merge
   | |
   o  0   5d1a6b64f9d0   1970-01-01 00:00 +0000   test
        origin
   
-
-  $ cd ..

tests/test-empty-working-tree.t

   $ hg push ../gitrepo2
   pushing to ../gitrepo2
   searching for changes
-
-  $ cd ../gitrepo2
-  $ git log --pretty=medium
+  $ cd ..
+  $ git --git-dir=gitrepo2 log --pretty=medium
   commit 678256865a8c85ae925bf834369264193c88f8de
   Author: test <test@example.org>
   Date:   Mon Jan 1 00:00:00 2007 +0000
   
       empty
-
-  $ cd ..

tests/test-encoding.t

   pushing to ../gitrepo2
   searching for changes
 
-  $ cd ../gitrepo2
-  $ git log --pretty=medium
+  $ cd ..
+  $ git --git-dir=gitrepo2 log --pretty=medium
   commit da0edb01d4f3d1abf08b1be298379b0b2960e680
   Author: t\xe9st \xe8nc\xf6d\xeeng <test@example.org> (esc)
   Date:   Mon Jan 1 00:00:13 2007 +0000
   Date:   Mon Jan 1 00:00:10 2007 +0000
   
       add älphà
-
-  $ cd ..

tests/test-file-removal.t

   pushing to ../gitrepo2
   searching for changes
 
-  $ cd ../gitrepo2
-  $ git log --pretty=medium
+  $ cd ..
+  $ git --git-dir=gitrepo2 log --pretty=medium
   commit b991de8952c482a7cd51162674ffff8474862218
   Author: test <test@example.org>
   Date:   Mon Jan 1 00:00:14 2007 +0000
   Date:   Mon Jan 1 00:00:10 2007 +0000
   
       add alpha
-
-  $ cd ..

tests/test-git-clone.t

   $ hg clone gitrepo hgrepo | grep -v '^updating'
   importing git objects into hg
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ cd hgrepo
-  $ hg log --graph  | grep -v ': *master'
+  $ hg -R hgrepo log --graph  | grep -v ': *master'
   @  changeset:   1:7bcd915dc873
   |  tag:         default/master
   |  tag:         tip
 
   $ echo % we should have some bookmarks
   % we should have some bookmarks
-  $ hg book
+  $ hg -R hgrepo book
    * master                    1:7bcd915dc873

tests/test-git-submodules.t

   $ hg clone gitrepo2 hgrepo | grep -v '^updating'
   importing git objects into hg
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ cd hgrepo
-  $ hg log --graph  | grep -v ': *master'
+  $ hg -R hgrepo log --graph  | grep -v ': *master'
   @  changeset:   2:76fda365fbbb
   |  tag:         default/master
   |  tag:         tip
 
   $ echo % we should have some bookmarks
   % we should have some bookmarks
-  $ hg book
+  $ hg -R hgrepo book
    * master                    2:76fda365fbbb

tests/test-hg-author.t

   $ hg clone gitrepo hgrepo2 | grep -v '^updating'
   importing git objects into hg
   8 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ cd hgrepo2
-  $ hg log --graph | egrep -v ': *(not-master|master)'
+  $ hg -R hgrepo2 log --graph | egrep -v ': *(not-master|master)'
   @  changeset:   8:efec0270e295
   |  tag:         default/master
   |  tag:         tip
      date:        Mon Jan 01 00:00:10 2007 +0000
      summary:     add alpha
   
-
-  $ cd ..
-  $ cd gitrepo
-  $ git log --pretty=medium master
+  $ git --git-dir=gitrepo/.git log --pretty=medium master
   commit 1e03e913eca571b86ee06d3c1ddd795dde9ca917
   Author: test ?test@example.com <test ?test@example.com>
   Date:   Mon Jan 1 00:00:18 2007 +0000
   Date:   Mon Jan 1 00:00:10 2007 +0000
   
       add alpha
-
-  $ cd ..

tests/test-hg-branch.t

   $ hg clone gitrepo hgrepo2 | grep -v '^updating'
   importing git objects into hg
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ cd hgrepo2
-  $ hg log --graph | $filterhash | egrep -v ': *(not-master|master)'
+  $ hg -R hgrepo2 log --graph | $filterhash | egrep -v ': *(not-master|master)'
   o  changeset:   2:05aed681ccb3
   |  branch:      gamma
   |  tag:         default/master
      date:        Mon Jan 01 00:00:10 2007 +0000
      summary:     add alpha
   
-
-  $ cd ..

tests/test-hg-tags.t

   $ hg clone gitrepo hgrepo2 | grep -v '^updating'
   importing git objects into hg
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ cd hgrepo2
-  $ hg log --graph | egrep -v ': *(not-master|master)'
+  $ hg -R hgrepo2 log --graph | egrep -v ': *(not-master|master)'
   @  changeset:   1:d529e9229f6d
   |  tag:         default/master
   |  tag:         tip
 
   $ echo % the tag should be in .hgtags
   % the tag should be in .hgtags
-  $ cat .hgtags
+  $ cat hgrepo2/.hgtags
   3442585be8a60c6cd476bbc4e45755339f2a23ef alpha
-
-  $ cd ..

tests/test-incoming.t

   importing git objects into hg
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
-  $ cd hgrepo
-  $ hg incoming | grep -v 'no changes found' | grep -v 'bookmark:'
+  $ hg -R hgrepo incoming | grep -v 'no changes found' | grep -v 'bookmark:'
   comparing with $TESTTMP/gitrepo
 
-  $ cd ../gitrepo
+  $ cd gitrepo
   $ echo beta > beta
   $ git add beta
   $ fn_git_commit -m 'add beta'
+  $ cd ..
 
-  $ cd ../hgrepo
-  $ hg incoming | grep -v 'no changes found' | grep -v 'bookmark:'
+  $ hg -R hgrepo incoming | grep -v 'no changes found' | grep -v 'bookmark:'
   comparing with $TESTTMP/gitrepo
   changeset:   1:9497a4ee62e1
   user:        test <test@example.org>
   summary:     add beta
   
 
-  $ cd ../gitrepo
+  $ cd gitrepo
   $ git checkout -b b1 HEAD^
   Switched to a new branch 'b1'
   $ mkdir d
   $ echo gamma 2 >> d/gamma
   $ git add d/gamma
   $ fn_git_commit -m'add d/gamma line 2'
-
   $ cd ../hgrepo
   $ hg incoming -p | grep -v 'no changes found' | grep -v 'bookmark:'
   comparing with $TESTTMP/gitrepo

tests/test-merge.t

   searching for changes
 
   $ cd ..
-  $ cd gitrepo2
   $ echo % git log in repo pushed from hg
   % git log in repo pushed from hg
-  $ git log --pretty=medium master | sed 's/\.\.\.//g'
+  $ git --git-dir=gitrepo2 log --pretty=medium master | sed 's/\.\.\.//g'
   commit 5806851511aaf3bfe813ae3a86c5027165fa9b96
   Merge: e5023f9 9497a4e
   Author: test <test@example.org>
   Date:   Mon Jan 1 00:00:10 2007 +0000
   
       add alpha
-  $ git log --pretty=medium beta | sed 's/\.\.\.//g'
+  $ git --git-dir=gitrepo2 log --pretty=medium beta | sed 's/\.\.\.//g'
   commit 9497a4ee62e16ee641860d7677cdb2589ea15554
   Author: test <test@example.org>
   Date:   Mon Jan 1 00:00:11 2007 +0000
   Date:   Mon Jan 1 00:00:10 2007 +0000
   
       add alpha
-
-  $ cd ..

tests/test-octopus.t

   $ hg push ../gitrepo2
   pushing to ../gitrepo2
   searching for changes
+  $ cd ..
 
-  $ cd ../gitrepo2
-  $ git log --pretty=medium | sed s/\\.\\.\\.//g
+  $ git --git-dir=gitrepo2 log --pretty=medium | sed s/\\.\\.\\.//g
   commit f0c7ec180419a130636d0c333fc34c1462cab4b5
   Merge: d8e22dd 9497a4e e5023f9
   Author: test <test@example.org>
   Date:   Mon Jan 1 00:00:10 2007 +0000
   
       add alpha
-
-  $ cd ..

tests/test-pull-after-strip.t

   $ hg clone -r alpha gitrepo hgrepo-a | grep -v '^updating'
   importing git objects into hg
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ cd hgrepo-a
-  $ hg log --graph | egrep -v ': *(beta|master)'
+  $ hg -R hgrepo-a log --graph | egrep -v ': *(beta|master)'
   @  changeset:   0:3442585be8a6
      tag:         alpha
      tag:         default/master
      date:        Mon Jan 01 00:00:10 2007 +0000
      summary:     add alpha
   
-
-  $ cd ..
   $ echo % clone a branch
   % clone a branch
   $ hg clone -r beta gitrepo hgrepo-b | grep -v '^updating'
   importing git objects into hg
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ cd hgrepo-b
-  $ hg log --graph | egrep -v ': *(beta|master)'
+  $ hg -R hgrepo-b log --graph | egrep -v ': *(beta|master)'
   @  changeset:   1:7bcd915dc873
   |  tag:         default/beta
   |  tag:         tip
      date:        Mon Jan 01 00:00:10 2007 +0000
      summary:     add alpha
   
-  $ cd ..
-
   $ cd gitrepo
   $ echo beta line 2 >> beta
   $ git add beta

tests/test-tree-decomposition.t

   $ hg push ../gitrepo2
   pushing to ../gitrepo2
   searching for changes
+  $ cd ..
 
-  $ cd ../gitrepo2
-  $ git log --pretty=medium
+  $ git --git-dir=gitrepo2 log --pretty=medium
   commit 6e0dbd8cd92ed4823c69cb48d8a2b81f904e6e69
   Author: test <test@example.org>
   Date:   Mon Jan 1 00:00:12 2007 +0000
   Date:   Mon Jan 1 00:00:10 2007 +0000
   
       initial
-
-  $ cd ..
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.