vim-flavor 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.rspec +1 -0
  2. data/.travis.yml +4 -0
  3. data/README.md +3 -174
  4. data/Rakefile +10 -0
  5. data/features/.nav +12 -0
  6. data/features/README.md +17 -0
  7. data/features/caching.feature +50 -0
  8. data/features/command_line/README.md +9 -0
  9. data/features/command_line/progress_messages.feature +44 -0
  10. data/features/flavorfile/README.md +9 -0
  11. data/features/flavorfile/comments.feature +24 -0
  12. data/features/flavorfile/repository_name.feature +53 -0
  13. data/features/flavorfile/version_constraint.feature +52 -0
  14. data/features/install_vim_flavor.md +42 -0
  15. data/features/philosophy.md +90 -0
  16. data/features/resolve_dependencies.feature +16 -0
  17. data/features/step_definitions/bootstrap_script_steps.rb +7 -0
  18. data/features/step_definitions/cli_steps.rb +34 -0
  19. data/features/step_definitions/directory_steps.rb +23 -0
  20. data/features/step_definitions/flavor_steps.rb +37 -0
  21. data/features/step_definitions/flavorfile_steps.rb +12 -0
  22. data/features/step_definitions/lockfile_steps.rb +13 -0
  23. data/features/support/env.rb +49 -0
  24. data/features/typical_usage/README.md +63 -0
  25. data/features/typical_usage/deploy_to_arbitrary_place.feature +24 -0
  26. data/features/typical_usage/install_vim_plugins.feature +26 -0
  27. data/features/typical_usage/uninstall_vim_plugins.feature +31 -0
  28. data/features/typical_usage/upgrade_vim_plugins.feature +27 -0
  29. data/features/uninstall_vim_flavor.md +16 -0
  30. data/features/version_lock.feature +26 -0
  31. data/lib/vim-flavor.rb +2 -12
  32. data/lib/vim-flavor/cli.rb +16 -12
  33. data/lib/vim-flavor/enumerableextension.rb +48 -0
  34. data/lib/vim-flavor/facade.rb +65 -102
  35. data/lib/vim-flavor/flavor.rb +70 -63
  36. data/lib/vim-flavor/flavorfile.rb +15 -47
  37. data/lib/vim-flavor/lockfile.rb +27 -44
  38. data/lib/vim-flavor/lockfileparser.rb +65 -0
  39. data/lib/vim-flavor/stringextension.rb +25 -1
  40. data/lib/vim-flavor/version.rb +1 -1
  41. data/lib/vim-flavor/versionconstraint.rb +12 -11
  42. data/spec/enumerableextension_spec.rb +100 -0
  43. data/spec/facade_spec.rb +49 -540
  44. data/spec/flavor_spec.rb +50 -250
  45. data/spec/flavorfile_spec.rb +34 -110
  46. data/spec/lockfile_spec.rb +79 -89
  47. data/spec/spec_helper.rb +0 -65
  48. data/spec/stringextension_spec.rb +10 -6
  49. data/spec/versionconstraint_spec.rb +37 -119
  50. data/vim-flavor.gemspec +3 -1
  51. metadata +135 -46
  52. data/spec/cli_spec.rb +0 -15
@@ -1,61 +1,29 @@
1
1
  module Vim
2
2
  module Flavor
3
3
  class FlavorFile
4
- attr_reader :flavors
5
-
6
- def initialize()
7
- @flavors = {}
8
- @default_groups = [:default]
9
- end
10
-
11
- def interpret(&block)
12
- instance_eval(&block)
4
+ # repo_name -> flavor
5
+ def flavor_table
6
+ @flavor_table ||= {}
13
7
  end
14
8
 
15
- def eval_flavorfile(flavorfile_path)
16
- content = File.open(flavorfile_path, 'rb') do |f|
17
- f.read()
18
- end
19
- interpret do
20
- instance_eval(content)
21
- end
9
+ def self.load(flavorfile_path)
10
+ ff = new()
11
+ ff.load(flavorfile_path)
12
+ ff
22
13
  end
23
14
 
24
- def repo_uri_from_repo_name(repo_name)
25
- if /^([^\/]+)$/.match(repo_name) then
26
- m = Regexp.last_match
27
- "git://github.com/vim-scripts/#{m[1]}.git"
28
- elsif /^([A-Za-z0-9_-]+)\/(.*)$/.match(repo_name) then
29
- m = Regexp.last_match
30
- "git://github.com/#{m[1]}/#{m[2]}.git"
31
- elsif /^[a-z]+:\/\/.*$/.match(repo_name) then
32
- repo_name
33
- else
34
- raise "repo_name is written in invalid format: #{repo_name.inspect}"
35
- end
15
+ def load(flavorfile_path)
16
+ instance_eval(
17
+ File.open(flavorfile_path, 'r').read(),
18
+ flavorfile_path
19
+ )
36
20
  end
37
21
 
38
- def flavor(repo_name, *args)
39
- options = Hash === args.last ? args.pop : {}
40
- options[:groups] ||= []
41
- version_contraint = VersionConstraint.new(args.last || '>= 0')
42
-
22
+ def flavor(repo_name, version_constraint='>= 0')
43
23
  f = Flavor.new()
44
24
  f.repo_name = repo_name
45
- f.repo_uri = repo_uri_from_repo_name(repo_name)
46
- f.version_contraint = version_contraint
47
- f.groups = @default_groups + options[:groups]
48
-
49
- @flavors[f.repo_uri] = f
50
- end
51
-
52
- def group(*group_names, &block)
53
- @default_groups.concat(group_names)
54
- yield
55
- ensure
56
- group_names.each do
57
- @default_groups.pop()
58
- end
25
+ f.version_constraint = VersionConstraint.new(version_constraint)
26
+ flavor_table[f.repo_name] = f
59
27
  end
60
28
  end
61
29
  end
@@ -1,63 +1,46 @@
1
- require 'yaml'
2
-
3
1
  module Vim
4
2
  module Flavor
5
3
  class LockFile
6
- # TODO: Resolve dependencies recursively.
7
-
8
- attr_reader :flavors, :path
4
+ def self.load_or_new(lockfile_path)
5
+ l = new(lockfile_path)
6
+ l.load() if File.exists?(lockfile_path)
7
+ l
8
+ end
9
9
 
10
10
  def initialize(path)
11
- @flavors = {} # repo_uri => flavor
12
11
  @path = path
13
12
  end
14
13
 
15
- def load()
16
- h = File.open(@path, 'rb') do |f|
17
- YAML.load(f.read())
18
- end
19
-
20
- @flavors = self.class.flavors_from_poro(h[:flavors])
14
+ def flavor_table
15
+ @flavor_table ||= {}
21
16
  end
22
17
 
23
- def save()
24
- h = {}
18
+ def flavors
19
+ flavor_table.values.sort_by {|f| f.repo_name}
20
+ end
25
21
 
26
- h[:flavors] = self.class.poro_from_flavors(@flavors)
22
+ def load()
23
+ s = File.open(@path, 'r') {|io| io.read()}
24
+ @flavor_table =
25
+ Hash[LockFileParser.parse(s).map {|f| [f.repo_name, f]}]
26
+ end
27
27
 
28
- File.open(@path, 'wb') do |f|
29
- YAML.dump(h, f)
30
- end
28
+ def update(completed_flavor_table)
29
+ @flavor_table = completed_flavor_table
31
30
  end
32
31
 
33
- def self.poro_from_flavors(flavors)
34
- Hash[
35
- flavors.values.map {|f|
36
- [
37
- f.repo_uri,
38
- {
39
- :groups => f.groups,
40
- :locked_version => f.locked_version.to_s(),
41
- :repo_name => f.repo_name,
42
- :version_contraint => f.version_contraint.to_s(),
43
- }
44
- ]
45
- }
46
- ]
32
+ def self.serialize_lock_status(flavor)
33
+ ["#{flavor.repo_name} (#{flavor.locked_version})"]
47
34
  end
48
35
 
49
- def self.flavors_from_poro(poro)
50
- Hash[
51
- poro.to_a().map {|repo_uri, h|
52
- f = Flavor.new()
53
- f.groups = h[:groups]
54
- f.locked_version = Gem::Version.create(h[:locked_version])
55
- f.repo_name = h[:repo_name]
56
- f.repo_uri = repo_uri
57
- f.version_contraint = VersionConstraint.new(h[:version_contraint])
58
- [f.repo_uri, f]
59
- }
60
- ]
36
+ def save()
37
+ File.open(@path, 'w') do |io|
38
+ lines = flavors.flat_map {|f| self.class.serialize_lock_status(f)}
39
+ lines.each do |line|
40
+ io.write(line)
41
+ io.write("\n")
42
+ end
43
+ end
61
44
  end
62
45
  end
63
46
  end
@@ -0,0 +1,65 @@
1
+ require 'parslet'
2
+
3
+ module Vim
4
+ module Flavor
5
+ class LockFileParser
6
+ def self.parse(s)
7
+ Transformer.new.apply(Parser.new().parse(s))[:lockfile]
8
+ end
9
+
10
+ class Parser < Parslet::Parser
11
+ root(:lockfile)
12
+
13
+ rule(:lockfile) {
14
+ space? >> newline.maybe >>
15
+ (
16
+ (
17
+ flavor >> (newline | eof)
18
+ ).repeat(0).as(:lockfile)
19
+ )
20
+ }
21
+
22
+ rule(:flavor) {
23
+ (
24
+ space? >>
25
+ repo_name >> space? >>
26
+ str('(') >> space? >>
27
+ locked_version >> space? >>
28
+ str(')') >> space?
29
+ ).as(:flavor)
30
+ }
31
+
32
+ rule(:repo_name) {
33
+ (
34
+ match('\w') >>
35
+ match('[^ \t()]').repeat(0)
36
+ ).as(:repo_name)
37
+ }
38
+ rule(:locked_version) {
39
+ (
40
+ match('[\d.]').repeat(1)
41
+ ).as(:locked_version)
42
+ }
43
+
44
+ rule(:space) {match('[ \t]').repeat(1)}
45
+ rule(:space?) {space.maybe}
46
+ rule(:newline) {match('[\r\n]').repeat(1)}
47
+ rule(:eof) {any.absent?}
48
+ end
49
+
50
+ class Transformer < Parslet::Transform
51
+ rule(
52
+ :flavor => {
53
+ :repo_name => simple(:repo_name),
54
+ :locked_version => simple(:locked_version),
55
+ }
56
+ ) {
57
+ f = Flavor.new()
58
+ f.repo_name = repo_name.to_s
59
+ f.locked_version = locked_version.to_s
60
+ f
61
+ }
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,9 +1,33 @@
1
1
  module Vim
2
2
  module Flavor
3
3
  module StringExtension
4
- def to_flavors_path()
4
+ def to_bootstrap_path
5
+ "#{self}/bootstrap.vim"
6
+ end
7
+
8
+ def to_flavorfile_path
9
+ "#{self}/VimFlavor"
10
+ end
11
+
12
+ def to_flavors_path
5
13
  "#{self}/flavors"
6
14
  end
15
+
16
+ def to_lockfile_path
17
+ "#{self}/VimFlavor.lock"
18
+ end
19
+
20
+ def to_stash_path
21
+ "#{self}/.vim-flavor"
22
+ end
23
+
24
+ def to_vimfiles_path
25
+ "#{self}/.vim"
26
+ end
27
+
28
+ def zap
29
+ gsub(/[^A-Za-z0-9._-]/, '_')
30
+ end
7
31
  end
8
32
  end
9
33
  end
@@ -1,5 +1,5 @@
1
1
  module Vim
2
2
  module Flavor
3
- VERSION = '0.0.4'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -1,24 +1,27 @@
1
1
  module Vim
2
2
  module Flavor
3
3
  class VersionConstraint
4
- attr_reader :base_version, :operator
4
+ attr_reader :base_version
5
+
6
+ # Specifies how to choose a suitable version according to base_version.
7
+ attr_reader :qualifier
5
8
 
6
9
  def initialize(s)
7
- @base_version, @operator = parse(s)
10
+ @base_version, @qualifier = self.class.parse(s)
8
11
  end
9
12
 
10
13
  def to_s()
11
- "#{@operator} #{@base_version}"
14
+ "#{qualifier} #{base_version}"
12
15
  end
13
16
 
14
17
  def ==(other)
15
18
  self.base_version == other.base_version &&
16
- self.operator == other.operator
19
+ self.qualifier == other.qualifier
17
20
  end
18
21
 
19
- def parse(s)
22
+ def self.parse(s)
20
23
  m = /^\s*(>=|~>)\s+(\S+)$/.match(s)
21
- if m then
24
+ if m
22
25
  [Gem::Version.create(m[2]), m[1]]
23
26
  else
24
27
  raise "Invalid version constraint: #{s.inspect}"
@@ -27,9 +30,9 @@ module Vim
27
30
 
28
31
  def compatible?(other_version_or_s)
29
32
  v = Gem::Version.create(other_version_or_s)
30
- if @operator == '~>' then
33
+ if qualifier == '~>'
31
34
  self.base_version.bump() > v and v >= self.base_version
32
- elsif @operator == '>=' then
35
+ elsif qualifier == '>='
33
36
  v >= self.base_version
34
37
  else
35
38
  raise NotImplementedError
@@ -39,9 +42,7 @@ module Vim
39
42
  def find_the_best_version(versions)
40
43
  versions.
41
44
  select {|v| compatible?(v)}.
42
- sort().
43
- reverse().
44
- first
45
+ max()
45
46
  end
46
47
  end
47
48
  end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+
3
+ module Vim
4
+ module Flavor
5
+ describe EnumerableExtension do
6
+ describe '#before_each' do
7
+ it 'runs a given block before enumerating each element' do
8
+ xs = []
9
+ [1, 2, 3].
10
+ before_each {|n| xs << "before_each #{n}"}.
11
+ each do |n|
12
+ xs << "each #{n}"
13
+ end
14
+
15
+ xs.should == [
16
+ "before_each 1",
17
+ "each 1",
18
+ "before_each 2",
19
+ "each 2",
20
+ "before_each 3",
21
+ "each 3",
22
+ ]
23
+ end
24
+ end
25
+
26
+ describe '#after_each' do
27
+ it 'runs a given block after enumerating each element' do
28
+ xs = []
29
+ [1, 2, 3].
30
+ after_each {|n| xs << "after_each #{n}"}.
31
+ each do |n|
32
+ xs << "each #{n}"
33
+ end
34
+
35
+ xs.should == [
36
+ "each 1",
37
+ "after_each 1",
38
+ "each 2",
39
+ "after_each 2",
40
+ "each 3",
41
+ "after_each 3",
42
+ ]
43
+ end
44
+ end
45
+
46
+ describe '#on_failure' do
47
+ it 'runs a given block if a core block raises an exception' do
48
+ xs = []
49
+
50
+ expect {
51
+ [1, 2, 3].
52
+ on_failure {|n| xs << "on_failure #{n}"}.
53
+ each do |n|
54
+ xs << "each enter #{n}"
55
+ raise RuntimeError, "bang! #{n}" if 2 < n
56
+ xs << "each leave #{n}"
57
+ end
58
+ }.to raise_error(RuntimeError, 'bang! 3')
59
+
60
+ xs.should == [
61
+ "each enter 1",
62
+ "each leave 1",
63
+ "each enter 2",
64
+ "each leave 2",
65
+ "each enter 3",
66
+ "on_failure 3",
67
+ ]
68
+ end
69
+
70
+ it 'runs a given block with null if a yielder raises an exception' do
71
+ xs = []
72
+ e = Object.new()
73
+ def e.each
74
+ yield 1
75
+ yield 2
76
+ raise RuntimeError, 'bang!'
77
+ yield 3
78
+ end
79
+
80
+ expect {
81
+ e.to_enum.
82
+ on_failure {|n| xs << "on_failure #{n.class}"}.
83
+ each do |n|
84
+ xs << "each enter #{n}"
85
+ xs << "each leave #{n}"
86
+ end
87
+ }.to raise_error(RuntimeError, 'bang!')
88
+
89
+ xs.should == [
90
+ "each enter 1",
91
+ "each leave 1",
92
+ "each enter 2",
93
+ "each leave 2",
94
+ "on_failure #{nil.class}",
95
+ ]
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
data/spec/facade_spec.rb CHANGED
@@ -1,548 +1,57 @@
1
- require 'bundler/setup'
2
1
  require 'fileutils'
3
2
  require 'spec_helper'
4
- require 'vim-flavor'
5
-
6
- describe Vim::Flavor::Facade do
7
- describe '#initialize' do
8
- it 'should have proper values by default' do
9
- facade = described_class.new()
10
- facade.flavorfile.should == nil
11
- facade.flavorfile_path.should == "#{Dir.getwd()}/VimFlavor"
12
- facade.lockfile.should == nil
13
- facade.lockfile_path.should == "#{Dir.getwd()}/VimFlavor.lock"
14
- end
15
- end
16
-
17
- describe '#load' do
18
- with_temporary_directory
19
-
20
- before :each do
21
- @facade = described_class.new()
22
- @facade.flavorfile_path = "#{@tmp_path}/VimFlavor"
23
- @facade.lockfile_path = "#{@tmp_path}/VimFlavor.lock"
24
-
25
- @flavor1 = Vim::Flavor::Flavor.new()
26
- @flavor1.groups = [:default]
27
- @flavor1.repo_name = 'kana/vim-smartinput'
28
- @flavor1.repo_uri = 'git://github.com/kana/vim-smartinput.git'
29
- @flavor1.version_contraint =
30
- Vim::Flavor::VersionConstraint.new('>= 0')
31
- @flavor1d = @flavor1.dup()
32
- @flavor1d.locked_version = Gem::Version.create('1.2.3')
33
- @flavor2 = Vim::Flavor::Flavor.new()
34
- @flavor2.groups = [:default]
35
- @flavor2.repo_name = 'kana/vim-smarttill'
36
- @flavor2.repo_uri = 'git://github.com/kana/vim-smarttill.git'
37
- @flavor2.version_contraint =
38
- Vim::Flavor::VersionConstraint.new('>= 0')
39
- @flavor2d = @flavor2.dup()
40
- @flavor2d.locked_version = Gem::Version.create('4.5.6')
41
-
42
- File.open(@facade.flavorfile_path, 'w') do |f|
43
- f.write(<<-'END')
44
- flavor 'kana/vim-smartinput'
45
- flavor 'kana/vim-smarttill'
46
- END
47
- end
48
- File.open(@facade.lockfile_path, 'w') do |f|
49
- f.write(<<-'END')
50
- :flavors:
51
- git://github.com/kana/vim-smartinput.git:
52
- :groups:
53
- - :default
54
- :locked_version: 1.2.3
55
- :repo_name: kana/vim-smartinput
56
- :version_contraint: >= 0
57
- END
58
- end
59
- end
60
-
61
- it 'should load both files' do
62
- @facade.load()
63
-
64
- @facade.flavorfile_path.should == "#{@tmp_path}/VimFlavor"
65
- @facade.lockfile_path.should == "#{@tmp_path}/VimFlavor.lock"
66
- @facade.flavorfile.flavors.keys.length == 2
67
- @facade.flavorfile.flavors[@flavor1.repo_uri].should == @flavor1
68
- @facade.flavorfile.flavors[@flavor2.repo_uri].should == @flavor2
69
- @facade.lockfile.flavors.should == {
70
- @flavor1d.repo_uri => @flavor1d,
71
- }
72
- end
73
-
74
- it 'should load a lockfile if it exists' do
75
- @facade.load()
76
-
77
- @facade.lockfile.flavors.should == {
78
- @flavor1d.repo_uri => @flavor1d,
79
- }
80
-
81
- @facade.lockfile_path = "#{@tmp_path}/VimFlavor.lock.xxx"
82
- @facade.load()
83
-
84
- @facade.lockfile.flavors.should == {}
85
- end
86
- end
87
-
88
- describe '#make_new_flavors' do
89
- before :each do
90
- @facade = described_class.new()
91
-
92
- @f0 = Vim::Flavor::Flavor.new()
93
- @f0.repo_name = 'kana/vim-textobj-entire'
94
- @f0.repo_uri = 'git://github.com/kana/vim-textobj-entire.git'
95
- @f0.version_contraint = Vim::Flavor::VersionConstraint.new('>= 0')
96
- @f0.locked_version = Gem::Version.create('0')
97
-
98
- @f1 = @f0.dup()
99
- @f1.locked_version = Gem::Version.create('2')
100
-
101
- @f1d = @f1.dup()
102
- @f1d.version_contraint = Vim::Flavor::VersionConstraint.new('>= 1')
103
- end
104
-
105
- it 'should keep current locked_version for newly added flavors' do
106
- @facade.make_new_flavors(
107
- {
108
- @f0.repo_uri => @f0,
109
- },
110
- {
111
- },
112
- :install
113
- ).should == {
114
- @f0.repo_uri => @f0,
115
- }
116
- end
117
-
118
- it 'should keep current locked_version for flavors with new constraint' do
119
- @facade.make_new_flavors(
120
- {
121
- @f1d.repo_uri => @f1d,
122
- },
123
- {
124
- @f0.repo_uri => @f0,
125
- },
126
- :install
127
- ).should == {
128
- @f1d.repo_uri => @f1d,
129
- }
130
- end
131
-
132
- it 'should keep current locked_version for :update mode' do
133
- @facade.make_new_flavors(
134
- {
135
- @f1.repo_uri => @f1,
136
- },
137
- {
138
- @f0.repo_uri => @f0,
139
- },
140
- :update
141
- ).should == {
142
- @f1.repo_uri => @f1,
143
- }
144
- end
145
-
146
- it 'should keep locked flavors otherwise' do
147
- @facade.make_new_flavors(
148
- {
149
- @f1.repo_uri => @f1,
150
- },
151
- {
152
- @f0.repo_uri => @f0,
153
- },
154
- :install
155
- ).should == {
156
- @f0.repo_uri => @f0,
157
- }
158
- end
159
-
160
- it 'should always use current groups even if locked version is updated' do
161
- f0 = @f0.dup()
162
- f0.groups = [:default]
163
- f1 = @f1.dup()
164
- f1.groups = [:default, :development]
165
- f1d = f1.dup()
166
- f1d.locked_version = f0.locked_version
167
-
168
- @facade.make_new_flavors(
169
- {
170
- f1.repo_uri => f1,
171
- },
172
- {
173
- f0.repo_uri => f0,
174
- },
175
- :install
176
- ).should == {
177
- f1d.repo_uri => f1d,
178
- }
179
- end
180
- end
181
-
182
- describe '#create_vim_script_for_bootstrap' do
183
- with_temporary_directory
184
-
185
- before :each do
186
- @facade = described_class.new()
187
- @home_path =
188
- if File.symlink?(@tmp_path)
189
- File.readlink(@tmp_path)
190
- else
191
- @tmp_path
3
+ require 'tmpdir'
4
+
5
+ module Vim
6
+ module Flavor
7
+ describe Facade do
8
+ describe '#create_vim_script_for_bootstrap' do
9
+ around :each do |example|
10
+ Dir.mktmpdir do |tmp_path|
11
+ @tmp_path = tmp_path
12
+ example.run
13
+ end
192
14
  end
193
- @vimfiles_path = "#{@home_path}/.vim"
194
- end
195
-
196
- it 'should create a bootstrap script into a given vimfiles path' do
197
- bootstrap_path = "#{@vimfiles_path.to_flavors_path()}/bootstrap.vim"
198
-
199
- File.exists?(bootstrap_path).should be_false
200
- @facade.create_vim_script_for_bootstrap(@vimfiles_path)
201
- File.exists?(bootstrap_path).should be_true
202
- end
203
-
204
- it 'should create a valid bootstrap script' do
205
- @facade.create_vim_script_for_bootstrap(@vimfiles_path)
206
-
207
- _rtp = %x{
208
- HOME='#{@home_path}'
209
- for plugin_name in 'foo' 'bar' 'baz'
210
- do
211
- mkdir -p "#{@vimfiles_path.to_flavors_path()}/$plugin_name"
212
- done
213
- vim -u NONE -i NONE -e -s -c '
214
- set nocompatible verbose=1
215
- let vimfiles_path = split(&runtimepath, ",")[0]
216
- source #{@vimfiles_path}/flavors/bootstrap.vim
217
- for path in split(&runtimepath, ",")
218
- if stridx(path, vimfiles_path) == 0
219
- echo substitute(path, vimfiles_path, "!", "")
220
- endif
221
- endfor
222
- qall!
223
- ' 2>&1
224
- }
225
- rtps =
226
- _rtp.
227
- split(/[\r\n]/).
228
- select {|p| p != ''}
229
- rtps.should == [
230
- '!',
231
- '!/flavors/bar',
232
- '!/flavors/baz',
233
- '!/flavors/foo',
234
- '!/flavors/foo/after',
235
- '!/flavors/baz/after',
236
- '!/flavors/bar/after',
237
- '!/after',
238
- ]
239
- end
240
- end
241
-
242
- describe '#deploy_flavors' do
243
- with_temporary_directory
244
-
245
- before :each do
246
- @facade = described_class.new()
247
-
248
- @test_repo_path = "#{@tmp_path}/test/origin"
249
-
250
- @flavor = Vim::Flavor::Flavor.new()
251
- @flavor.repo_name = '@test_repo_path'
252
- @flavor.repo_uri = @test_repo_path
253
- @flavor.locked_version = Gem::Version.create('1.0.0')
254
-
255
- @flavors = [@flavor]
256
-
257
- @vimfiles_path = "#{@tmp_path}/vimfiles"
258
- @bootstrap_path = "#{@vimfiles_path.to_flavors_path()}/bootstrap.vim"
259
- end
260
-
261
- it 'should replace a given path with given flavors' do
262
- create_a_test_repo(@test_repo_path)
263
- @flavors.each do |f|
264
- f.clone()
265
- end
266
-
267
- File.exists?(@vimfiles_path).should be_false
268
- File.exists?(@bootstrap_path).should be_false
269
- @flavors.each do |f|
270
- File.exists?(f.make_deploy_path(@vimfiles_path)).should be_false
271
- end
272
-
273
- @facade.deploy_flavors(@flavors, @vimfiles_path)
274
-
275
- File.exists?(@vimfiles_path).should be_true
276
- File.exists?(@bootstrap_path).should be_true
277
- @flavors.each do |f|
278
- File.exists?(f.make_deploy_path(@vimfiles_path)).should be_true
279
- end
280
-
281
- system(<<-"END")
282
- touch '#{@vimfiles_path}/foo'
283
- touch '#{@vimfiles_path.to_flavors_path()}/foo'
284
- END
285
-
286
- File.exists?("#{@vimfiles_path}/foo").should be_true
287
- File.exists?("#{@vimfiles_path.to_flavors_path()}/foo").should be_true
288
-
289
- @facade.deploy_flavors(@flavors, @vimfiles_path)
290
-
291
- File.exists?("#{@vimfiles_path}/foo").should be_true
292
- File.exists?("#{@vimfiles_path.to_flavors_path()}/foo").should be_false
293
- end
294
- end
295
-
296
- describe '#save_lockfile' do
297
- with_temporary_directory
298
-
299
- before :each do
300
- @facade = described_class.new()
301
- @facade.flavorfile_path = "#{@tmp_path}/VimFlavor"
302
- @facade.lockfile_path = "#{@tmp_path}/VimFlavor.lock"
303
-
304
- File.open(@facade.flavorfile_path, 'w') do |f|
305
- f.write(<<-'END')
306
- END
307
- end
308
- end
309
-
310
- it 'should save locked flavors' do
311
- @facade.load()
312
-
313
- @facade.lockfile.flavors.should == {}
314
-
315
- flavor1 = Vim::Flavor::Flavor.new()
316
- flavor1.groups = [:default]
317
- flavor1.locked_version = Gem::Version.create('1.2.3')
318
- flavor1.repo_name = 'kana/vim-smartinput'
319
- flavor1.repo_uri = 'git://github.com/kana/vim-smartinput.git'
320
- flavor1.version_contraint = Vim::Flavor::VersionConstraint.new('>= 0')
321
- @facade.lockfile.instance_eval do
322
- @flavors = {
323
- flavor1.repo_uri => flavor1,
324
- }
325
- end
326
- @facade.save_lockfile()
327
- @facade.lockfile.instance_eval do
328
- @flavors = nil
329
- end
330
-
331
- @facade.lockfile.flavors.should == nil
332
-
333
- @facade.load()
334
-
335
- @facade.lockfile.flavors.should == {
336
- flavor1.repo_uri => flavor1,
337
- }
338
- end
339
- end
340
-
341
- describe '#complete_locked_flavors' do
342
- with_temporary_directory
343
-
344
- before :each do
345
- @test_repo_path = "#{@tmp_path}/test/origin"
346
- @facade = described_class.new()
347
- @facade.flavorfile_path = "#{@tmp_path}/VimFlavor"
348
- @facade.lockfile_path = "#{@tmp_path}/VimFlavor.lock"
349
-
350
- create_a_test_repo(@test_repo_path)
351
- File.open(@facade.flavorfile_path, 'w') do |f|
352
- f.write(<<-"END")
353
- flavor 'file://#{@test_repo_path}', '~> 1.1.1'
354
- END
355
- end
356
- end
357
-
358
- it 'should complete flavors if they are not locked' do
359
- @facade.load()
360
-
361
- cf1 = @facade.flavorfile.flavors.values[0]
362
- cf1.locked_version.should be_nil
363
- File.exists?(cf1.cached_repo_path).should be_false
364
- @facade.lockfile.flavors.should == {}
365
-
366
- @facade.complete_locked_flavors(:upgrade_if_necessary)
367
-
368
- lf1 = @facade.lockfile.flavors.values[0]
369
- lf1.locked_version.should == Gem::Version.create('1.1.2')
370
- File.exists?(lf1.cached_repo_path).should be_true
371
- @facade.lockfile.flavors.should == {
372
- lf1.repo_uri => lf1,
373
- }
374
-
375
- @facade.complete_locked_flavors(:upgrade_if_necessary)
376
-
377
- lf1d = @facade.lockfile.flavors.values[0]
378
- lf1d.locked_version.should == Gem::Version.create('1.1.2')
379
- File.exists?(lf1d.cached_repo_path).should be_true
380
- @facade.lockfile.flavors.should == {
381
- lf1d.repo_uri => lf1d,
382
- }
383
- end
384
-
385
- it 'should complete flavors if their constraint are changed' do
386
- @facade.load()
387
-
388
- cf1 = @facade.flavorfile.flavors.values[0]
389
- cf1.locked_version.should be_nil
390
- File.exists?(cf1.cached_repo_path).should be_false
391
- @facade.lockfile.flavors.should == {}
392
-
393
- @facade.complete_locked_flavors(:upgrade_if_necessary)
394
-
395
- lf1 = @facade.lockfile.flavors.values[0]
396
- lf1.locked_version.should == Gem::Version.create('1.1.2')
397
- File.exists?(lf1.cached_repo_path).should be_true
398
- @facade.lockfile.flavors.should == {
399
- lf1.repo_uri => lf1,
400
- }
401
-
402
- cf1.version_contraint = Vim::Flavor::VersionConstraint.new('~> 1.1.2')
403
- update_a_test_repo(@test_repo_path)
404
- @facade.complete_locked_flavors(:upgrade_if_necessary)
405
-
406
- lf1d = @facade.lockfile.flavors.values[0]
407
- lf1d.locked_version.should == Gem::Version.create('1.1.9')
408
- File.exists?(lf1d.cached_repo_path).should be_true
409
- @facade.lockfile.flavors.should == {
410
- lf1d.repo_uri => lf1d,
411
- }
412
- end
413
-
414
- it 'should upgrade flavors even if their constraint are not changed' do
415
- @facade.load()
416
-
417
- cf1 = @facade.flavorfile.flavors.values[0]
418
- cf1.locked_version.should be_nil
419
- File.exists?(cf1.cached_repo_path).should be_false
420
- @facade.lockfile.flavors.should == {}
421
-
422
- @facade.complete_locked_flavors(:upgrade_all)
423
-
424
- lf1 = @facade.lockfile.flavors.values[0]
425
- lf1.locked_version.should == Gem::Version.create('1.1.2')
426
- File.exists?(lf1.cached_repo_path).should be_true
427
- @facade.lockfile.flavors.should == {
428
- lf1.repo_uri => lf1,
429
- }
430
-
431
- update_a_test_repo(@test_repo_path)
432
- @facade.complete_locked_flavors(:upgrade_all)
433
15
 
434
- lf1d = @facade.lockfile.flavors.values[0]
435
- lf1d.locked_version.should == Gem::Version.create('1.1.9')
436
- File.exists?(lf1d.cached_repo_path).should be_true
437
- @facade.lockfile.flavors.should == {
438
- lf1d.repo_uri => lf1d,
439
- }
440
- end
441
- end
442
-
443
- describe '#get_default_vimfiles_path' do
444
- it 'should return an appropriate value for *nix' do
445
- # FIXME: Add proper tests depending on the current environment.
446
- @facade = described_class.new()
447
- @facade.get_default_vimfiles_path().should == "#{ENV['HOME']}/.vim"
448
- end
449
- end
450
-
451
- describe '#install' do
452
- with_temporary_directory
453
-
454
- before :each do
455
- @test_repo_path = "#{@tmp_path}/test/origin"
456
- @vimfiles_path = "#{@tmp_path}/vimfiles"
457
- @facade = described_class.new()
458
- @facade.flavorfile_path = "#{@tmp_path}/VimFlavor"
459
- @facade.lockfile_path = "#{@tmp_path}/VimFlavor.lock"
460
-
461
- create_a_test_repo(@test_repo_path)
462
- File.open(@facade.flavorfile_path, 'w') do |f|
463
- f.write(<<-"END")
464
- flavor 'file://#{@test_repo_path}', '~> 1.1.1'
465
- END
466
- end
467
- end
468
-
469
- it 'should install Vim plugins according to VimFlavor' do
470
- File.exists?(@facade.lockfile_path).should be_false
471
- File.exists?(@vimfiles_path).should be_false
472
- @facade.lockfile.should be_nil
473
-
474
- @facade.install(@vimfiles_path)
475
-
476
- File.exists?(@facade.lockfile_path).should be_true
477
- File.exists?(@vimfiles_path).should be_true
478
- @facade.lockfile.flavors.values.each do |f|
479
- File.exists?(f.make_deploy_path(@vimfiles_path)).should be_true
480
- end
481
- end
482
-
483
- it 'should respect existing VimFlavor.lock if possible' do
484
- def self.install()
485
- @facade.install(@vimfiles_path)
486
- [
487
- @facade.lockfile.flavors.map {|_, f| f.locked_version},
488
- @facade.flavorfile.flavors.count(),
489
- ]
490
- end
491
-
492
- result1 = self.install()
493
- update_a_test_repo(@test_repo_path)
494
- result2 = self.install()
495
-
496
- result2.should == result1
497
- end
498
- end
499
-
500
- describe '#upgrade' do
501
- with_temporary_directory
502
-
503
- before :each do
504
- @test_repo_path = "#{@tmp_path}/test/origin"
505
- @vimfiles_path = "#{@tmp_path}/vimfiles"
506
- @facade = described_class.new()
507
- @facade.flavorfile_path = "#{@tmp_path}/VimFlavor"
508
- @facade.lockfile_path = "#{@tmp_path}/VimFlavor.lock"
509
-
510
- create_a_test_repo(@test_repo_path)
511
- File.open(@facade.flavorfile_path, 'w') do |f|
512
- f.write(<<-"END")
513
- flavor 'file://#{@test_repo_path}', '~> 1.1.1'
514
- END
515
- end
516
- end
517
-
518
- it 'should upgrade Vim plugins according to VimFlavor' do
519
- File.exists?(@facade.lockfile_path).should be_false
520
- File.exists?(@vimfiles_path).should be_false
521
- @facade.lockfile.should be_nil
522
-
523
- @facade.upgrade(@vimfiles_path)
524
-
525
- File.exists?(@facade.lockfile_path).should be_true
526
- File.exists?(@vimfiles_path).should be_true
527
- @facade.lockfile.flavors.values.each do |f|
528
- File.exists?(f.make_deploy_path(@vimfiles_path)).should be_true
529
- end
530
- end
531
-
532
- it 'should always upgrade existing VimFlavor.lock' do
533
- def self.upgrade()
534
- @facade.upgrade(@vimfiles_path)
535
- [
536
- @facade.lockfile.flavors.map {|_, f| f.locked_version},
537
- @facade.flavorfile.flavors.count(),
538
- ]
16
+ it 'creates a bootstrap script to configure runtimepath for flavors' do
17
+ vimfiles_path = @tmp_path.to_vimfiles_path
18
+ Facade.new().create_vim_script_for_bootstrap(vimfiles_path)
19
+
20
+ File.should exist(vimfiles_path.to_flavors_path.to_bootstrap_path)
21
+
22
+ _rtp = %x{
23
+ for plugin_name in 'foo' 'bar' 'baz'
24
+ do
25
+ mkdir -p "#{vimfiles_path.to_flavors_path}/$plugin_name"
26
+ done
27
+ HOME='#{@tmp_path}' vim -u NONE -i NONE -n -N -e -s -c '
28
+ set verbose=1
29
+ let vimfiles_path = split(&runtimepath, ",")[0]
30
+ runtime flavors/bootstrap.vim
31
+ for path in split(&runtimepath, ",")
32
+ if stridx(path, vimfiles_path) == 0
33
+ echo substitute(path, vimfiles_path, "!", "")
34
+ endif
35
+ endfor
36
+ qall!
37
+ ' 2>&1
38
+ }
39
+ rtps =
40
+ _rtp.
41
+ split(/[\r\n]/).
42
+ select {|p| p != ''}
43
+ rtps.should == [
44
+ '!',
45
+ '!/flavors/bar',
46
+ '!/flavors/baz',
47
+ '!/flavors/foo',
48
+ '!/flavors/foo/after',
49
+ '!/flavors/baz/after',
50
+ '!/flavors/bar/after',
51
+ '!/after',
52
+ ]
53
+ end
539
54
  end
540
-
541
- result1 = self.upgrade()
542
- update_a_test_repo(@test_repo_path)
543
- result2 = self.upgrade()
544
-
545
- result2.should_not == result1
546
55
  end
547
56
  end
548
57
  end