vim-flavor 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +6 -0
- data/README.md +8 -0
- data/features/.nav +2 -0
- data/features/command_line/progress_messages.feature +2 -2
- data/features/flavorfile/groups.feature +60 -0
- data/features/step_definitions/cli_steps.rb +10 -1
- data/features/step_definitions/dependency_steps.rb +3 -0
- data/features/step_definitions/file_steps.rb +9 -0
- data/features/step_definitions/flavor_steps.rb +10 -1
- data/features/support/env.rb +5 -0
- data/features/testing_vim_plugins/README.md +47 -0
- data/features/testing_vim_plugins/dependencies.feature +61 -0
- data/features/testing_vim_plugins/typical_usage.feature +61 -0
- data/features/typical_usage/README.md +1 -1
- data/lib/vim-flavor/cli.rb +23 -6
- data/lib/vim-flavor/facade.rb +51 -7
- data/lib/vim-flavor/flavor.rb +7 -11
- data/lib/vim-flavor/flavorfile.rb +34 -1
- data/lib/vim-flavor/shellutility.rb +14 -0
- data/lib/vim-flavor/stringextension.rb +4 -0
- data/lib/vim-flavor/version.rb +1 -1
- data/lib/vim-flavor.rb +1 -0
- data/spec/facade_spec.rb +4 -4
- data/spec/flavorfile_spec.rb +78 -12
- metadata +16 -2
data/.gitmodules
ADDED
data/README.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# vim-flavor, a tool to manage your favorite Vim plugins
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/kana/vim-flavor.png)](https://travis-ci.org/kana/vim-flavor)
|
4
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/kana/vim-flavor)
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
## Getting started
|
10
|
+
|
3
11
|
cd $YOUR_REPOSITORY_FOR_DOTFILES
|
4
12
|
|
5
13
|
cat >VimFlavor <<'END'
|
data/features/.nav
CHANGED
@@ -16,7 +16,7 @@ Feature: Progress messages
|
|
16
16
|
flavor '$bar_uri'
|
17
17
|
"""
|
18
18
|
When I run `vim-flavor install`
|
19
|
-
Then it outputs progress
|
19
|
+
Then it outputs progress as follows
|
20
20
|
"""
|
21
21
|
Checking versions...
|
22
22
|
Use $bar_uri ... 2.0.2
|
@@ -37,7 +37,7 @@ Feature: Progress messages
|
|
37
37
|
"""
|
38
38
|
fatal: '\S+' does not appear to be a git repository
|
39
39
|
"""
|
40
|
-
And it outputs progress
|
40
|
+
And it outputs progress as follows
|
41
41
|
"""
|
42
42
|
Checking versions...
|
43
43
|
Use no-such-plugin ... failed
|
@@ -0,0 +1,60 @@
|
|
1
|
+
Feature: Groups
|
2
|
+
In order to deploy a specific set of Vim plugins,
|
3
|
+
as a lazy Vim user,
|
4
|
+
I want to declare groups of flavors.
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given a temporary directory called 'tmp'
|
8
|
+
And a home directory called 'home' in '$tmp/home'
|
9
|
+
And a repository 'foo' with versions '1.0 1.1 1.2'
|
10
|
+
And a repository 'bar' with versions '2.0 2.1 2.2'
|
11
|
+
|
12
|
+
Scenario: Install only runtime dependencies
|
13
|
+
Given flavorfile
|
14
|
+
"""ruby
|
15
|
+
flavor '$foo_uri', :group => :runtime
|
16
|
+
flavor '$bar_uri', :group => :development
|
17
|
+
"""
|
18
|
+
When I run `vim-flavor install`
|
19
|
+
Then I get lockfile
|
20
|
+
"""
|
21
|
+
$bar_uri (2.2)
|
22
|
+
$foo_uri (1.2)
|
23
|
+
"""
|
24
|
+
And I get a bootstrap script in '$home/.vim'
|
25
|
+
And I get flavor '$foo_uri' with '1.2' in '$home/.vim'
|
26
|
+
But I don't have flavor '$bar_uri' in '$home/.vim'
|
27
|
+
|
28
|
+
Scenario: The default group
|
29
|
+
Given flavorfile
|
30
|
+
"""ruby
|
31
|
+
flavor '$foo_uri'
|
32
|
+
flavor '$bar_uri', :group => :development
|
33
|
+
"""
|
34
|
+
When I run `vim-flavor install`
|
35
|
+
Then I get lockfile
|
36
|
+
"""
|
37
|
+
$bar_uri (2.2)
|
38
|
+
$foo_uri (1.2)
|
39
|
+
"""
|
40
|
+
And I get a bootstrap script in '$home/.vim'
|
41
|
+
And I get flavor '$foo_uri' with '1.2' in '$home/.vim'
|
42
|
+
But I don't have flavor '$bar_uri' in '$home/.vim'
|
43
|
+
|
44
|
+
Scenario: Group a bunch of flavors at once
|
45
|
+
Given flavorfile
|
46
|
+
"""ruby
|
47
|
+
group :development do
|
48
|
+
flavor '$foo_uri'
|
49
|
+
flavor '$bar_uri'
|
50
|
+
end
|
51
|
+
"""
|
52
|
+
When I run `vim-flavor install`
|
53
|
+
Then I get lockfile
|
54
|
+
"""
|
55
|
+
$bar_uri (2.2)
|
56
|
+
$foo_uri (1.2)
|
57
|
+
"""
|
58
|
+
And I get a bootstrap script in '$home/.vim'
|
59
|
+
But I don't have flavor '$foo_uri' in '$home/.vim'
|
60
|
+
But I don't have flavor '$bar_uri' in '$home/.vim'
|
@@ -23,12 +23,21 @@ When /^I run `vim-flavor(.*)`(?: again)?(?:,? (but))?$/ do |args, mode|
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
Then /^it succeeds$/ do
|
27
|
+
@last_error.should be_nil
|
28
|
+
end
|
29
|
+
|
26
30
|
Then /^it fails with messages like$/ do |pattern|
|
27
31
|
@last_error.should_not be_nil
|
28
32
|
@last_error.message.should match Regexp.new(pattern.strip().gsub(/\s+/, '\s+'))
|
29
33
|
end
|
30
34
|
|
31
|
-
Then 'it outputs progress
|
35
|
+
Then 'it outputs progress as follows' do |text|
|
32
36
|
# For some reason, Cucumber drops the last newline from every docstring...
|
33
37
|
@output.string.should include expand(text + "\n")
|
34
38
|
end
|
39
|
+
|
40
|
+
Then 'it outputs progress like' do |pattern|
|
41
|
+
# For some reason, Cucumber drops the last newline from every docstring...
|
42
|
+
@output.string.should match Regexp.new(expand(pattern + "\n"))
|
43
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Given /^a file called '(.*)'$/ do |virtual_path, content|
|
2
|
+
create_file expand(virtual_path), expand(content)
|
3
|
+
end
|
4
|
+
|
5
|
+
Given /^an executable called '(.*)'$/ do |virtual_path, content|
|
6
|
+
path = expand(virtual_path)
|
7
|
+
create_file path, expand(content)
|
8
|
+
File.chmod(0755, path)
|
9
|
+
end
|
@@ -2,7 +2,7 @@ Given /^a repository '(.+)' with versions '(.+)'$/ do |basename, versions|
|
|
2
2
|
repository_path = make_repo_path(basename)
|
3
3
|
doc_name = basename.split('/').last.sub(/^vim-/, '')
|
4
4
|
variable_table["#{basename}_uri"] = make_repo_uri(basename)
|
5
|
-
|
5
|
+
sh <<-"END"
|
6
6
|
{
|
7
7
|
mkdir -p '#{repository_path}' &&
|
8
8
|
cd '#{repository_path}' &&
|
@@ -19,6 +19,15 @@ Given /^a repository '(.+)' with versions '(.+)'$/ do |basename, versions|
|
|
19
19
|
END
|
20
20
|
end
|
21
21
|
|
22
|
+
Given /^a repository '(.+)' from offline cache$/ do |repo_name|
|
23
|
+
repository_path = make_repo_path(repo_name)
|
24
|
+
sh <<-"END"
|
25
|
+
{
|
26
|
+
git clone 'vendor/#{repo_name}' '#{repository_path}'
|
27
|
+
} >/dev/null
|
28
|
+
END
|
29
|
+
end
|
30
|
+
|
22
31
|
Given /^I disable network to the original repository of '(.+)'$/ do |basename|
|
23
32
|
delete_path make_repo_path(basename)
|
24
33
|
end
|
data/features/support/env.rb
CHANGED
@@ -2,6 +2,8 @@ require 'fileutils'
|
|
2
2
|
require 'vim-flavor'
|
3
3
|
|
4
4
|
class FakeUserEnvironment
|
5
|
+
include Vim::Flavor::ShellUtility
|
6
|
+
|
5
7
|
def initialize()
|
6
8
|
env = self
|
7
9
|
Vim::Flavor::Flavor.instance_eval do
|
@@ -12,6 +14,7 @@ class FakeUserEnvironment
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def create_file path, content
|
17
|
+
FileUtils.mkdir_p(File.dirname(path))
|
15
18
|
File.open(path, 'w') do |f|
|
16
19
|
f.write(content)
|
17
20
|
end
|
@@ -47,3 +50,5 @@ end
|
|
47
50
|
World do
|
48
51
|
FakeUserEnvironment.new
|
49
52
|
end
|
53
|
+
|
54
|
+
ENV['THOR_DEBUG'] = '1' # To raise an exception as is.
|
@@ -0,0 +1,47 @@
|
|
1
|
+
## Short summary
|
2
|
+
|
3
|
+
1. Write tests for your Vim plugin with
|
4
|
+
[vim-vspec](https://github.com/kana/vim-vspec).
|
5
|
+
2. Declare dependencies of your Vim plugin as a [flavorfile](flavorfile), and
|
6
|
+
save it as `VimFlavor` in the root of your Vim plugin.
|
7
|
+
3. Run `vim-flavor test`.
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
## Long story
|
13
|
+
|
14
|
+
It is hard to test Vim plugins, because there are a few problems:
|
15
|
+
|
16
|
+
* It is hard to write readable and maintainable test code in Vim script, even
|
17
|
+
for skilled users. Because Vim script is not expressive as script languages
|
18
|
+
like Ruby and others.
|
19
|
+
* Each test must be run in an isolated environment to guarantee the same
|
20
|
+
results for every time and everywhere. So that all settings including vimrc
|
21
|
+
and plugins must be ignored. User's viminfo must not be read and written
|
22
|
+
too.
|
23
|
+
* Some plugins require other plugins at runtime. Such dependencies must be
|
24
|
+
resolved, but they must be installed into a temporary place to avoid
|
25
|
+
corrupting user's settings. And `'runtimepath'` must be configured
|
26
|
+
carefully for both dependencies and plugins under development.
|
27
|
+
|
28
|
+
Therefore it is hard to do right testing for Vim plugins from scratch. As
|
29
|
+
a lazy Vim user, I want to abstract all of the complexity.
|
30
|
+
|
31
|
+
Fortunately, the problems can be solved partially with
|
32
|
+
[vim-vspec](https://github.com/kana/vim-vspec), a testing framework for Vim
|
33
|
+
script. It provides a DSL based on Vim script to write readable test code.
|
34
|
+
It provides also a driver script to run tests. The driver script hides
|
35
|
+
details about the isolation of Vim processes and `'runtimepath'`
|
36
|
+
configuration.
|
37
|
+
|
38
|
+
However, vim-vspec is a tool to write tests, not a tool to set up environment
|
39
|
+
to test. So that it does nothing about dependencies. And it is painful to
|
40
|
+
manage dependencies by hand. But it is easy with vim-flavor. The complexity
|
41
|
+
can be hidden by combining both tools. That's why vim-flavor is integrated
|
42
|
+
with vim-vspec.
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
<!-- vim: set expandtab shiftwidth=4 softtabstop=4 textwidth=78 : -->
|
@@ -0,0 +1,61 @@
|
|
1
|
+
Feature: Dependencies
|
2
|
+
In order to easily test Vim plugins with dependencies,
|
3
|
+
As a lazy Vim user,
|
4
|
+
I want to hide details to do proper testing.
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given a temporary directory called 'tmp'
|
8
|
+
And a home directory called 'home' in '$tmp/home'
|
9
|
+
And a repository 'kana/vim-vspec' from offline cache
|
10
|
+
And a repository 'kana/vim-textobj-user' from offline cache
|
11
|
+
|
12
|
+
Scenario: Testing a Vim plugin with dependencies
|
13
|
+
Given flavorfile
|
14
|
+
"""
|
15
|
+
flavor 'kana/vim-textobj-user', '~> 0.3'
|
16
|
+
"""
|
17
|
+
And a file called '$tmp/plugin/textobj/date.vim'
|
18
|
+
"""
|
19
|
+
call textobj#user#plugin('date', {
|
20
|
+
\ '-': {
|
21
|
+
\ '*pattern*': '\v<\d{4}-\d{2}-\d{2}>',
|
22
|
+
\ 'select': ['ad', 'id'],
|
23
|
+
\ }
|
24
|
+
\ })
|
25
|
+
"""
|
26
|
+
And a file called '$tmp/t/basics.vim'
|
27
|
+
"""
|
28
|
+
" Tests are written with vim-vspec.
|
29
|
+
runtime! plugin/textobj/date.vim
|
30
|
+
describe 'Text object: date'
|
31
|
+
it 'is available in Visual mode'
|
32
|
+
Expect maparg('ad', 'v') != ''
|
33
|
+
end
|
34
|
+
end
|
35
|
+
"""
|
36
|
+
When I run `vim-flavor test`
|
37
|
+
Then it succeeds
|
38
|
+
And it outputs progress like
|
39
|
+
"""
|
40
|
+
-------- Preparing dependencies
|
41
|
+
Checking versions...
|
42
|
+
Use kana/vim-textobj-user ... 0.3.12
|
43
|
+
Use kana/vim-vspec ... 1.1.0
|
44
|
+
Deploying plugins...
|
45
|
+
kana/vim-textobj-user 0.3.12 ... done
|
46
|
+
kana/vim-vspec 1.1.0 ... done
|
47
|
+
-------- Testing a Vim plugin
|
48
|
+
Files=0, Tests=0, \d+ wallclock secs .*
|
49
|
+
Result: NOTESTS
|
50
|
+
t/basics.vim .. ok
|
51
|
+
All tests successful.
|
52
|
+
Files=1, Tests=1, \d+ wallclock secs .*
|
53
|
+
Result: PASS
|
54
|
+
"""
|
55
|
+
And I get lockfile
|
56
|
+
"""
|
57
|
+
kana/vim-textobj-user (0.3.12)
|
58
|
+
kana/vim-vspec (1.1.0)
|
59
|
+
"""
|
60
|
+
And it stores a dependency 'kana/vim-vspec' in '$tmp/.vim-flavor/deps'
|
61
|
+
And it stores a dependency 'kana/vim-textobj-user' in '$tmp/.vim-flavor/deps'
|
@@ -0,0 +1,61 @@
|
|
1
|
+
Feature: Typical usage
|
2
|
+
In order to easily test Vim plugins,
|
3
|
+
As a lazy Vim user,
|
4
|
+
I want to hide details to do proper testing.
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given a temporary directory called 'tmp'
|
8
|
+
And a home directory called 'home' in '$tmp/home'
|
9
|
+
And a repository 'kana/vim-vspec' from offline cache
|
10
|
+
|
11
|
+
Scenario: Testing a Vim plugin without any dependency
|
12
|
+
Given flavorfile
|
13
|
+
"""
|
14
|
+
# No dependency
|
15
|
+
"""
|
16
|
+
And a file called '$tmp/plugin/foo.vim'
|
17
|
+
"""
|
18
|
+
let g:foo = 3
|
19
|
+
"""
|
20
|
+
And a file called '$tmp/t/basics.vim'
|
21
|
+
"""
|
22
|
+
" Tests are written with vim-vspec.
|
23
|
+
runtime! plugin/foo.vim
|
24
|
+
describe 'g:foo'
|
25
|
+
it 'is equal to 3'
|
26
|
+
Expect g:foo == 3
|
27
|
+
end
|
28
|
+
end
|
29
|
+
"""
|
30
|
+
And an executable called '$tmp/t/sh.t'
|
31
|
+
"""
|
32
|
+
#!/bin/bash
|
33
|
+
# It is also possible to write tests with arbitrary tools.
|
34
|
+
# Such tests must output results in Test Anything Protocol.
|
35
|
+
echo 'ok 1'
|
36
|
+
echo '1..1'
|
37
|
+
"""
|
38
|
+
When I run `vim-flavor test`
|
39
|
+
Then it succeeds
|
40
|
+
And it outputs progress like
|
41
|
+
"""
|
42
|
+
-------- Preparing dependencies
|
43
|
+
Checking versions...
|
44
|
+
Use kana/vim-vspec ... 1.1.0
|
45
|
+
Deploying plugins...
|
46
|
+
kana/vim-vspec 1.1.0 ... done
|
47
|
+
-------- Testing a Vim plugin
|
48
|
+
t/sh.t .. ok
|
49
|
+
All tests successful.
|
50
|
+
Files=1, Tests=1, \d+ wallclock secs .*
|
51
|
+
Result: PASS
|
52
|
+
t/basics.vim .. ok
|
53
|
+
All tests successful.
|
54
|
+
Files=1, Tests=1, \d+ wallclock secs .*
|
55
|
+
Result: PASS
|
56
|
+
"""
|
57
|
+
And I get lockfile
|
58
|
+
"""
|
59
|
+
kana/vim-vspec (1.1.0)
|
60
|
+
"""
|
61
|
+
And it stores a dependency 'kana/vim-vspec' in '$tmp/.vim-flavor/deps'
|
@@ -44,7 +44,7 @@ and `vim-flavor` does it.
|
|
44
44
|
The file is called a flavorfile. A flavorfile contains zero or more
|
45
45
|
declarations about Vim plugins and which versions of Vim plugins to use.
|
46
46
|
|
47
|
-
See also [
|
47
|
+
See also [more details about flavorfile](flavorfile).
|
48
48
|
|
49
49
|
|
50
50
|
|
data/lib/vim-flavor/cli.rb
CHANGED
@@ -3,10 +3,14 @@ require 'thor'
|
|
3
3
|
module Vim
|
4
4
|
module Flavor
|
5
5
|
class CLI < Thor
|
6
|
+
def self.common_options_to_deploy
|
7
|
+
method_option :vimfiles_path,
|
8
|
+
:desc => 'Where to install Vim plugins.',
|
9
|
+
:banner => 'DIR'
|
10
|
+
end
|
11
|
+
|
6
12
|
desc 'install', 'Install Vim plugins according to VimFlavor file.'
|
7
|
-
|
8
|
-
:desc => 'Where to install Vim plugins.',
|
9
|
-
:banner => 'DIR'
|
13
|
+
common_options_to_deploy
|
10
14
|
def install
|
11
15
|
Facade.new().install(
|
12
16
|
options[:vimfiles_path] || default_vimfiles_path
|
@@ -14,19 +18,32 @@ module Vim
|
|
14
18
|
end
|
15
19
|
|
16
20
|
desc 'upgrade', 'Upgrade Vim plugins according to VimFlavor file.'
|
17
|
-
|
18
|
-
:desc => 'Where to install Vim plugins.',
|
19
|
-
:banner => 'DIR'
|
21
|
+
common_options_to_deploy
|
20
22
|
def upgrade
|
21
23
|
Facade.new().upgrade(
|
22
24
|
options[:vimfiles_path] || default_vimfiles_path
|
23
25
|
)
|
24
26
|
end
|
25
27
|
|
28
|
+
desc 'test', 'Test a Vim plugin in the current working directory.'
|
29
|
+
def test
|
30
|
+
Facade.new().test()
|
31
|
+
end
|
32
|
+
|
26
33
|
no_tasks do
|
27
34
|
def default_vimfiles_path
|
28
35
|
ENV['HOME'].to_vimfiles_path
|
29
36
|
end
|
37
|
+
|
38
|
+
def normalize_groups(s)
|
39
|
+
groups =
|
40
|
+
(s || '').
|
41
|
+
split(/,/).
|
42
|
+
map(&:strip).
|
43
|
+
reject(&:empty?).
|
44
|
+
map(&:to_sym)
|
45
|
+
0 < groups.length ? groups : nil
|
46
|
+
end
|
30
47
|
end
|
31
48
|
end
|
32
49
|
end
|
data/lib/vim-flavor/facade.rb
CHANGED
@@ -3,6 +3,8 @@ require 'fileutils'
|
|
3
3
|
module Vim
|
4
4
|
module Flavor
|
5
5
|
class Facade
|
6
|
+
include ShellUtility
|
7
|
+
|
6
8
|
def trace message
|
7
9
|
print message
|
8
10
|
end
|
@@ -20,7 +22,10 @@ module Vim
|
|
20
22
|
)
|
21
23
|
lockfile.save()
|
22
24
|
|
23
|
-
deploy_flavors(
|
25
|
+
deploy_flavors(
|
26
|
+
lockfile.flavors.select {|f| f.group == :runtime},
|
27
|
+
vimfiles_path.to_flavors_path
|
28
|
+
)
|
24
29
|
|
25
30
|
trace "Completed.\n"
|
26
31
|
end
|
@@ -61,27 +66,27 @@ module Vim
|
|
61
66
|
completed_flavor_table
|
62
67
|
end
|
63
68
|
|
64
|
-
def deploy_flavors(flavors,
|
69
|
+
def deploy_flavors(flavors, flavors_path)
|
65
70
|
trace "Deploying plugins...\n"
|
66
71
|
|
67
72
|
FileUtils.rm_rf(
|
68
|
-
[
|
73
|
+
[flavors_path],
|
69
74
|
:secure => true
|
70
75
|
)
|
71
76
|
|
72
|
-
create_vim_script_for_bootstrap(
|
77
|
+
create_vim_script_for_bootstrap(flavors_path)
|
73
78
|
|
74
79
|
flavors.
|
75
80
|
before_each {|f| trace " #{f.repo_name} #{f.locked_version} ..."}.
|
76
81
|
after_each {|f| trace " done\n"}.
|
77
82
|
on_failure {trace " failed\n"}.
|
78
83
|
each do |f|
|
79
|
-
f.deploy(
|
84
|
+
f.deploy(flavors_path)
|
80
85
|
end
|
81
86
|
end
|
82
87
|
|
83
|
-
def create_vim_script_for_bootstrap(
|
84
|
-
bootstrap_path =
|
88
|
+
def create_vim_script_for_bootstrap(flavors_path)
|
89
|
+
bootstrap_path = flavors_path.to_bootstrap_path
|
85
90
|
FileUtils.mkdir_p(File.dirname(bootstrap_path))
|
86
91
|
File.open(bootstrap_path, 'w') do |f|
|
87
92
|
f.write(<<-'END')
|
@@ -113,6 +118,45 @@ module Vim
|
|
113
118
|
END
|
114
119
|
end
|
115
120
|
end
|
121
|
+
|
122
|
+
def test()
|
123
|
+
trace "-------- Preparing dependencies\n"
|
124
|
+
|
125
|
+
flavorfile = FlavorFile.load_or_new(Dir.getwd().to_flavorfile_path)
|
126
|
+
flavorfile.flavor 'kana/vim-vspec', '~> 1.0', :group => :development unless
|
127
|
+
flavorfile.flavor_table.has_key?('kana/vim-vspec')
|
128
|
+
lockfile = LockFile.load_or_new(Dir.getwd().to_lockfile_path)
|
129
|
+
|
130
|
+
lockfile.update(
|
131
|
+
complete(
|
132
|
+
flavorfile.flavor_table,
|
133
|
+
lockfile.flavor_table,
|
134
|
+
:install
|
135
|
+
)
|
136
|
+
)
|
137
|
+
lockfile.save()
|
138
|
+
|
139
|
+
# FIXME: It's somewhat wasteful to refresh flavors every time.
|
140
|
+
deploy_flavors(
|
141
|
+
lockfile.flavors,
|
142
|
+
Dir.getwd().to_stash_path.to_deps_path
|
143
|
+
)
|
144
|
+
|
145
|
+
trace "-------- Testing a Vim plugin\n"
|
146
|
+
|
147
|
+
prove_options = '--comments --failure --directives'
|
148
|
+
deps_path = Dir.getwd().to_stash_path.to_deps_path
|
149
|
+
vspec = "#{deps_path}/#{'kana/vim-vspec'.zap}/bin/vspec"
|
150
|
+
plugin_paths = lockfile.flavors.map {|f|
|
151
|
+
"#{deps_path}/#{f.repo_name.zap}"
|
152
|
+
}
|
153
|
+
# FIXME: Testing messages are not outputted in real time.
|
154
|
+
print sh %Q{
|
155
|
+
prove --ext '.t' #{prove_options} &&
|
156
|
+
prove --ext '.vim' #{prove_options} \
|
157
|
+
--exec '#{vspec} #{Dir.getwd()} #{plugin_paths.join(' ')}'
|
158
|
+
}
|
159
|
+
end
|
116
160
|
end
|
117
161
|
end
|
118
162
|
end
|
data/lib/vim-flavor/flavor.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Vim
|
2
2
|
module Flavor
|
3
3
|
class Flavor
|
4
|
+
include ShellUtility
|
5
|
+
|
4
6
|
# A short name of a repository.
|
5
7
|
# Possible formats are "$user/$repo", "$repo" and "$repo_uri".
|
6
8
|
attr_accessor :repo_name
|
@@ -8,6 +10,9 @@ module Vim
|
|
8
10
|
# A constraint to choose a proper version.
|
9
11
|
attr_accessor :version_constraint
|
10
12
|
|
13
|
+
# A group which this flavor belongs to.
|
14
|
+
attr_accessor :group
|
15
|
+
|
11
16
|
# A version of a plugin to be installed.
|
12
17
|
attr_accessor :locked_version
|
13
18
|
|
@@ -61,8 +66,8 @@ module Vim
|
|
61
66
|
}
|
62
67
|
end
|
63
68
|
|
64
|
-
def deploy(
|
65
|
-
deployment_path = "#{
|
69
|
+
def deploy(flavors_path)
|
70
|
+
deployment_path = "#{flavors_path}/#{repo_name.zap}"
|
66
71
|
sh %Q[
|
67
72
|
{
|
68
73
|
cd '#{cached_repo_path}' &&
|
@@ -108,15 +113,6 @@ module Vim
|
|
108
113
|
versions_from_tags(list_tags())
|
109
114
|
end
|
110
115
|
|
111
|
-
def sh script
|
112
|
-
output = send(:`, script)
|
113
|
-
if $? == 0
|
114
|
-
output
|
115
|
-
else
|
116
|
-
raise RuntimeError, output
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
116
|
def satisfied_with?(locked_flavor)
|
121
117
|
repo_name == locked_flavor.repo_name &&
|
122
118
|
version_constraint.compatible?(locked_flavor.locked_version)
|
@@ -6,6 +6,20 @@ module Vim
|
|
6
6
|
@flavor_table ||= {}
|
7
7
|
end
|
8
8
|
|
9
|
+
def default_groups
|
10
|
+
@default_groups ||= [:runtime]
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_group
|
14
|
+
default_groups.last
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.load_or_new(flavorfile_path)
|
18
|
+
ff = new()
|
19
|
+
ff.load(flavorfile_path) if File.exists?(flavorfile_path)
|
20
|
+
ff
|
21
|
+
end
|
22
|
+
|
9
23
|
def self.load(flavorfile_path)
|
10
24
|
ff = new()
|
11
25
|
ff.load(flavorfile_path)
|
@@ -19,12 +33,31 @@ module Vim
|
|
19
33
|
)
|
20
34
|
end
|
21
35
|
|
22
|
-
|
36
|
+
# :call-seq:
|
37
|
+
# flavor repo_name, version_constraint='>= 0', options={} -> a_flavor
|
38
|
+
def flavor(repo_name, *args)
|
39
|
+
a = args.shift()
|
40
|
+
if a.kind_of?(String)
|
41
|
+
version_constraint = a
|
42
|
+
a = args.shift()
|
43
|
+
else
|
44
|
+
version_constraint = '>= 0'
|
45
|
+
end
|
46
|
+
options = a.kind_of?(Hash) ? a : {}
|
47
|
+
|
23
48
|
f = Flavor.new()
|
24
49
|
f.repo_name = repo_name
|
25
50
|
f.version_constraint = VersionConstraint.new(version_constraint)
|
51
|
+
f.group = options[:group] || default_group
|
26
52
|
flavor_table[f.repo_name] = f
|
27
53
|
end
|
54
|
+
|
55
|
+
def group(group, &block)
|
56
|
+
default_groups.push(group)
|
57
|
+
instance_eval &block
|
58
|
+
ensure
|
59
|
+
default_groups.pop()
|
60
|
+
end
|
28
61
|
end
|
29
62
|
end
|
30
63
|
end
|
data/lib/vim-flavor/version.rb
CHANGED
data/lib/vim-flavor.rb
CHANGED
data/spec/facade_spec.rb
CHANGED
@@ -14,15 +14,15 @@ module Vim
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'creates a bootstrap script to configure runtimepath for flavors' do
|
17
|
-
|
18
|
-
Facade.new().create_vim_script_for_bootstrap(
|
17
|
+
flavors_path = @tmp_path.to_vimfiles_path.to_flavors_path
|
18
|
+
Facade.new().create_vim_script_for_bootstrap(flavors_path)
|
19
19
|
|
20
|
-
File.should exist(
|
20
|
+
File.should exist(flavors_path.to_bootstrap_path)
|
21
21
|
|
22
22
|
_rtp = %x{
|
23
23
|
for plugin_name in 'foo' 'bar' 'baz'
|
24
24
|
do
|
25
|
-
mkdir -p "#{
|
25
|
+
mkdir -p "#{flavors_path}/$plugin_name"
|
26
26
|
done
|
27
27
|
HOME='#{@tmp_path}' vim -u NONE -i NONE -n -N -e -s -c '
|
28
28
|
set verbose=1
|
data/spec/flavorfile_spec.rb
CHANGED
@@ -4,20 +4,86 @@ module Vim
|
|
4
4
|
module Flavor
|
5
5
|
describe FlavorFile do
|
6
6
|
describe '#flavor' do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
let(:ff) {FlavorFile.new()}
|
8
|
+
|
9
|
+
context 'basics' do
|
10
|
+
it 'registers a flavor' do
|
11
|
+
ff.flavor 'kana/vim-altr', '>= 1.2.3'
|
12
|
+
f = ff.flavor_table['kana/vim-altr']
|
13
|
+
f.repo_name.should == 'kana/vim-altr'
|
14
|
+
f.version_constraint.should == VersionConstraint.new('>= 1.2.3')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'completes version constraint if it is not given' do
|
18
|
+
ff.flavor 'kana/vim-altr'
|
19
|
+
f = ff.flavor_table['kana/vim-altr']
|
20
|
+
f.repo_name.should == 'kana/vim-altr'
|
21
|
+
f.version_constraint.should == VersionConstraint.new('>= 0')
|
22
|
+
end
|
13
23
|
end
|
14
24
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
25
|
+
context 'group option' do
|
26
|
+
it 'supports a group option with a version constraint' do
|
27
|
+
ff.flavor 'kana/vim-vspec', '~> 1.0', :group => :development
|
28
|
+
f = ff.flavor_table['kana/vim-vspec']
|
29
|
+
f.version_constraint.should == VersionConstraint.new('~> 1.0')
|
30
|
+
f.group.should == :development
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'supports a group option without version constraint' do
|
34
|
+
ff.flavor 'kana/vim-vspec', :group => :development
|
35
|
+
f = ff.flavor_table['kana/vim-vspec']
|
36
|
+
f.version_constraint.should == VersionConstraint.new('>= 0')
|
37
|
+
f.group.should == :development
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'uses :default as the default group' do
|
41
|
+
ff.flavor 'kana/vim-vspec'
|
42
|
+
f = ff.flavor_table['kana/vim-vspec']
|
43
|
+
f.group.should == :runtime
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'group block' do
|
48
|
+
it 'changes the default group for flavors in a given block' do
|
49
|
+
ff.flavor 'a'
|
50
|
+
ff.group :outer do
|
51
|
+
flavor 'b'
|
52
|
+
group :inner do
|
53
|
+
flavor 'c'
|
54
|
+
end
|
55
|
+
flavor 'd'
|
56
|
+
end
|
57
|
+
ff.flavor 'e'
|
58
|
+
|
59
|
+
ff.flavor_table['a'].group.should == :runtime
|
60
|
+
ff.flavor_table['b'].group.should == :outer
|
61
|
+
ff.flavor_table['c'].group.should == :inner
|
62
|
+
ff.flavor_table['d'].group.should == :outer
|
63
|
+
ff.flavor_table['e'].group.should == :runtime
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'restores the default group even if an exception is raised' do
|
67
|
+
ff.flavor 'a'
|
68
|
+
ff.group :outer do
|
69
|
+
begin
|
70
|
+
flavor 'b'
|
71
|
+
group :inner do
|
72
|
+
raise RuntimeError
|
73
|
+
flavor 'c'
|
74
|
+
end
|
75
|
+
rescue
|
76
|
+
end
|
77
|
+
flavor 'd'
|
78
|
+
end
|
79
|
+
ff.flavor 'e'
|
80
|
+
|
81
|
+
ff.flavor_table['a'].group.should == :runtime
|
82
|
+
ff.flavor_table['b'].group.should == :outer
|
83
|
+
ff.flavor_table['c'].should be_nil
|
84
|
+
ff.flavor_table['d'].group.should == :outer
|
85
|
+
ff.flavor_table['e'].group.should == :runtime
|
86
|
+
end
|
21
87
|
end
|
22
88
|
end
|
23
89
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vim-flavor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parslet
|
@@ -84,6 +84,7 @@ extensions: []
|
|
84
84
|
extra_rdoc_files: []
|
85
85
|
files:
|
86
86
|
- .gitignore
|
87
|
+
- .gitmodules
|
87
88
|
- .rspec
|
88
89
|
- .travis.yml
|
89
90
|
- Gemfile
|
@@ -98,6 +99,7 @@ files:
|
|
98
99
|
- features/command_line/progress_messages.feature
|
99
100
|
- features/flavorfile/README.md
|
100
101
|
- features/flavorfile/comments.feature
|
102
|
+
- features/flavorfile/groups.feature
|
101
103
|
- features/flavorfile/repository_name.feature
|
102
104
|
- features/flavorfile/version_constraint.feature
|
103
105
|
- features/install_vim_flavor.md
|
@@ -105,11 +107,16 @@ files:
|
|
105
107
|
- features/resolve_dependencies.feature
|
106
108
|
- features/step_definitions/bootstrap_script_steps.rb
|
107
109
|
- features/step_definitions/cli_steps.rb
|
110
|
+
- features/step_definitions/dependency_steps.rb
|
108
111
|
- features/step_definitions/directory_steps.rb
|
112
|
+
- features/step_definitions/file_steps.rb
|
109
113
|
- features/step_definitions/flavor_steps.rb
|
110
114
|
- features/step_definitions/flavorfile_steps.rb
|
111
115
|
- features/step_definitions/lockfile_steps.rb
|
112
116
|
- features/support/env.rb
|
117
|
+
- features/testing_vim_plugins/README.md
|
118
|
+
- features/testing_vim_plugins/dependencies.feature
|
119
|
+
- features/testing_vim_plugins/typical_usage.feature
|
113
120
|
- features/typical_usage/README.md
|
114
121
|
- features/typical_usage/deploy_to_arbitrary_place.feature
|
115
122
|
- features/typical_usage/install_vim_plugins.feature
|
@@ -125,6 +132,7 @@ files:
|
|
125
132
|
- lib/vim-flavor/flavorfile.rb
|
126
133
|
- lib/vim-flavor/lockfile.rb
|
127
134
|
- lib/vim-flavor/lockfileparser.rb
|
135
|
+
- lib/vim-flavor/shellutility.rb
|
128
136
|
- lib/vim-flavor/stringextension.rb
|
129
137
|
- lib/vim-flavor/version.rb
|
130
138
|
- lib/vim-flavor/versionconstraint.rb
|
@@ -168,6 +176,7 @@ test_files:
|
|
168
176
|
- features/command_line/progress_messages.feature
|
169
177
|
- features/flavorfile/README.md
|
170
178
|
- features/flavorfile/comments.feature
|
179
|
+
- features/flavorfile/groups.feature
|
171
180
|
- features/flavorfile/repository_name.feature
|
172
181
|
- features/flavorfile/version_constraint.feature
|
173
182
|
- features/install_vim_flavor.md
|
@@ -175,11 +184,16 @@ test_files:
|
|
175
184
|
- features/resolve_dependencies.feature
|
176
185
|
- features/step_definitions/bootstrap_script_steps.rb
|
177
186
|
- features/step_definitions/cli_steps.rb
|
187
|
+
- features/step_definitions/dependency_steps.rb
|
178
188
|
- features/step_definitions/directory_steps.rb
|
189
|
+
- features/step_definitions/file_steps.rb
|
179
190
|
- features/step_definitions/flavor_steps.rb
|
180
191
|
- features/step_definitions/flavorfile_steps.rb
|
181
192
|
- features/step_definitions/lockfile_steps.rb
|
182
193
|
- features/support/env.rb
|
194
|
+
- features/testing_vim_plugins/README.md
|
195
|
+
- features/testing_vim_plugins/dependencies.feature
|
196
|
+
- features/testing_vim_plugins/typical_usage.feature
|
183
197
|
- features/typical_usage/README.md
|
184
198
|
- features/typical_usage/deploy_to_arbitrary_place.feature
|
185
199
|
- features/typical_usage/install_vim_plugins.feature
|