vim-update-bundles 0.6 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/CHANGES +10 -0
  2. data/README.md +52 -41
  3. data/Rakefile +23 -0
  4. data/test.rb +394 -157
  5. data/vim-update-bundles +192 -127
  6. metadata +6 -6
data/CHANGES CHANGED
@@ -1,3 +1,13 @@
1
+ 0.8 15 Jul 2011
2
+ - Support Vundle directives so both tools can read the same .vimrc.
3
+ - When pull fails, remove and re-clone the repo instead of aborting.
4
+ - vim-update-bundles no longer symlinks .vim and .vimrc into $HOME.
5
+ - Remove the dotfile_path option, it's not necessary anymore.
6
+ - Finding .vim and .vimrc has been simplified, see the readme.
7
+ - No longer trim 'vim-' from the front of repo names in ~/.vim/bundle.
8
+ - We now check for duplicate and conflicting Bundle entries.
9
+ - All known tests written, all todos fixed. 1.0 is close.
10
+
1
11
  0.6 29 Jun 2011
2
12
  - Added doc/bundle-log.txt. :help bundle-log to see it.
3
13
  - Added --no-updates option to make adding/deleting bundles faster.
data/README.md CHANGED
@@ -7,17 +7,22 @@ Use Pathogen and Git to manage your Vim plugins.
7
7
 
8
8
  ## Description
9
9
 
10
- To install a plugin, put lines like this in your ~/.vimrc:
10
+ To install plugins, put lines like this in your ~/.vimrc:
11
11
 
12
- " Bundle: jQuery # https://github.com/vim-scripts/jQuery
13
- " Bundle: scrooloose/nerdtree # https://github.com/scrooloose/nerdtree
14
- " Bundle: https://github.com/scrooloose/nerdtree.git # Full URL to the repository.
12
+ " Bundle: jQuery # https://github.com/vim-scripts/jQuery
13
+ " Bundle: scrooloose/nerdtree # https://github.com/scrooloose/nerdtree
14
+ " Bundle: git://git.wincent.com/command-t.git # Full URL to the repo to clone
15
15
 
16
- Now, run `./vim-update-bundles`. Your plugins are installed and ready for use.
16
+ When you run `./vim-update-bundles`, your plugins will be installed and ready for use.
17
17
 
18
18
  Type `:help bundles` from within Vim to show the list of plugins that you have installed.
19
19
  Hit Control-] on the bundle's name to jump to its documentation.
20
- Also make sure to look at the bundle-log.
20
+ Also look at `:help bundle-log`.
21
+
22
+ It works with [~/.dotfiles](http://github.com/ryanb/dotfiles) and Git submodules.
23
+
24
+ If you're not already using Vim, just run `./vim-update-bundles` and a full environment
25
+ will be set up for you.
21
26
 
22
27
 
23
28
  ## Installation
@@ -31,14 +36,10 @@ One of:
31
36
 
32
37
  ## Usage
33
38
 
34
- $ ./vim-update-bundles --help
35
-
36
- If you're not already using Vim, vim-update-bundles will set up a typical vim environment.
37
- Edit your ~/.vimrc and run vim-update-bundles whenever you want changes to take effect.
38
-
39
- vim-update-bundles will use ~/.dotfiles if it exists; so, it works seamlessly
40
- with <http://github.com/ryanb/dotfiles> and friends. It also supports Git
41
- submodules (see the configuration section below).
39
+ Just run `./vim-update-bundles` to install and remove plugins to match
40
+ the ones named in your ~/.vimrc.
41
+ If you're not already using Vim, vim-update-bundles will also install
42
+ Pathogen, a sample .vimrc, and get everything ready to go.
42
43
 
43
44
  * _-n -\-no-updates_ Adds and deletes bundles but doesn't update them.
44
45
  This prevents vim-update-bundles from laboriously scrubbing through every
@@ -49,11 +50,19 @@ submodules (see the configuration section below).
49
50
  submodules before running vim-update bundles.
50
51
 
51
52
  * _-v -\-verbose_ prints more information about what's happening.
53
+ Pass multiple -v -v -v for more verbosity.
54
+
55
+ * _-\-vimdir-path=path_ specifies the .vim directory that will contain
56
+ your autoload and bundles.
57
+
58
+ * _\-vimrc-path_ specifies the location of your ~/.vimrc file.
59
+
60
+ * _-\-help_ prints usage information.
52
61
 
53
62
 
54
63
  ## Specifying Plugins
55
64
 
56
- vim-update-bundles reads the plugins you want installed from your ~/.vimrc.
65
+ vim-update-bundles reads the plugins you want installed from comments in your ~/.vimrc.
57
66
  Here are the directives it recognizes:
58
67
 
59
68
  #### Bundle:
@@ -90,49 +99,51 @@ ignore, mark them as static.
90
99
  " Static: my-plugin
91
100
 
92
101
 
93
- ## Configuration File
102
+ ### Vundle
94
103
 
95
- All configuration options can be passed on the command line or placed in ~/.vim-update-bundles.conf.
96
- Putting "submodules=1" in the config file is the same as passing -s or --submodules on the command line.
97
- Blank lines and comments starting with '#' are ignored.
104
+ vim-update-bundles also supports Vundle-style directives. This allows you to use
105
+ either tool to manage your bundles, whichever is more convenient at the time.
106
+ This is brand new so problems are not unexpected.
98
107
 
99
- String interpolation is performed on all values. First configuration settings
100
- are tried then environment variables. For instance, this would expand to
101
- "/home/_username_/.dotfiles/_username_/vim":
102
108
 
103
- vimdir_path = $dotfiles_path/$USERNAME/vim
109
+ ## Configuration File
104
110
 
111
+ All configuration options can be passed on the command line or placed in `~/.vim-update-bundles.conf`.
112
+ Putting `submodules = 1` in the config file is the same as passing --submodules on the command line.
105
113
 
106
- ## Location of .vim and .vimrc
114
+ Blank lines and comments starting with # are ignored.
107
115
 
108
- Unless you have a custom dotfiles configuration, you can probably skip this
109
- section.
116
+ String interpolation is performed on all values.
117
+ First configuration settings are tried, then environment variables.
118
+ Here's an example vim-update-bundles.conf file:
110
119
 
111
- vim-update-bundles tries hard to figure out where you want to store your .vim
112
- directory and .vimrc file. It first looks for a dotfiles directory (~/.dotfiles
113
- or specified by dotfiles\_path).
120
+ # use shared vim environment
121
+ vimdir_path = $HOME/vim/$USERNAME
122
+ vimrc_path = $vimdir_path/vimrc
114
123
 
115
- * dotfiles\_path = $HOME/.dotfiles
116
124
 
117
- If dotfiles\_path exists, then vim-update-bundles will use it; otherwise, it
118
- will use the default location:
125
+ ## Location of .vim and .vimrc
126
+
127
+ vim-update-bundles will use ~/.vim and ~/.vimrc if they exist.
128
+ Since this is also what Vim uses, most people can stop reading here.
119
129
 
120
- * vimdir\_path = $dotfiles\_path/vim
121
- * vimdir\_path = $HOME/.vim
130
+ If ~/.dotfiles exists, vim-update-bundles will look for .dotfiles/vim and .dotfiles/vimrc.
122
131
 
123
- Finally, these are the places that vim-update-bundles will look for a .vimrc:
132
+ If your dotfiles are in a custom place, you can specify --vimdir-path and --vimrc-path
133
+ on the command line or in vim-update-bundles.conf.
124
134
 
125
- * vimrc\_path = $dotfiles\_path/vim/vimrc
126
- * vimrc\_path = $dotfiles\_path/vimrc
127
- * vimrc\_path = $HOME/.vim/vimrc
128
- * vimrc\_path = $HOME/.vimrc
135
+ If vim-update-bundles still can't find a Vim environment, it will create one for you.
136
+ It creates the ~/.vim directory and gives you a default ~/.vimrc, downloads and installs Pathogen,
137
+ and leaves everything ready to roll.
129
138
 
130
- It always updates the ~/.vim and ~/.vimrc symlinks; so, Vim can find the correct
131
- files.
139
+ If you're unsure which vimdir_path and vimrc_path are being used,
140
+ `vim-update-bundles --verbose` will tell you.
132
141
 
133
142
 
134
143
  ## Authors
135
144
 
145
+ This software is released under the [MIT License](http://en.wikipedia.org/wiki/Mit_license).
146
+
136
147
  * [Scott Bronson](http://github.com/bronson)
137
148
  * [Sorin Ionescu](http://github.com/sorin-ionescu)
138
149
  * [steeef](http://github.com/steeef)
data/Rakefile CHANGED
@@ -1,5 +1,28 @@
1
+ require 'rake/clean'
2
+
3
+ coverage_file = "aggregate.rcov"
4
+ CLEAN.include('vim-update-bundles-*.gem', 'coverage', coverage_file)
5
+
1
6
  task :default => [:test]
2
7
 
3
8
  task :test do
4
9
  ruby "test.rb"
5
10
  end
11
+
12
+ task :rcov do
13
+ system "rm -rf coverage #{coverage_file}"
14
+ ENV['RCOV'] = coverage_file
15
+ ruby "test.rb"
16
+ system "rcov -x analyzer --aggregate #{coverage_file} -t"
17
+ puts 'Open coverage/index.html to see rcov results.'
18
+ end
19
+
20
+ task :build do
21
+ system 'gem build vim-update-bundles.gemspec'
22
+ end
23
+
24
+ task :release do
25
+ $load_only = true
26
+ Kernel.load 'vim-update-bundles'
27
+ system "gem push vim-update-bundles-#{Version}.gem"
28
+ end
data/test.rb CHANGED
@@ -1,16 +1,14 @@
1
+ require 'test/unit'
1
2
  require 'tempfile'
2
3
  require 'tmpdir'
3
- require 'test/unit'
4
+ require 'fileutils'
4
5
 
5
6
  # You can specify where the tests will be run instead of mktmpdir's default:
6
7
  # TESTDIR=/ramdisk/test ruby test.rb
7
8
  # You can also tell the tester to preserve the test directory after running:
8
- # PRESERVE=1 ruby test.rb -n test_multiple_removes
9
- #
10
- # TODO: test when .vimrc and .vim/vimrc both exist, the former is preferred
11
- #
12
- # We shell to the executable; so, this isn't actually unit testing.
13
- # Has anyone written a functional test framework for executables?
9
+ # PRESERVE=1 VERBOSE=1 ruby test.rb -n test_multiple_removes
10
+ # VERBOSE=1 causes the vim-update-bundles commands to be printed.
11
+ # TRACE=1 forces vim-update-bundles to include a stack trace in any errors.
14
12
 
15
13
 
16
14
  class TestUpdater < Test::Unit::TestCase
@@ -31,42 +29,43 @@ class TestUpdater < Test::Unit::TestCase
31
29
  def prepare_test_trampoline tmpdir, block
32
30
  create_mock_files tmpdir
33
31
  Dir.mkdir "#{tmpdir}/home"
34
- ENV['HOME']="#{tmpdir}/home"
35
- ENV['TESTING']='1'
36
32
  block.call "#{tmpdir}/home"
37
33
  end
38
34
 
39
- def write_file base, path, contents
40
- File.open(File.join(base, path), 'w') { |f| f.write contents }
35
+ def write_file path, contents
36
+ File.open(path, 'w') { |f| f.write contents }
41
37
  end
42
38
 
43
39
  def create_mock_files tmpdir
44
40
  # Creates mock files to download (it saves on bandwidth and test time).
45
- write_file tmpdir, "pathogen", "\" PATHOGEN SCRIPT"
46
- write_file tmpdir, "starter-vimrc", "\" STARTER VIMRC"
41
+ write_file "#{tmpdir}/pathogen", "\" PATHOGEN SCRIPT"
42
+ write_file "#{tmpdir}/starter-vimrc", "\" STARTER VIMRC"
47
43
  @starter_urls = "starter_url='#{tmpdir}/starter-vimrc' pathogen_url='#{tmpdir}/pathogen'"
48
44
  end
49
45
 
50
- def create_mock_repo name
46
+ def create_mock_repo name, author=nil
51
47
  Dir.mkdir name
52
48
  Dir.chdir name do
53
49
  `git init`
54
- write_file name, "first", "first"
50
+ write_file "#{name}/first", "first"
55
51
  `git add first`
56
- `git commit -q -m first`
52
+
53
+ command = "git commit -q -m first"
54
+ command = "sh -c 'GIT_AUTHOR_NAME='\\''#{author}'\\'' #{command}'" if author
55
+ `#{command}`
57
56
  end
58
57
  end
59
58
 
60
- def update_mock_repo dir, name
59
+ def update_mock_repo dir, name="second", contents=nil
61
60
  Dir.chdir dir do
62
- write_file dir, name, name
61
+ write_file "#{dir}/#{name}", contents || name
63
62
  `git add '#{name}'`
64
63
  `git commit -q -m '#{name}'`
65
64
  end
66
65
  end
67
66
 
68
- def update_mock_repo_tagged dir, name, tag
69
- update_mock_repo dir, name
67
+ def update_mock_repo_tagged dir, name, tag, contents=nil
68
+ update_mock_repo dir, name, contents
70
69
  Dir.chdir(dir) { `git tag -a #{tag} -m 'tag #{tag}'` }
71
70
  end
72
71
 
@@ -83,47 +82,37 @@ class TestUpdater < Test::Unit::TestCase
83
82
  end
84
83
  end
85
84
 
86
- def check_tree base, vimdir='.vim', vimrc='.vimrc'
87
- # Makes sure .vim, .vimrc, and the symlinks are set up correctly.
88
85
 
89
- if vimdir == '.vim'
90
- # No symlinks are needed.
91
- assert_test ?d, "#{base}/.vim"
92
- else
93
- # it appears Rubinius has a bug https://github.com/rubinius/rubinius/issues/1057
94
- #assert_test ?l, "#{base}/.vim"
95
- assert_equal File.readlink("#{base}/.vim"), "#{base}/#{vimdir}"
96
- end
97
-
98
- if vimrc == '.vimrc'
99
- assert_test ?f, "#{base}/.vimrc"
100
- else
101
- # it appears Rubinius has a bug https://github.com/rubinius/rubinius/issues/1057
102
- #assert_test ?l, "#{base}/.vimrc"
103
- assert_equal File.readlink("#{base}/.vimrc"), "#{base}/#{vimrc}"
104
- end
105
-
106
- assert_test ?f, "#{base}/#{vimdir}/autoload/pathogen.vim"
86
+ def check_tree base, vimdir='.vim', vimrc='.vimrc'
107
87
  assert_test ?d, "#{base}/#{vimdir}"
88
+ assert_test ?f, "#{base}/#{vimdir}/autoload/pathogen.vim"
108
89
  assert_test ?f, "#{base}/#{vimrc}"
109
90
  end
110
91
 
111
- def run_vim_update_bundles *args
112
- `./vim-update-bundles #{@starter_urls} #{args.join(' ')}`
113
- end
114
92
 
93
+ # runs the command under test and check the exit status
94
+ def vim_update_bundles tmpdir, *args
95
+ options = { :acceptable_exit_codes => [0], :stderr => nil }
96
+ options.merge!(args.pop) if args.last.kind_of?(Hash)
115
97
 
116
- # runs the command under test expecting there will not be an error
117
- def vim_update_bundles *args
118
- result = run_vim_update_bundles *args
119
- raise "vim-update-bundles returned #{$?.exitstatus} RESULT: <<\n#{result}>>" unless $?.exitstatus == 0
120
- result
121
- end
98
+ runner = prearg = ''
99
+ if ENV['RCOV']
100
+ # run 'rake rcov' to run the coverage of all tests
101
+ runner = "rcov -x analyzer --aggregate '#{ENV['RCOV']}' --no-html "
102
+ prearg = ' -- '
103
+ end
122
104
 
123
- # runs the command under test expecting that there WILL be an error
124
- def vim_update_bundles__expect_error *args
125
- result = run_vim_update_bundles *args + ['2>&1']
126
- raise "vim-update-bundles returned #{$?.exitstatus} RESULT: <<\n#{result}>>" unless $?.exitstatus != 0
105
+ redirects = ' 2>/dev/null' if options[:stderr] == :suppress
106
+ redirects = ' 2>&1' if options[:stderr] == :merge
107
+ command = "HOME='#{tmpdir}' TESTING=1 #{runner} ./vim-update-bundles #{prearg} #{@starter_urls} #{args.join(' ')} #{redirects}"
108
+ STDERR.puts "Running: #{command}" if ENV['VERBOSE']
109
+ result = `#{command}`
110
+
111
+ unless options[:acceptable_exit_codes].include?($?.exitstatus)
112
+ raise "vim-update-bundles returned #{$?.exitstatus} " +
113
+ "instead of #{options[:acceptable_exit_codes].inspect} " +
114
+ "RESULT: <<\n#{result}>>"
115
+ end
127
116
  result
128
117
  end
129
118
 
@@ -131,7 +120,7 @@ class TestUpdater < Test::Unit::TestCase
131
120
  def test_standard_run
132
121
  # Creates a starter environment then updates a few times.
133
122
  prepare_test do |tmpdir|
134
- vim_update_bundles
123
+ vim_update_bundles tmpdir
135
124
  check_tree tmpdir
136
125
  assert_test ?f, "#{tmpdir}/.vim/doc/bundles.txt"
137
126
  assert_test ?d, "#{tmpdir}/.vim/bundle"
@@ -139,23 +128,29 @@ class TestUpdater < Test::Unit::TestCase
139
128
 
140
129
  # Add a repository.
141
130
  create_mock_repo "#{tmpdir}/repo"
142
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo"
143
- vim_update_bundles
131
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo"
132
+ vim_update_bundles tmpdir
144
133
  assert_equal ['.', '..', 'repo'], Dir.open("#{tmpdir}/.vim/bundle") { |d| d.sort }
145
134
  repo = "#{tmpdir}/.vim/bundle/repo" # The local repository, not the origin.
146
135
  assert_test ?f, "#{repo}/first"
147
136
  assert_equal 1, File.read("#{repo}/.git/info/exclude").scan("doc/tags").size
137
+ log = File.read "#{tmpdir}/.vim/doc/bundle-log.txt"
138
+ assert_match /1 bundle added$/, log
148
139
 
149
140
  # Pull upstream changes.
150
141
  update_mock_repo "#{tmpdir}/repo", "second"
151
- vim_update_bundles
142
+ vim_update_bundles tmpdir
152
143
  assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
153
144
  assert_equal 1, File.read("#{repo}/.git/info/exclude").scan("doc/tags").size
145
+ log = File.read "#{tmpdir}/.vim/doc/bundle-log.txt"
146
+ assert_match /1 bundle updated$/, log
154
147
 
155
148
  # Remove the repository.
156
- write_file tmpdir, ".vimrc", ""
157
- vim_update_bundles
149
+ write_file "#{tmpdir}/.vimrc", ""
150
+ vim_update_bundles tmpdir
158
151
  refute_test ?d, repo
152
+ log = File.read "#{tmpdir}/.vim/doc/bundle-log.txt"
153
+ assert_match /1 bundle removed$/, log
159
154
  end
160
155
  end
161
156
 
@@ -164,8 +159,8 @@ class TestUpdater < Test::Unit::TestCase
164
159
  # Do not destroy an existing .vimrc.
165
160
  prepare_test do |tmpdir|
166
161
  str = "don't tread on me"
167
- write_file tmpdir, '.vimrc', str
168
- vim_update_bundles "--vimrc_path='#{tmpdir}/.vimrc'"
162
+ write_file "#{tmpdir}/.vimrc", str
163
+ vim_update_bundles tmpdir, "--vimrc_path='#{tmpdir}/.vimrc'"
169
164
  assert_equal str, File.read("#{tmpdir}/.vimrc")
170
165
  end
171
166
  end
@@ -176,15 +171,15 @@ class TestUpdater < Test::Unit::TestCase
176
171
  prepare_test do |tmpdir|
177
172
  Dir.mkdir "#{tmpdir}/.vim"
178
173
  Dir.chdir("#{tmpdir}/.vim") { `git init` }
179
- vim_update_bundles
174
+ vim_update_bundles tmpdir
180
175
  check_tree tmpdir, ".vim", ".vimrc"
181
176
 
182
177
  # Add submodule.
183
178
  create_mock_repo "#{tmpdir}/repo"
184
179
  File.open("#{tmpdir}/.vim-update-bundles.conf", 'w') { |f| f.write "submodule = true" }
185
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo"
180
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo"
186
181
 
187
- vim_update_bundles
182
+ vim_update_bundles tmpdir
188
183
  assert_equal ['.', '..', 'repo'], Dir.open("#{tmpdir}/.vim/bundle") { |d| d.sort }
189
184
  repo = "#{tmpdir}/.vim/bundle/repo" # The local repository, not the origin.
190
185
  assert_test ?f, "#{repo}/first"
@@ -193,12 +188,12 @@ class TestUpdater < Test::Unit::TestCase
193
188
 
194
189
  # Pull upstream changes.
195
190
  update_mock_repo "#{tmpdir}/repo", "second"
196
- vim_update_bundles
191
+ vim_update_bundles tmpdir
197
192
  assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
198
193
 
199
194
  # Remove the repository.
200
- write_file tmpdir, ".vimrc", ""
201
- vim_update_bundles
195
+ write_file "#{tmpdir}/.vimrc", ""
196
+ vim_update_bundles tmpdir
202
197
  refute_test ?d, repo
203
198
 
204
199
  ['.gitmodules', '.git/config'].each do |filename|
@@ -214,9 +209,9 @@ class TestUpdater < Test::Unit::TestCase
214
209
  # already exists.
215
210
  prepare_test do |tmpdir|
216
211
  Dir.mkdir "#{tmpdir}/.vim"
217
- write_file tmpdir, ".vim/vimrc", ''
218
- vim_update_bundles
219
- check_tree tmpdir, ".vim", ".vim/vimrc"
212
+ write_file "#{tmpdir}/.vimrc", ''
213
+ vim_update_bundles tmpdir
214
+ check_tree tmpdir, ".vim", ".vimrc"
220
215
 
221
216
  # Make a repository with a tagged commit and commits after that.
222
217
  create_mock_repo "#{tmpdir}/repo"
@@ -224,8 +219,8 @@ class TestUpdater < Test::Unit::TestCase
224
219
  update_mock_repo "#{tmpdir}/repo", 'third'
225
220
 
226
221
  # Check out the plugin locked at 0.2
227
- write_file tmpdir, ".vim/vimrc", "\" Bundle: #{tmpdir}/repo 0.2"
228
- vim_update_bundles
222
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo 0.2"
223
+ vim_update_bundles tmpdir
229
224
  assert_equal ['.', '..', 'repo'], Dir.open("#{tmpdir}/.vim/bundle") { |d| d.sort }
230
225
  assert_test ?f, "#{tmpdir}/.vim/bundle/repo/first"
231
226
  assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
@@ -233,21 +228,21 @@ class TestUpdater < Test::Unit::TestCase
233
228
 
234
229
  # Pull upstream changes, make sure we're still locked on 0.2.
235
230
  update_mock_repo "#{tmpdir}/repo", "fourth"
236
- vim_update_bundles
231
+ vim_update_bundles tmpdir
237
232
  assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
238
233
  refute_test ?f, "#{tmpdir}/.vim/bundle/repo/third"
239
234
  refute_test ?f, "#{tmpdir}/.vim/bundle/repo/fourth"
240
235
 
241
236
  # Switch to the branch head
242
- write_file tmpdir, ".vim/vimrc", "\" Bundle: #{tmpdir}/repo"
243
- vim_update_bundles
237
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo"
238
+ vim_update_bundles tmpdir
244
239
  assert_test ?f, "#{tmpdir}/.vim/bundle/repo/first"
245
240
  assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
246
241
  assert_test ?f, "#{tmpdir}/.vim/bundle/repo/third"
247
242
 
248
243
  # Switch back to the tag
249
- write_file tmpdir, ".vim/vimrc", "\" Bundle: #{tmpdir}/repo 0.2"
250
- vim_update_bundles
244
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo 0.2"
245
+ vim_update_bundles tmpdir
251
246
  assert_test ?f, "#{tmpdir}/.vim/bundle/repo/first"
252
247
  assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
253
248
  refute_test ?f, "#{tmpdir}/.vim/bundle/repo/third"
@@ -259,15 +254,15 @@ class TestUpdater < Test::Unit::TestCase
259
254
  # Ensures locking a checkout to a tag.
260
255
  prepare_test do |tmpdir|
261
256
  Dir.chdir(tmpdir) { `git init` }
262
- vim_update_bundles '--submodule=true'
257
+ vim_update_bundles tmpdir, '--submodule=true'
263
258
  check_tree tmpdir
264
259
 
265
260
  create_mock_repo "#{tmpdir}/repo"
266
261
  update_mock_repo_tagged "#{tmpdir}/repo", 'second', '0.2'
267
262
  update_mock_repo "#{tmpdir}/repo", 'third'
268
263
 
269
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo 0.2"
270
- vim_update_bundles '--submodule=1'
264
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo 0.2"
265
+ vim_update_bundles tmpdir, '--submodule=1'
271
266
  assert_equal ['.', '..', 'repo'], Dir.open("#{tmpdir}/.vim/bundle") { |d| d.sort }
272
267
  assert_test ?f, "#{tmpdir}/.gitmodules"
273
268
  repo = "#{tmpdir}/.vim/bundle/repo" # The local repository, not the origin.
@@ -278,7 +273,7 @@ class TestUpdater < Test::Unit::TestCase
278
273
 
279
274
  # Pull upstream changes.
280
275
  update_mock_repo "#{tmpdir}/repo", "third"
281
- vim_update_bundles '--submodule=1'
276
+ vim_update_bundles tmpdir, '--submodule=1'
282
277
  assert_test ?f, "#{repo}/second"
283
278
  refute_test ?f, "#{repo}/third"
284
279
  refute_test ?f, "#{repo}/fourth"
@@ -289,7 +284,7 @@ class TestUpdater < Test::Unit::TestCase
289
284
  def test_branch_checkout
290
285
  # Ensures new commits on a branch are followed.
291
286
  prepare_test do |tmpdir|
292
- vim_update_bundles
287
+ vim_update_bundles tmpdir
293
288
  check_tree tmpdir
294
289
 
295
290
  # Make a repository with another branch.
@@ -300,8 +295,8 @@ class TestUpdater < Test::Unit::TestCase
300
295
  update_mock_repo "#{tmpdir}/repo", 'second'
301
296
 
302
297
  # Clone repository on the given branch.
303
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo abranch"
304
- vim_update_bundles
298
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo abranch"
299
+ vim_update_bundles tmpdir
305
300
  assert_equal ['.', '..', 'repo'], Dir.open("#{tmpdir}/.vim/bundle") { |d| d.sort }
306
301
  repo = "#{tmpdir}/.vim/bundle/repo" # The local repository, not the origin.
307
302
  assert_test ?f, "#{repo}/first"
@@ -312,23 +307,23 @@ class TestUpdater < Test::Unit::TestCase
312
307
  update_mock_repo "#{tmpdir}/repo", "third"
313
308
  Dir.chdir("#{tmpdir}/repo") { `git checkout -q abranch` }
314
309
  update_mock_repo "#{tmpdir}/repo", "b-third"
315
- vim_update_bundles
310
+ vim_update_bundles tmpdir
316
311
  assert_test ?f, "#{repo}/b-second"
317
312
  assert_test ?f, "#{repo}/b-third"
318
313
  refute_test ?f, "#{repo}/second"
319
314
  refute_test ?f, "#{repo}/third"
320
315
 
321
316
  # Switch to the master branch
322
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo"
323
- vim_update_bundles
317
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo"
318
+ vim_update_bundles tmpdir
324
319
  assert_test ?f, "#{repo}/second"
325
320
  assert_test ?f, "#{repo}/third"
326
321
  refute_test ?f, "#{repo}/b-second"
327
322
  refute_test ?f, "#{repo}/b-third"
328
323
 
329
324
  # And switch back to our branch
330
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo abranch"
331
- vim_update_bundles
325
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo abranch"
326
+ vim_update_bundles tmpdir
332
327
  assert_test ?f, "#{repo}/b-second"
333
328
  assert_test ?f, "#{repo}/b-third"
334
329
  refute_test ?f, "#{repo}/second"
@@ -341,7 +336,7 @@ class TestUpdater < Test::Unit::TestCase
341
336
  # Ensures locking a checkout to a tag.
342
337
  prepare_test do |tmpdir|
343
338
  Dir.chdir(tmpdir) { `git init` }
344
- vim_update_bundles '--submodule=true'
339
+ vim_update_bundles tmpdir, '--submodule=true'
345
340
  check_tree tmpdir
346
341
 
347
342
  # Make a repository with another branch.
@@ -351,8 +346,8 @@ class TestUpdater < Test::Unit::TestCase
351
346
  Dir.chdir("#{tmpdir}/repo") { `git checkout -q master` }
352
347
  update_mock_repo "#{tmpdir}/repo", 'second'
353
348
 
354
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo abranch"
355
- vim_update_bundles '--submodule=1'
349
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo abranch"
350
+ vim_update_bundles tmpdir, '--submodule=1'
356
351
  assert_equal ['.', '..', 'repo'], Dir.open("#{tmpdir}/.vim/bundle") { |d| d.sort }
357
352
  assert_test ?f, "#{tmpdir}/.gitmodules"
358
353
  repo = "#{tmpdir}/.vim/bundle/repo" # The local repository, not the origin.
@@ -365,7 +360,7 @@ class TestUpdater < Test::Unit::TestCase
365
360
  update_mock_repo "#{tmpdir}/repo", "third"
366
361
  Dir.chdir("#{tmpdir}/repo") { `git checkout -q abranch` }
367
362
  update_mock_repo "#{tmpdir}/repo", "b-third"
368
- vim_update_bundles '--submodule=1'
363
+ vim_update_bundles tmpdir, '--submodule=1'
369
364
  assert_test ?f, "#{repo}/b-second"
370
365
  assert_test ?f, "#{repo}/b-third"
371
366
  refute_test ?f, "#{repo}/third"
@@ -379,8 +374,8 @@ class TestUpdater < Test::Unit::TestCase
379
374
  create_mock_repo "#{tmpdir}/repo1"
380
375
  create_mock_repo "#{tmpdir}/repo2"
381
376
 
382
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo1 nobranch\n\" Bundle: #{tmpdir}/repo2"
383
- vim_update_bundles__expect_error
377
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo1 nobranch\n\" Bundle: #{tmpdir}/repo2"
378
+ vim_update_bundles tmpdir, :acceptable_exit_codes => [1], :stderr => :suppress
384
379
  refute_test ?d, "#{tmpdir}/.vim/bundle/repo2" # ensure we didn't continue cloning repos
385
380
  end
386
381
  end
@@ -391,52 +386,263 @@ class TestUpdater < Test::Unit::TestCase
391
386
  create_mock_repo "#{tmpdir}/repo1"
392
387
  create_mock_repo "#{tmpdir}/repo2"
393
388
 
394
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo1"
395
- vim_update_bundles
389
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo1"
390
+ vim_update_bundles tmpdir
396
391
  assert_test ?f, "#{tmpdir}/.vim/bundle/repo1/first"
397
392
 
398
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo1 v0.2\n\" Bundle: #{tmpdir}/repo2"
399
- vim_update_bundles__expect_error
393
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo1 v0.2\n\" Bundle: #{tmpdir}/repo2"
394
+ vim_update_bundles tmpdir, :acceptable_exit_codes => [1], :stderr => :suppress
400
395
  refute_test ?d, "#{tmpdir}/.vim/bundle/repo2" # ensure we didn't continue cloning repos
401
396
  end
402
397
  end
403
398
 
404
399
 
400
+ def test_duplicate_bundle_entries
401
+ prepare_test do |tmpdir|
402
+ create_mock_repo "#{tmpdir}/repo1"
403
+ write_file "#{tmpdir}/.vimrc",
404
+ "\" Bundle: #{tmpdir}/repo1\n" +
405
+ "\" Bundle: #{tmpdir}/repo1\n"
406
+ output = vim_update_bundles tmpdir, :acceptable_exit_codes => [1], :stderr => :merge
407
+ assert_match /duplicate entry for .*repo1/, output
408
+ end
409
+ end
410
+
411
+
412
+ def test_bundles_with_conflicting_names
413
+ prepare_test do |tmpdir|
414
+ Dir.mkdir "#{tmpdir}/one"
415
+ Dir.mkdir "#{tmpdir}/two"
416
+ create_mock_repo "#{tmpdir}/one/repo"
417
+ create_mock_repo "#{tmpdir}/two/repo"
418
+
419
+ # write a single .vimrc with conflicting bundles
420
+ write_file "#{tmpdir}/.vimrc",
421
+ "\" Bundle: #{tmpdir}/one/repo\n" +
422
+ "\" Bundle: #{tmpdir}/two/repo\n"
423
+ output = vim_update_bundles tmpdir, :acceptable_exit_codes => [1], :stderr => :merge
424
+ assert_match /urls map to the same bundle: .*repo and .*repo/, output
425
+ end
426
+ end
427
+
428
+
429
+ def test_remote_for_repo_is_changed
430
+ # plugin name stays the same but the Git url changes
431
+ prepare_test do |tmpdir|
432
+ Dir.mkdir "#{tmpdir}/one"
433
+ Dir.mkdir "#{tmpdir}/two"
434
+ create_mock_repo "#{tmpdir}/one/repo"
435
+ create_mock_repo "#{tmpdir}/two/repo"
436
+ update_mock_repo "#{tmpdir}/two/repo"
437
+
438
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/one/repo"
439
+ vim_update_bundles tmpdir
440
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/first"
441
+ refute_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
442
+
443
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/two/repo"
444
+ output = vim_update_bundles tmpdir, :stderr => :merge
445
+ assert_match /bundle for repo changed/, output
446
+
447
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/first"
448
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
449
+ log = File.read "#{tmpdir}/.vim/doc/bundle-log.txt"
450
+ assert_match /bundle for repo changed/, log
451
+ end
452
+ end
453
+
454
+
455
+ def git_sha repo, branch='HEAD'
456
+ # returns the sha of the topmost commit in the named branch
457
+ sha = `git --git-dir='#{repo}/.git' rev-parse #{branch}`.chomp
458
+ assert_match /^[0-9A-Fa-f]{40}/, sha
459
+ sha
460
+ end
461
+
462
+
463
+ def test_upstream_regenerates_ancestry_resets_repo
464
+ # Test what happens when the checked out git branch loses its ancestry.
465
+ prepare_test do |tmpdir|
466
+ create_mock_repo "#{tmpdir}/repo1"
467
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo1"
468
+ vim_update_bundles tmpdir
469
+
470
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo1/first"
471
+ orig_head = git_sha("#{tmpdir}/.vim/bundle/repo1")
472
+ assert_equal orig_head, git_sha("#{tmpdir}/repo1")
473
+
474
+ # delete/regen repo so it looks identical but all SHAs are different
475
+ FileUtils.rm_rf "#{tmpdir}/repo1"
476
+ create_mock_repo "#{tmpdir}/repo1", "Invalid .-. Second Author"
477
+ vim_update_bundles tmpdir, :stderr => :merge
478
+
479
+ new_head = git_sha("#{tmpdir}/.vim/bundle/repo1")
480
+ assert_not_equal orig_head, new_head
481
+ assert_equal new_head, git_sha("#{tmpdir}/repo1")
482
+ assert_test ?d, "#{tmpdir}/.vim/Trashed-Bundles/repo1" # make sure old was trashed
483
+ end
484
+ end
485
+
486
+
487
+ def test_pull_with_local_changes_resets_repo
488
+ prepare_test do |tmpdir|
489
+ create_mock_repo "#{tmpdir}/repo1"
490
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo1"
491
+ vim_update_bundles tmpdir
492
+ # make sure repo was successfully cloned
493
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo1/first"
494
+ assert_equal "first", File.read("#{tmpdir}/.vim/bundle/repo1/first")
495
+
496
+ # make a conflicting local change and pull again
497
+ update_mock_repo "#{tmpdir}/repo1", "first", "second commit to first file"
498
+ write_file "#{tmpdir}/.vim/bundle/repo1/first", "local change"
499
+ vim_update_bundles tmpdir, :stderr => :merge
500
+
501
+ # make sure the local repo matches the latest upstream
502
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo1/first"
503
+ assert_equal "second commit to first file", File.read("#{tmpdir}/.vim/bundle/repo1/first")
504
+ # and also verify user's changes are preserved in .Trashed-Bundles
505
+ assert_test ?f, "#{tmpdir}/.vim/Trashed-Bundles/repo1/first"
506
+ assert_equal "local change", File.read("#{tmpdir}/.vim/Trashed-Bundles/repo1/first")
507
+ end
508
+ end
509
+
510
+
511
+ def test_pull_with_conflicting_local_file_resets_repo
512
+ prepare_test do |tmpdir|
513
+ create_mock_repo "#{tmpdir}/repo1"
514
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo1"
515
+ vim_update_bundles tmpdir
516
+ # make sure repo was successfully cloned
517
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo1/first"
518
+ assert_equal "first", File.read("#{tmpdir}/.vim/bundle/repo1/first")
519
+
520
+ # make a conflicting local change and pull again
521
+ update_mock_repo "#{tmpdir}/repo1", "second"
522
+ write_file "#{tmpdir}/.vim/bundle/repo1/second", "changed!"
523
+ output = vim_update_bundles tmpdir, :stderr => :merge
524
+
525
+ # make sure the local repo matches the latest upstream
526
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo1/second"
527
+ assert_equal "second", File.read("#{tmpdir}/.vim/bundle/repo1/second")
528
+ # and also verify user's changes are preserved in .Trashed-Bundles
529
+ assert_test ?f, "#{tmpdir}/.vim/Trashed-Bundles/repo1/second"
530
+ assert_equal "changed!", File.read("#{tmpdir}/.vim/Trashed-Bundles/repo1/second")
531
+ end
532
+ end
533
+
534
+
535
+ def clone_and_delete_repo tmpdir, suffix
536
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/plugin1"
537
+ vim_update_bundles tmpdir
538
+ assert_test ?d, "#{tmpdir}/.vim/bundle/plugin1"
539
+
540
+ write_file "#{tmpdir}/.vimrc", ''
541
+ vim_update_bundles tmpdir
542
+ refute_test ?d, "#{tmpdir}/.vim/bundle/plugin1"
543
+ assert_test ?d, "#{tmpdir}/.vim/Trashed-Bundles/plugin1#{suffix}"
544
+ end
545
+
546
+
405
547
  def test_multiple_removes
406
548
  # add and remove a plugin multiple times
407
549
  prepare_test do |tmpdir|
408
550
  create_mock_repo "#{tmpdir}/plugin1"
409
- 4.times do
410
- write_file tmpdir, '.vimrc', "\" Bundle: #{tmpdir}/plugin1"
411
- vim_update_bundles
412
- assert_test ?d, "#{tmpdir}/.vim/bundle/plugin1"
413
-
414
- write_file tmpdir, '.vimrc', ''
415
- vim_update_bundles
416
- refute_test ?d, "#{tmpdir}/.vim/bundle/plugin1"
417
- end
551
+ clone_and_delete_repo tmpdir, ''
552
+ 1.upto(5) { |i| clone_and_delete_repo tmpdir, "-#{"%02d" % i}" }
418
553
  end
419
554
  end
420
555
 
421
556
 
422
- def test_bundle_command # oops, there's some duplication with test_working_bundle_command
557
+ def test_multiple_remove_failure
558
+ # Plug up Trashed-Bundles so a bundle can't be removed to ensure
559
+ # that vim-update-bundles bails out and prints a decent error.
560
+ prepare_test do |tmpdir|
561
+ create_mock_repo "#{tmpdir}/plugin1"
562
+ Dir.mkdir "#{tmpdir}/.vim"
563
+ Dir.mkdir "#{tmpdir}/.vim/Trashed-Bundles"
564
+ Dir.mkdir "#{tmpdir}/.vim/Trashed-Bundles/plugin1"
565
+ 1.upto(99) { |i| Dir.mkdir "#{tmpdir}/.vim/Trashed-Bundles/plugin1-%02d" % i }
566
+
567
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/plugin1"
568
+ vim_update_bundles tmpdir
569
+ assert_test ?f, "#{tmpdir}/.vim/bundle/plugin1/first"
570
+
571
+ write_file "#{tmpdir}/.vimrc", ''
572
+ output = vim_update_bundles tmpdir, :acceptable_exit_codes => [1], :stderr => :merge
573
+ assert_test ?f, "#{tmpdir}/.vim/bundle/plugin1/first"
574
+ assert_match /unable to remove plugin1/, output
575
+ end
576
+ end
577
+
578
+
579
+ def test_submodule_remove_failure
580
+ prepare_test do |tmpdir|
581
+ Dir.mkdir "#{tmpdir}/.vim"
582
+ Dir.chdir("#{tmpdir}/.vim") { `git init` }
583
+ create_mock_repo "#{tmpdir}/repo"
584
+ # add plugin as a submodule
585
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo"
586
+ vim_update_bundles tmpdir, '--submodule'
587
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/first"
588
+ assert_test ?f, "#{tmpdir}/.vim/.gitmodules"
589
+
590
+ # remove plugin but write-protect .gitmodules to force failure
591
+ write_file "#{tmpdir}/.vimrc", ''
592
+ File.chmod 0444, "#{tmpdir}/.vim/.gitmodules"
593
+ output = vim_update_bundles tmpdir, '--submodule', :acceptable_exit_codes => [1], :stderr => :merge
594
+ assert_match /could not delete repo from \.gitmodules/, output
595
+ end
596
+ end
597
+
598
+
599
+ def test_vundle_directives
600
+ # ensure vundle directives work
601
+ prepare_test do |tmpdir|
602
+ create_mock_repo "#{tmpdir}/repo"
603
+ # test Bundle and BundleCommand
604
+ write_file "#{tmpdir}/.vimrc", "Bundle '#{tmpdir}/repo'\n" +
605
+ "BundleCommand 'echo \"yep''s\" > ''#{tmpdir}/sentinel'''\n"
606
+ vim_update_bundles tmpdir
607
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/first"
608
+ assert_equal "yep's\n", File.read("#{tmpdir}/sentinel")
609
+
610
+ # make sure Bundle accepts a branch/tag to check out
611
+ update_mock_repo_tagged "#{tmpdir}/repo", 'second', '0.2'
612
+ update_mock_repo "#{tmpdir}/repo", 'third'
613
+ write_file "#{tmpdir}/.vimrc", "Bundle \"#{tmpdir}/repo 0.2\""
614
+ vim_update_bundles tmpdir
615
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/first"
616
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
617
+ refute_test ?f, "#{tmpdir}/.vim/bundle/repo/third"
618
+
619
+ # mark the bundle as static, make sure it isn't removed
620
+ write_file "#{tmpdir}/.vimrc", "Bundle! 'repo'\n"
621
+ vim_update_bundles tmpdir
622
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/first"
623
+ end
624
+ end
625
+
626
+
627
+ def test_bundle_command
628
+ # oops, there's some duplication with test_working_bundle_command
423
629
  prepare_test do |tmpdir|
424
630
  # ensure BundleCommand is called when adding a repo
425
631
  create_mock_repo "#{tmpdir}/plugin1"
426
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/plugin1\n\" BundleCommand: touch '#{tmpdir}/sentinel1'"
427
- vim_update_bundles
632
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/plugin1\n\" BundleCommand: touch '#{tmpdir}/sentinel1'"
633
+ vim_update_bundles tmpdir
428
634
  assert_test ?f, "#{tmpdir}/sentinel1"
429
635
 
430
636
  # ensure BundleCommand is called when updating a repo
431
637
  update_mock_repo "#{tmpdir}/plugin1", "second"
432
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/plugin1\n\" Bundle-Command: touch '#{tmpdir}/sentinel2'"
433
- vim_update_bundles
638
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/plugin1\n\" Bundle-Command: touch '#{tmpdir}/sentinel2'"
639
+ vim_update_bundles tmpdir
434
640
  assert_test ?f, "#{tmpdir}/sentinel2"
435
641
 
436
642
  # ensure BundleCommand is NOT called when updating a repo when --no-updates is on
437
643
  update_mock_repo "#{tmpdir}/plugin1", "second"
438
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/plugin1\n\" BundleCommand: touch '#{tmpdir}/sentinel3'"
439
- vim_update_bundles '--no-updates'
644
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/plugin1\n\" BundleCommand: touch '#{tmpdir}/sentinel3'"
645
+ vim_update_bundles tmpdir, '--no-updates'
440
646
  refute_test ?f, "#{tmpdir}/sentinel3"
441
647
  end
442
648
  end
@@ -444,15 +650,15 @@ class TestUpdater < Test::Unit::TestCase
444
650
 
445
651
  def test_working_bundle_command
446
652
  prepare_test do |tmpdir|
447
- vim_update_bundles
653
+ vim_update_bundles tmpdir
448
654
  check_tree tmpdir
449
655
  create_mock_repo "#{tmpdir}/repo"
450
- write_file tmpdir, ".vimrc", <<-EOL
656
+ write_file "#{tmpdir}/.vimrc", <<-EOL
451
657
  " Bundle: #{tmpdir}/repo
452
658
  " Bundle command: echo hiya > #{tmpdir}/output
453
659
  EOL
454
660
 
455
- vim_update_bundles
661
+ vim_update_bundles tmpdir
456
662
  assert_test ?f, "#{tmpdir}/output"
457
663
  assert_equal "hiya\n", File.read("#{tmpdir}/output")
458
664
  end
@@ -461,32 +667,31 @@ class TestUpdater < Test::Unit::TestCase
461
667
 
462
668
  def test_failing_bundle_command
463
669
  prepare_test do |tmpdir|
464
- vim_update_bundles '#{@starter_urls}'
670
+ vim_update_bundles tmpdir, '#{@starter_urls}'
465
671
  check_tree tmpdir
466
672
 
467
673
  create_mock_repo "#{tmpdir}/repo"
468
- write_file tmpdir, ".vimrc", <<-EOL
674
+ write_file "#{tmpdir}/.vimrc", <<-EOL
469
675
  " Bundle: #{tmpdir}/repo
470
676
  " Bundle-Command: oh-no-this-command-does-not-exist
471
677
  EOL
472
678
 
473
- vim_update_bundles__expect_error
474
- assert $?.exitstatus == 47, "the bundle-command should have produced 47, not #{$?.exitstatus}"
679
+ vim_update_bundles tmpdir, :acceptable_exit_codes => [47], :stderr => :suppress
475
680
  end
476
681
  end
477
682
 
478
683
 
479
684
  def test_static_bundle
480
685
  prepare_test do |tmpdir|
481
- vim_update_bundles
686
+ vim_update_bundles tmpdir
482
687
  Dir.mkdir "#{tmpdir}/.vim/bundle/foreign"
483
688
  Dir.mkdir "#{tmpdir}/.vim/bundle/static"
484
- write_file tmpdir, ".vimrc", '" Static: static'
689
+ write_file "#{tmpdir}/.vimrc", '" Static: static'
485
690
 
486
- vim_update_bundles
691
+ vim_update_bundles tmpdir
487
692
  assert_test ?d, "#{tmpdir}/.vim/bundle/static"
488
693
  refute_test ?d, "#{tmpdir}/.vim/bundle/foreign"
489
- assert_test ?d, "#{tmpdir}/.vim/Trashed-Bundles/foreign-01"
694
+ assert_test ?d, "#{tmpdir}/.vim/Trashed-Bundles/foreign"
490
695
  end
491
696
  end
492
697
 
@@ -495,8 +700,8 @@ class TestUpdater < Test::Unit::TestCase
495
700
  # Makes sure we still add and delete even when --no-updates prevents updates
496
701
  prepare_test do |tmpdir|
497
702
  create_mock_repo "#{tmpdir}/plugin1"
498
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/plugin1"
499
- vim_update_bundles '--no-updates'
703
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/plugin1"
704
+ vim_update_bundles tmpdir, '--no-updates'
500
705
 
501
706
  # make sure plugin1 was added even though --no-updates was turned on
502
707
  assert_test ?f, "#{tmpdir}/.vim/bundle/plugin1/first"
@@ -504,8 +709,8 @@ class TestUpdater < Test::Unit::TestCase
504
709
 
505
710
  update_mock_repo "#{tmpdir}/plugin1", "second"
506
711
  create_mock_repo "#{tmpdir}/plugin2"
507
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/plugin1\n\" Bundle: #{tmpdir}/plugin2"
508
- vim_update_bundles '-n' # test single-letter arg
712
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/plugin1\n\" Bundle: #{tmpdir}/plugin2"
713
+ vim_update_bundles tmpdir, '-n' # test single-letter arg
509
714
 
510
715
  # make sure plugin1 hasn't been updated but plugin2 has been added
511
716
  assert_test ?f, "#{tmpdir}/.vim/bundle/plugin1/first"
@@ -513,8 +718,8 @@ class TestUpdater < Test::Unit::TestCase
513
718
  assert_test ?f, "#{tmpdir}/.vim/bundle/plugin2/first"
514
719
 
515
720
  # Remove the repository.
516
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/plugin1"
517
- vim_update_bundles '--no-updates'
721
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/plugin1"
722
+ vim_update_bundles tmpdir, '--no-updates'
518
723
 
519
724
  # make sure plugin1 hasn't been updated but plugin2 has been deleted
520
725
  assert_test ?f, "#{tmpdir}/.vim/bundle/plugin1/first"
@@ -524,25 +729,25 @@ class TestUpdater < Test::Unit::TestCase
524
729
  end
525
730
 
526
731
 
527
- def test_create_dotfile_environment
732
+ def test_create_skips_dotfile_environment
528
733
  prepare_test do |tmpdir|
529
734
  Dir.mkdir "#{tmpdir}/.dotfiles"
530
- vim_update_bundles
531
- check_tree tmpdir, '.dotfiles/vim', '.dotfiles/vimrc'
735
+ vim_update_bundles tmpdir
736
+ check_tree tmpdir, '.vim', '.vimrc'
532
737
  end
533
738
  end
534
739
 
535
740
 
536
- def test_create_dotfile_environment_with_vimrc_in_vim
741
+ def test_dotfiles_are_used_if_present
537
742
  prepare_test do |tmpdir|
538
- Dir.mkdir "#{tmpdir}/zedots"
539
- Dir.mkdir "#{tmpdir}/zedots/vim"
540
- write_file tmpdir, "zedots/vim/vimrc", '" ignored'
743
+ Dir.mkdir "#{tmpdir}/.dotfiles"
744
+ Dir.mkdir "#{tmpdir}/.dotfiles/vim"
745
+ write_file "#{tmpdir}/.dotfiles/vimrc", ''
746
+ vim_update_bundles tmpdir
541
747
 
542
- vim_update_bundles "--dotfiles_path='#{tmpdir}/zedots'"
543
- check_tree tmpdir, 'zedots/vim', 'zedots/vim/vimrc'
544
- refute_test ?e, "#{tmpdir}/.dotfiles/.vimrc"
545
- refute_test ?e, "#{tmpdir}/zedots/.vimrc"
748
+ check_tree tmpdir, '.dotfiles/vim', '.dotfiles/vimrc'
749
+ refute_test ?d, "#{tmpdir}/.vim"
750
+ refute_test ?f, "#{tmpdir}/.vimrc"
546
751
  end
547
752
  end
548
753
 
@@ -550,7 +755,7 @@ class TestUpdater < Test::Unit::TestCase
550
755
  def test_create_custom_vimrc_environment
551
756
  prepare_test do |tmpdir|
552
757
  Dir.mkdir "#{tmpdir}/mydots"
553
- vim_update_bundles "vimrc_path='#{tmpdir}/mydots/vim rc'"
758
+ vim_update_bundles tmpdir, "vimrc_path='#{tmpdir}/mydots/vim rc'"
554
759
  check_tree tmpdir, '.vim', 'mydots/vim rc'
555
760
  end
556
761
  end
@@ -564,7 +769,7 @@ class TestUpdater < Test::Unit::TestCase
564
769
  File.open("#{tmpdir}/.vim-update-bundles.conf", 'w') { |f|
565
770
  f.write "vimrc_path = #{tmpdir}/$PARENT/child/vv zz"
566
771
  }
567
- vim_update_bundles
772
+ vim_update_bundles tmpdir
568
773
  check_tree tmpdir, '.vim', 'parent/child/vv zz'
569
774
  end
570
775
  end
@@ -572,7 +777,7 @@ class TestUpdater < Test::Unit::TestCase
572
777
 
573
778
  def test_interpolation_works
574
779
  prepare_test do |tmpdir|
575
- vim_update_bundles "--vimdir_path='$HOME/vimmy' --vimrc_path='$vimdir_path/vimmyrc'"
780
+ vim_update_bundles tmpdir, "--vimdir_path='$HOME/vimmy' --vimrc_path='$vimdir_path/vimmyrc'"
576
781
  check_tree tmpdir, 'vimmy', 'vimmy/vimmyrc'
577
782
  end
578
783
  end
@@ -580,8 +785,7 @@ class TestUpdater < Test::Unit::TestCase
580
785
 
581
786
  def test_unknown_interpolation_fails
582
787
  prepare_test do |tmpdir|
583
- vim_update_bundles__expect_error "--verbose='$unknown'"
584
- assert $?.exitstatus == 1, "the bundle-command should have produced 1, not #{$?.exitstatus}"
788
+ vim_update_bundles tmpdir, "--verbose='$unknown'", :acceptable_exit_codes => [1], :stderr => :suppress
585
789
  # Make sure it didn't create any files.
586
790
  refute_test ?e, "#{tmpdir}/.vim"
587
791
  refute_test ?e, "#{tmpdir}/.vimrc"
@@ -604,8 +808,8 @@ class TestUpdater < Test::Unit::TestCase
604
808
 
605
809
  # test logfiles with an empty .vimrc
606
810
  Dir.mkdir "#{tmpdir}/.vim"
607
- write_file tmpdir, ".vimrc", ''
608
- vim_update_bundles
811
+ write_file "#{tmpdir}/.vimrc", ''
812
+ vim_update_bundles tmpdir
609
813
 
610
814
  assert_test ?f, "#{tmpdir}/.vim/doc/bundles.txt"
611
815
  assert_test ?f, "#{tmpdir}/.vim/doc/bundle-log.txt"
@@ -613,8 +817,8 @@ class TestUpdater < Test::Unit::TestCase
613
817
  # Make a repository with a tagged commit and commits after that.
614
818
  create_mock_repo "#{tmpdir}/repo"
615
819
  update_mock_repo_tagged "#{tmpdir}/repo", 'second', '0.2'
616
- write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo"
617
- vim_update_bundles
820
+ write_file "#{tmpdir}/.vimrc", "\" Bundle: #{tmpdir}/repo"
821
+ vim_update_bundles tmpdir
618
822
 
619
823
  list = File.read "#{tmpdir}/.vim/doc/bundles.txt"
620
824
  log = File.read "#{tmpdir}/.vim/doc/bundle-log.txt"
@@ -628,7 +832,7 @@ class TestUpdater < Test::Unit::TestCase
628
832
 
629
833
  # Pull upstream changes.
630
834
  update_mock_repo_tagged "#{tmpdir}/repo", 'third', '0.3'
631
- vim_update_bundles
835
+ vim_update_bundles tmpdir
632
836
 
633
837
  list = File.read "#{tmpdir}/.vim/doc/bundles.txt"
634
838
  log = File.read "#{tmpdir}/.vim/doc/bundle-log.txt"
@@ -636,14 +840,14 @@ class TestUpdater < Test::Unit::TestCase
636
840
  assert_no_match /\|repo\|\s*0\.2/, list
637
841
  assert_match /\|repo\|\s*0\.3/, list
638
842
  assert_match /Add\s*\|repo\|\s*0\.2/, log
639
- assert_match /up\s*\|repo\|\s*0\.2\s*->\s*0\.3/, log
843
+ assert_match /up\s*\|repo\|\s*0\.3\s*<-\s*0\.2/, log
640
844
  ensure_marker log, marker_string
641
845
 
642
846
  # won't bother changing the remote since vim-update-bundles handles it
643
847
  # as a delete followed by an add. might be worth testing though.
644
848
 
645
- write_file tmpdir, ".vimrc", ''
646
- vim_update_bundles
849
+ write_file "#{tmpdir}/.vimrc", ''
850
+ vim_update_bundles tmpdir
647
851
 
648
852
  list = File.read "#{tmpdir}/.vim/doc/bundles.txt"
649
853
  log = File.read "#{tmpdir}/.vim/doc/bundle-log.txt"
@@ -651,10 +855,43 @@ class TestUpdater < Test::Unit::TestCase
651
855
  assert_no_match /\|repo\|\s*0\.2/, list
652
856
  assert_no_match /\|repo\|\s*0\.3/, list
653
857
  assert_match /Add\s*\|repo\|\s*0\.2/, log
654
- assert_match /up\s*\|repo\|\s*0\.2\s*->\s*0\.3/, log
858
+ assert_match /up\s*\|repo\|\s*0\.3\s*<-\s*0\.2/, log
655
859
  assert_match /Del\s*\|repo\|\s*0\.3/, log
656
860
  ensure_marker log, marker_string
657
861
  end
658
862
  end
863
+
864
+ def test_unknown_argument
865
+ result = vim_update_bundles '/dev/null', '--yarg', :acceptable_exit_codes => [1], :stderr => :merge
866
+ assert_match /Unknown option.*"yarg"/, result
867
+
868
+ result = vim_update_bundles '/dev/null', '-y', :acceptable_exit_codes => [1], :stderr => :merge
869
+ assert_match /Unknown option.*"y"/, result
870
+
871
+ result = vim_update_bundles '/dev/null', 'y', :acceptable_exit_codes => [1], :stderr => :merge
872
+ assert_match /Unknown option.*"y"/, result
873
+ end
874
+
875
+ def test_usage
876
+ result = vim_update_bundles '/dev/null', '--help'
877
+ assert_match /--no-updates/, result
878
+ end
879
+
880
+ def test_version
881
+ $load_only = true
882
+ Kernel.load 'vim-update-bundles'
883
+ result = vim_update_bundles '/dev/null', '--version'
884
+ assert_match /vim-update-bundles #{Version}/, result
885
+ end
886
+
887
+ def test_verbose
888
+ prepare_test do |tmpdir|
889
+ result = vim_update_bundles tmpdir, '--verbose'
890
+ assert_match /submodule = false/, result
891
+ assert_match /verbose = 1/, result
892
+ assert_match /vimdir_path = "#{tmpdir}\/\.vim"/, result
893
+ assert_match /vimrc_path = "#{tmpdir}\/\.vimrc"/, result
894
+ end
895
+ end
659
896
  end
660
897