[SCM] vim-addon-manager packaging branch, master, updated. v0.4.4-52-geef7258

Antonio Terceiro terceiro at debian.org
Tue Jan 31 23:33:29 UTC 2012


The following commit has been merged in the master branch:
commit 6442a9cb853b6b35e2adb31e943a641e0b2985c2
Author: Antonio Terceiro <terceiro at debian.org>
Date:   Sun Jan 22 14:23:18 2012 -0200

    Implement new style addons
    
    New style addons do not list files in their YAML descriptors, e.g.:
    
      addon: newstyle
      description: "new style addon with a directory instead of files"
      basedir: /path/to/stuff
    
    Such an addon is expected to provide a single directory at
    ${basedir}/bundles/${addon} (i.e., /usr/share/vim/bundles/${addon} by
    default)

diff --git a/features/install.feature b/features/install.feature
index 24b8fdd..c8e3d12 100644
--- a/features/install.feature
+++ b/features/install.feature
@@ -7,3 +7,7 @@ Feature: installing addons
   Scenario: unknown addons
     When I run `vim-addons install addonthatdoesnotexist`
     Then vim-addons should warn "Ignoring unknown addons: addonthatdoesnotexist"
+
+  Scenario: installing newstyle
+    When I run `vim-addons install newstyle`
+    Then newstyle should be installed
diff --git a/features/remove.feature b/features/remove.feature
index d2303ac..a63f4d6 100644
--- a/features/remove.feature
+++ b/features/remove.feature
@@ -4,3 +4,8 @@ Feature: removing addons
     Given foo is installed
     When I run `vim-addons remove foo`
     Then foo should not be installed anymore
+
+  Scenario: removing newstyle
+    Given newstyle is installed
+    When I run `vim-addons remove newstyle`
+    Then newstyle should not be installed anymore
diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb
index 5b4b430..a513ccf 100644
--- a/features/step_definitions/steps.rb
+++ b/features/step_definitions/steps.rb
@@ -1,34 +1,58 @@
 require 'rbconfig'
 require 'tmpdir'
 ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
-sources_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
-vim_addons = File.join(sources_root, 'bin', 'vim-addons')
-libdir = File.join(sources_root, 'lib')
-registry = File.join(sources_root , 'spec/data/registry')
-source = File.join(sources_root, 'spec/data/addons')
+$sources_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
+vim_addons = File.join($sources_root, 'bin', 'vim-addons')
+libdir = File.join($sources_root, 'lib')
+registry = File.join($sources_root , 'spec/data/registry')
+source = File.join($sources_root, 'spec/data/scripts')
 
 Before do
-  @tmpdir = Dir.mktmpdir
+  $tmpdir = Dir.mktmpdir
 end
 
 After do
-  FileUtils.rm_rf(@tmpdir)
+  FileUtils.rm_rf($tmpdir)
 end
 
 When /^I run `vim\-addons (.*)`$/ do |args|
-  command = [ruby, "-I#{libdir}", vim_addons, '--silent', '--registry-dir', registry, '--source-dir', source, '--target-dir', @tmpdir]
+  command = [ruby, "-I#{libdir}", vim_addons, '--silent', '--registry-dir', registry, '--source-dir', source, '--target-dir', $tmpdir]
   args.split.each { |a| command << a }
 
-  stdout = File.join(@tmpdir, 'stdout')
-  stderr = File.join(@tmpdir, 'stderr')
+  stdout = File.join($tmpdir, 'stdout')
+  stderr = File.join($tmpdir, 'stderr')
+
+  cmd = command.join(' ')
+  success = system("#{cmd} >#{stdout} 2>#{stderr}")
 
-  system("#{command.join(' ')} >#{stdout} 2>#{stderr}")
   @stdout = File.read(stdout)
   @stderr = File.read(stderr)
+
+  if !success
+    errormsgs = []
+    errormsgs << "Command `#{cmd}` failed with exit status #{$?.exitstatus}"
+    errormsgs << "stdout:"
+    errormsgs << '======='
+    errormsgs << @stdout
+    errormsgs << "stderr:"
+    errormsgs << '======='
+    errormsgs << @stderr
+    raise errormsgs.join("\n")
+  end
+
+end
+
+def installed_addon_files(addon)
+  descriptor = File.join($sources_root, 'spec/data/registry/' + addon + '.yaml')
+  if !File.exists?(descriptor) || YAML.load_file(descriptor)['files']
+    Dir.glob(File.join($tmpdir, '*', addon + '.vim'))
+  else
+    Dir.glob(File.join($tmpdir, 'bundles', addon))
+  end
 end
 
-Then /^foo should be installed$/ do
-  Dir.glob(File.join(@tmpdir, '*/foo.vim')).should_not be_empty
+Then /^(.*) should be installed$/ do |addon|
+  installed_addon_files(addon).should_not be_empty
 end
 
 Given /^(.*) is installed$/ do |addon|
@@ -36,7 +60,7 @@ Given /^(.*) is installed$/ do |addon|
 end
 
 Then /^(.*) should not be installed anymore$/ do |addon|
-  Dir.glob(File.join(@tmpdir, '*/foo.vim')).should be_empty
+  installed_addon_files(addon).should be_empty
 end
 
 Then /^vim-addons should warn "([^"]*)"$/ do |text|
diff --git a/lib/vim/addon_manager/addon.rb b/lib/vim/addon_manager/addon.rb
index 7444725..153c65d 100644
--- a/lib/vim/addon_manager/addon.rb
+++ b/lib/vim/addon_manager/addon.rb
@@ -47,7 +47,7 @@ module Vim
       # This method must be overriden by subclasses.
       #
       def status(target_dir)
-        :unkonwn
+        AddonStatus.new :unkonwn
       end
 
       # Installs addon files into +target_dir+ and returns a list of installed
diff --git a/lib/vim/addon_manager/addon/directory.rb b/lib/vim/addon_manager/addon/directory.rb
index 1569fa7..22ca928 100644
--- a/lib/vim/addon_manager/addon/directory.rb
+++ b/lib/vim/addon_manager/addon/directory.rb
@@ -6,6 +6,42 @@ module Vim
 
       class Directory < Addon
 
+        def status(target_dir)
+          if File.symlink?(destination(target_dir))
+            AddonStatus.new :installed
+          else
+            AddonStatus.new :not_installed
+          end
+        end
+
+        def install(target_dir)
+          dest = destination(target_dir)
+          FileUtils.mkdir_p(File.dirname(dest))
+          FileUtils.ln_sf(source, dest)
+          files
+        end
+
+        def remove(target_dir)
+          FileUtils.rm_f(destination(target_dir))
+          files
+        end
+
+        def files
+          Dir.chdir(source) do
+            Dir.glob('**/*')
+          end
+        end
+
+      protected
+
+        def source
+          File.join(basedir, 'bundles', name)
+        end
+
+        def destination(target_dir)
+          File.join(target_dir.to_s, 'bundles', name)
+        end
+
       end
     end
 
diff --git a/spec/data/registry/newstyle.yaml b/spec/data/registry/newstyle.yaml
index 1bf87e7..64a82b7 100644
--- a/spec/data/registry/newstyle.yaml
+++ b/spec/data/registry/newstyle.yaml
@@ -1,3 +1,2 @@
 addon: newstyle
 description: "new style addon with a directory instead of files"
-basedir: /usr/share/vim-scripts/bundles
diff --git a/spec/data/bundle/newstyle/ftplugin/newstyle.vim b/spec/data/scripts/bundles/newstyle/ftplugin/newstyle.vim
similarity index 100%
rename from spec/data/bundle/newstyle/ftplugin/newstyle.vim
rename to spec/data/scripts/bundles/newstyle/ftplugin/newstyle.vim
diff --git a/spec/data/bundle/newstyle/syntax/newstyle.vim b/spec/data/scripts/bundles/newstyle/syntax/newstyle.vim
similarity index 100%
rename from spec/data/bundle/newstyle/syntax/newstyle.vim
rename to spec/data/scripts/bundles/newstyle/syntax/newstyle.vim
diff --git a/spec/data/addons/ftplugin/foo.vim b/spec/data/scripts/ftplugin/foo.vim
similarity index 100%
rename from spec/data/addons/ftplugin/foo.vim
rename to spec/data/scripts/ftplugin/foo.vim
diff --git a/spec/data/addons/syntax/bar.vim b/spec/data/scripts/syntax/bar.vim
similarity index 100%
rename from spec/data/addons/syntax/bar.vim
rename to spec/data/scripts/syntax/bar.vim
diff --git a/spec/data/addons/syntax/foo.vim b/spec/data/scripts/syntax/foo.vim
similarity index 100%
rename from spec/data/addons/syntax/foo.vim
rename to spec/data/scripts/syntax/foo.vim
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 358ce19..e9bdc6c 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -8,7 +8,7 @@ rescue LoadError
 end
 
 FAKE_REGISTRY = File.join(File.dirname(__FILE__), 'data/registry')
-FAKE_ADDONS   = File.join(File.dirname(__FILE__), 'data/addons')
+FAKE_SCRIPTS  = File.join(File.dirname(__FILE__), 'data/scripts')
 
 module VimAddonManagerSpecHelper
 
@@ -17,6 +17,7 @@ module VimAddonManagerSpecHelper
     def initialize(path)
       @path = path
     end
+    alias :to_s :path
     def has_file?(file)
       File.exists?(File.join(path, file))
     end
@@ -34,7 +35,7 @@ module VimAddonManagerSpecHelper
   end
 
   def registry
-    @registry ||= Vim::AddonManager::Registry.new(FAKE_REGISTRY, FAKE_ADDONS)
+    @registry ||= Vim::AddonManager::Registry.new(FAKE_REGISTRY, FAKE_SCRIPTS)
   end
 
   def addon(name)
diff --git a/spec/vim/addon_manager/addon/directory_spec.rb b/spec/vim/addon_manager/addon/directory_spec.rb
new file mode 100644
index 0000000..081a5f5
--- /dev/null
+++ b/spec/vim/addon_manager/addon/directory_spec.rb
@@ -0,0 +1,47 @@
+require 'spec_helper'
+
+describe Vim::AddonManager::Addon::Directory do
+
+  it 'report status as :not_installed by default' do
+    addon('newstyle').status(target_dir).status.should == :not_installed
+  end
+
+  it 'lists files inside the directory' do
+    addon = addon('newstyle')
+    addon.stub(:basedir).and_return(File.join(FAKE_SCRIPTS))
+    addon.files.should include('ftplugin/newstyle.vim')
+    addon.files.should include('syntax/newstyle.vim')
+  end
+
+  context 'when installed' do
+    before do
+      @addon = addon('newstyle')
+      @addon.install(target_dir)
+    end
+
+    it 'installs symlink into ~/.vim/bundles/' do
+      Dir.glob(File.join(target_dir.path, 'bundles', 'newstyle')).should_not be_empty
+    end
+
+    it 'reports status as :installed' do
+      @addon.status(target_dir).status.should == :installed
+    end
+
+    context 'and removed' do
+
+      before do
+        @addon.remove(target_dir)
+      end
+
+      it 'reports status as :not_installed' do
+        @addon.status(target_dir.path).status.should == :not_installed
+      end
+
+      it 'removes symlink from ~/.vim/bundles/' do
+        Dir.glob(File.join(target_dir.path, 'bundles', 'newstyle')).should be_empty
+      end
+
+    end
+  end
+
+end
diff --git a/spec/vim/addon_manager/registry_spec.rb b/spec/vim/addon_manager/registry_spec.rb
index 3b6047d..9c52a84 100644
--- a/spec/vim/addon_manager/registry_spec.rb
+++ b/spec/vim/addon_manager/registry_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
 describe Vim::AddonManager::Registry do
 
   before do
-    @registry = Vim::AddonManager::Registry.new(FAKE_REGISTRY, FAKE_ADDONS)
+    @registry = Vim::AddonManager::Registry.new(FAKE_REGISTRY, FAKE_SCRIPTS)
   end
 
   it 'finds all addons in a directory' do

-- 
vim-addon-manager packaging



More information about the pkg-vim-maintainers mailing list