fig 2.0.0.pre.alpha.4 → 2.0.0.pre.alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fig/spec_utils.rb +312 -0
  3. data/lib/fig/version.rb +1 -1
  4. data/spec/application_configuration_spec.rb +73 -0
  5. data/spec/command/clean_spec.rb +62 -0
  6. data/spec/command/command_line_vs_package_spec.rb +32 -0
  7. data/spec/command/dump_package_definition_spec.rb +104 -0
  8. data/spec/command/environment_variables_spec.rb +62 -0
  9. data/spec/command/grammar_asset_spec.rb +391 -0
  10. data/spec/command/grammar_command_spec.rb +88 -0
  11. data/spec/command/grammar_environment_variable_spec.rb +384 -0
  12. data/spec/command/grammar_retrieve_spec.rb +74 -0
  13. data/spec/command/grammar_spec.rb +87 -0
  14. data/spec/command/grammar_spec_helper.rb +23 -0
  15. data/spec/command/include_file_spec.rb +73 -0
  16. data/spec/command/listing_spec.rb +1574 -0
  17. data/spec/command/miscellaneous_spec.rb +145 -0
  18. data/spec/command/publish_local_and_updates_spec.rb +32 -0
  19. data/spec/command/publishing_retrieval_spec.rb +423 -0
  20. data/spec/command/publishing_spec.rb +596 -0
  21. data/spec/command/running_commands_spec.rb +354 -0
  22. data/spec/command/suppress_includes_spec.rb +65 -0
  23. data/spec/command/suppress_warning_include_statement_missing_version_spec.rb +134 -0
  24. data/spec/command/update_lock_response_spec.rb +47 -0
  25. data/spec/command/usage_errors_spec.rb +481 -0
  26. data/spec/command_options_spec.rb +184 -0
  27. data/spec/command_spec.rb +49 -0
  28. data/spec/deparser/v1_spec.rb +64 -0
  29. data/spec/environment_variables_spec.rb +91 -0
  30. data/spec/figrc_spec.rb +144 -0
  31. data/spec/parser_spec.rb +398 -0
  32. data/spec/repository_spec.rb +117 -0
  33. data/spec/runtime_environment_spec.rb +357 -0
  34. data/spec/spec_helper.rb +1 -0
  35. data/spec/split_repo_url_spec.rb +190 -0
  36. data/spec/statement/asset_spec.rb +203 -0
  37. data/spec/statement/configuration_spec.rb +41 -0
  38. data/spec/support/formatters/seed_spitter.rb +12 -0
  39. data/spec/working_directory_maintainer_spec.rb +102 -0
  40. metadata +42 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7b0a1e7e7c54f5641e35e7ae6cb79f68d99ecbf29fcea10db478169599ae532
4
- data.tar.gz: d13a64acc3c9f804a96454039a54005098b3869f83af7e1f037fa61e445e6dab
3
+ metadata.gz: 62f48881b3ac7d401f94298e95315f0500b08a26635ecbc36a47de29e9ef172e
4
+ data.tar.gz: b1833add69c8cf53d54cd0ce76ee6cc1608c713eb487963f0af679671916e22e
5
5
  SHA512:
6
- metadata.gz: e62dcf96e9bb214fb48a4d88428006ef893b7c7d0e93c4fc63752e3931261f5eaf1549eade14ac836d5f022bbcddc5f165f1315d773fb5748f275ca799cf963b
7
- data.tar.gz: de2f11e4a62585e3c23d1ca6193d8564be023bb3765b9e9c2e1baec8e2e05952a6b9c2d3ad5c719a5c40368450c786c71b019dd6cfab6a4eb50105b72b9e6ffa
6
+ metadata.gz: 062e6bb0dc0a5ccaa087022de0398cb641393f2dd4938afeecf1199ab0a8d81ef3b7c6c784d116b9f9b43aac5c769df1e177b12ac85a06fa4c54dd08b7249a7a
7
+ data.tar.gz: 77ec6f3a04820f24d373304f5289c5164ffd66984f3d6922a6de2d02fd3be288432e0b07a319e52dd36f633f877b109b859b79feef609a7aeef9e32ffe8bd98a
@@ -0,0 +1,312 @@
1
+ # coding: utf-8
2
+
3
+ if ENV['FIG_COVERAGE']
4
+ require 'simplecov' # note that .simplecov will be loaded here.
5
+
6
+ SimpleCov.start
7
+ end
8
+
9
+ require 'rubygems'
10
+ require 'rbconfig'
11
+ require 'rspec'
12
+
13
+ require 'fileutils'
14
+ require 'tmpdir'
15
+
16
+ require 'fig/command'
17
+ require 'fig/external_program'
18
+ require 'fig/figrc'
19
+ require 'fig/logging'
20
+ require 'fig/repository'
21
+
22
+ FIG_SPEC_BASE_DIRECTORY = Dir.mktmpdir 'fig-rspec-'
23
+ at_exit { FileUtils.rm_rf FIG_SPEC_BASE_DIRECTORY }
24
+
25
+ # "Current" as in current directory when running fig.
26
+ CURRENT_DIRECTORY = FIG_SPEC_BASE_DIRECTORY + '/current-directory'
27
+
28
+ USER_HOME = FIG_SPEC_BASE_DIRECTORY + '/user-home'
29
+ FIG_HOME = FIG_SPEC_BASE_DIRECTORY + '/fig-home'
30
+
31
+ # For split URL behavior - using distinct directories to catch incorrect URL usage
32
+ FIG_DOWNLOAD_DIR = File.join(FIG_SPEC_BASE_DIRECTORY, 'remote')
33
+ FIG_UPLOAD_DIR = File.join(FIG_SPEC_BASE_DIRECTORY, 'upload')
34
+ FIG_DOWNLOAD_URL = %Q<file://#{FIG_DOWNLOAD_DIR}>
35
+ FIG_UPLOAD_URL = %Q<file://#{FIG_UPLOAD_DIR}>
36
+
37
+ #FIG_DIRECTORY ||= File.expand_path(File.dirname(__FILE__)) + '/../bin'
38
+ FIG_DIRECTORY ||= File.expand_path(File.dirname(__FILE__)) + '/../../bin'
39
+ FIG_COMMAND_CLASS ||= Fig::Command
40
+ FIG_PROGRAM ||= ENV['FIG_SPEC_DEBUG'] \
41
+ ? 'exit Fig::Command.new.run_fig ARGV' \
42
+ : 'exit Fig::Command.new.run_fig_with_exception_handling ARGV'
43
+
44
+ # Needed for testing of resources.
45
+ FIG_FILE_GUARANTEED_TO_EXIST =
46
+ File.expand_path(CURRENT_DIRECTORY + '/file-guaranteed-to-exist')
47
+
48
+ RUBY_EXE ||= RbConfig.ruby
49
+ BASE_FIG_COMMAND_LINE ||= [
50
+ RUBY_EXE,
51
+ '--external-encoding', 'UTF-8',
52
+ '--internal-encoding', 'UTF-8',
53
+ '-r', "#{FIG_DIRECTORY}/../lib/fig/command/initialization.rb",
54
+ '-e', FIG_PROGRAM,
55
+ '--',
56
+ ]
57
+
58
+ ENV['HOME'] = USER_HOME
59
+ ENV['FIG_HOME'] = FIG_HOME
60
+ # Set up new environment variables for tests
61
+ ENV['FIG_DOWNLOAD_URL'] = FIG_DOWNLOAD_URL
62
+ ENV['FIG_UPLOAD_URL'] = FIG_UPLOAD_URL
63
+
64
+ ENV['FIG_COVERAGE_ROOT_DIRECTORY'] =
65
+ File.expand_path(File.dirname(__FILE__) + '/..')
66
+
67
+ Fig::Logging.initialize_post_configuration(nil, false, 'off', true)
68
+
69
+ $fig_run_count = 0 # Nasty, nasty global.
70
+
71
+ # Options:
72
+ #
73
+ # :current_directory What the current directory should be when starting fig.
74
+ #
75
+ # :figrc Value of the --figrc option. If not specified,
76
+ # --no-figrc will be passed to fig.
77
+ #
78
+ # :no_raise_on_error Normally an exception is thrown if fig returns an error
79
+ # code. If this option is true, then no exception will
80
+ # be raised, allowing testing of failure states/output.
81
+ #
82
+ # :fork If specified as false, don't run fig as an external
83
+ # process, but in-process instead. This will run faster,
84
+ # but will screw up the test suite if fig invokes
85
+ # Kernel#exec (due to a command statement) or otherwise
86
+ # depends upon at-exit behavior.
87
+ def fig(command_line, first_extra = nil, rest_extra = nil)
88
+ input, options = _fig_input_options(first_extra, rest_extra)
89
+
90
+ $fig_run_count += 1
91
+ ENV['FIG_COVERAGE_RUN_COUNT'] = $fig_run_count.to_s
92
+
93
+ out = err = exit_code = nil
94
+
95
+ current_directory = options[:current_directory] || CURRENT_DIRECTORY
96
+ Dir.chdir current_directory do
97
+ standard_options = []
98
+ standard_options.concat %w< --log-level warn >
99
+ standard_options.concat %w< --file - > if input
100
+
101
+ figrc = options[:figrc]
102
+ if figrc
103
+ standard_options << '--figrc' << figrc
104
+ else
105
+ standard_options << '--no-figrc'
106
+ end
107
+
108
+ if command_line.include?('--update-lock-response')
109
+ if ! options.fetch(:fork, true)
110
+ raise 'Cannot specify both ":fork => false" and --update-lock-response.'
111
+ end
112
+ elsif ! options.fetch(:fork, true) || Fig::OperatingSystem.windows?
113
+ standard_options.concat %w< --update-lock-response ignore >
114
+ end
115
+
116
+ command_line = [standard_options, command_line].flatten
117
+ out, err, exit_code = _run_command command_line, input, options
118
+ end
119
+
120
+ return out, err, exit_code
121
+ end
122
+
123
+ # A bit of ruby magic to make invoking fig() nicer; this takes advantage of the
124
+ # hash assignment syntax so you can call it like any of
125
+ #
126
+ # fig([arguments])
127
+ # fig([arguments], input)
128
+ # fig([arguments], input, :no_raise_on_error => true)
129
+ # fig([arguments], :no_raise_on_error => true)
130
+ def _fig_input_options(first_extra, rest_extra)
131
+ return nil, rest_extra || {} if first_extra.nil?
132
+
133
+ if first_extra.is_a? Hash
134
+ return nil, first_extra
135
+ end
136
+
137
+ return first_extra, rest_extra || {}
138
+ end
139
+
140
+ def _run_command(command_line, input, options)
141
+ out = err = exit_code = exit_string = nil
142
+
143
+ if options.fetch(:fork, true)
144
+ out, err, exit_code, exit_string =
145
+ _run_command_externally command_line, input, options
146
+ else
147
+ out, err, exit_code, exit_string =
148
+ _run_command_internally command_line, input, options
149
+ end
150
+
151
+ if exit_string
152
+ # Common scenario during development is that the fig process will fail for
153
+ # whatever reason, but the RSpec expectation is checking whether a file was
154
+ # created, etc. meaning that we don't see stdout, stderr, etc. but RSpec's
155
+ # failure message for the expectation, which isn't informative. Throwing
156
+ # an exception that RSpec will catch will correctly integrate the fig
157
+ # output with the rest of the RSpec output.
158
+ fig_failure = "Fig process failed:\n"
159
+ fig_failure << "command: #{command_line.join(' ')}\n"
160
+ fig_failure << "result: #{exit_string}\n"
161
+ fig_failure << "stdout: #{out.nil? ? '<nil>' : out}\n"
162
+ fig_failure << "stderr: #{err.nil? ? '<nil>' : err}\n"
163
+ if input
164
+ fig_failure << "input: #{input}\n"
165
+ end
166
+
167
+ raise fig_failure
168
+ end
169
+
170
+ if ! options[:dont_strip_output]
171
+ err.strip!
172
+ out.strip!
173
+ end
174
+
175
+ return out, err, exit_code
176
+ end
177
+
178
+ def _run_command_externally(command_line, input, options)
179
+ full_command_line = BASE_FIG_COMMAND_LINE + command_line
180
+ out, err, result = Fig::ExternalProgram.capture(full_command_line, input)
181
+
182
+ exit_code = result.nil? ? 0 : result.exitstatus
183
+ exit_string = nil
184
+ if result && ! result.success? && ! options[:no_raise_on_error]
185
+ exit_string = result.to_s
186
+ end
187
+
188
+ # Hooray for Windows line endings! Not.
189
+ if out
190
+ out.gsub!(/\r+\n/, "\n")
191
+ end
192
+ if err
193
+ err.gsub!(/\r+\n/, "\n")
194
+ end
195
+
196
+ return out, err, exit_code, exit_string
197
+ end
198
+
199
+ def _run_command_internally(command_line, input, options)
200
+ original_stdin = $stdin
201
+ original_stdout = $stdout
202
+ original_stderr = $stderr
203
+
204
+ begin
205
+ stdin = input ? StringIO.new(input) : StringIO.new
206
+ stdout = StringIO.new
207
+ stderr = StringIO.new
208
+ exit_code = nil
209
+
210
+ $stdin = stdin
211
+ $stdout = stdout
212
+ $stderr = stderr
213
+
214
+ if ENV['FIG_SPEC_DEBUG']
215
+ exit_code = FIG_COMMAND_CLASS.new.run_fig command_line
216
+ else
217
+ exit_code =
218
+ FIG_COMMAND_CLASS.new.run_fig_with_exception_handling command_line
219
+ end
220
+
221
+ exit_string = nil
222
+ if exit_code != 0 && ! options[:no_raise_on_error]
223
+ exit_string = exit_code.to_s
224
+ end
225
+
226
+ return stdout.string, stderr.string, exit_code, exit_string
227
+ ensure
228
+ $stdin = original_stdin
229
+ $stdout = original_stdout
230
+ $stderr = original_stderr
231
+ end
232
+ end
233
+
234
+ def set_up_test_environment()
235
+ FileUtils.mkdir_p FIG_SPEC_BASE_DIRECTORY
236
+ FileUtils.mkdir_p CURRENT_DIRECTORY
237
+ FileUtils.mkdir_p USER_HOME
238
+ FileUtils.mkdir_p FIG_HOME
239
+ FileUtils.mkdir_p FIG_UPLOAD_DIR
240
+ FileUtils.ln_s FIG_UPLOAD_DIR, FIG_DOWNLOAD_DIR
241
+
242
+ FileUtils.touch FIG_FILE_GUARANTEED_TO_EXIST
243
+
244
+ metadata_directory =
245
+ File.join FIG_UPLOAD_DIR, Fig::Repository::METADATA_SUBDIRECTORY
246
+ FileUtils.mkdir_p metadata_directory
247
+
248
+ File.open(
249
+ File.join(FIG_UPLOAD_DIR, Fig::FigRC::REPOSITORY_CONFIGURATION), 'w'
250
+ ) do
251
+ |handle|
252
+ handle.puts '{}' # Empty Javascript/JSON object
253
+ end
254
+
255
+ return
256
+ end
257
+
258
+ def clean_up_test_environment()
259
+ FileUtils.rm_rf(FIG_SPEC_BASE_DIRECTORY)
260
+
261
+ return
262
+ end
263
+
264
+ def cleanup_home_and_remote(unified: true)
265
+ FileUtils.rm_rf(FIG_HOME)
266
+
267
+ # Clean up split URL directories
268
+ FileUtils.rm_rf(FIG_DOWNLOAD_DIR)
269
+ FileUtils.rm_rf(FIG_UPLOAD_DIR)
270
+
271
+ # Create base directories for split URLs
272
+ FileUtils.mkdir_p(FIG_UPLOAD_DIR)
273
+ FileUtils.mkdir_p(File.join(FIG_UPLOAD_DIR, Fig::Repository::METADATA_SUBDIRECTORY))
274
+
275
+ if unified
276
+ # use symlink to simulate an aggregated artifactory repo
277
+ FileUtils.ln_s(FIG_UPLOAD_DIR, FIG_DOWNLOAD_DIR)
278
+ else
279
+ FileUtils.mkdir_p(FIG_DOWNLOAD_DIR)
280
+ FileUtils.mkdir_p(File.join(FIG_DOWNLOAD_DIR, Fig::Repository::METADATA_SUBDIRECTORY))
281
+ end
282
+
283
+ return
284
+ end
285
+
286
+ def set_local_repository_format_to_future_version()
287
+ version_file = File.join(FIG_HOME, Fig::Repository::VERSION_FILE_NAME)
288
+ FileUtils.mkdir_p(FIG_HOME)
289
+ File.open(version_file, 'w') {
290
+ |handle| handle.write(Fig::Repository::LOCAL_VERSION_SUPPORTED + 1)
291
+ }
292
+
293
+ return
294
+ end
295
+
296
+ def set_remote_repository_format_to_future_version()
297
+ # Set future version in download dir
298
+ version_file = File.join(FIG_DOWNLOAD_DIR, Fig::Repository::VERSION_FILE_NAME)
299
+ FileUtils.mkdir_p(FIG_DOWNLOAD_DIR)
300
+ File.open(version_file, 'w') {
301
+ |handle| handle.write(Fig::Repository::REMOTE_VERSION_SUPPORTED + 1)
302
+ }
303
+
304
+ # Set future version in upload dir
305
+ version_file = File.join(FIG_UPLOAD_DIR, Fig::Repository::VERSION_FILE_NAME)
306
+ FileUtils.mkdir_p(FIG_UPLOAD_DIR)
307
+ File.open(version_file, 'w') {
308
+ |handle| handle.write(Fig::Repository::REMOTE_VERSION_SUPPORTED + 1)
309
+ }
310
+
311
+ return
312
+ end
data/lib/fig/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Fig
4
- VERSION = '2.0.0-alpha.4'.freeze
4
+ VERSION = '2.0.0-alpha.5'.freeze
5
5
  end
@@ -0,0 +1,73 @@
1
+ # coding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
4
+
5
+ require 'fig/application_configuration'
6
+
7
+ REPOSITORY_TEST_URL = 'http://example.com'
8
+ WHITELIST_TEST_URL = 'http://foo.com'
9
+
10
+ describe 'ApplicationConfiguration' do
11
+ def new_configuration()
12
+ config = Fig::ApplicationConfiguration.new
13
+
14
+ config.base_whitelisted_url = REPOSITORY_TEST_URL
15
+ config.remote_download_url = REPOSITORY_TEST_URL
16
+ config.remote_upload_url = REPOSITORY_TEST_URL
17
+
18
+ return config
19
+ end
20
+
21
+ it 'allows arbitrary urls when there is no whitelist' do
22
+ config = new_configuration
23
+ config.url_access_allowed?('').should == true
24
+ end
25
+
26
+ it 'allows the repo url when whitelist is empty' do
27
+ config = new_configuration
28
+ config.push_dataset({'url whitelist' => []})
29
+ config.url_access_allowed?(REPOSITORY_TEST_URL).should == true
30
+ end
31
+
32
+ it 'disallows a non-repo url when whitelist is empty' do
33
+ config = new_configuration
34
+ config.push_dataset({'url whitelist' => []})
35
+ config.url_access_allowed?('').should == false
36
+ end
37
+
38
+ it 'disallows a url that starts with a whitelisted url that is a hostname only' do
39
+ config = new_configuration
40
+ config.push_dataset({'url whitelist' => []})
41
+ config.url_access_allowed?(REPOSITORY_TEST_URL + 'x').should == false
42
+ end
43
+
44
+ it 'allows a full url with empty whitelist' do
45
+ config = new_configuration
46
+ config.push_dataset({'url whitelist' => []})
47
+ config.url_access_allowed?(REPOSITORY_TEST_URL + '/x').should == true
48
+ end
49
+
50
+ it 'allows a url when it\'s on the whitelist' do
51
+ config = new_configuration
52
+ config.push_dataset({'url whitelist' => [REPOSITORY_TEST_URL]})
53
+ config.url_access_allowed?(REPOSITORY_TEST_URL + '/x').should == true
54
+ end
55
+
56
+ it 'disallows a url when it\'s not on the whitelist' do
57
+ config = new_configuration
58
+ config.push_dataset({'url whitelist' => [WHITELIST_TEST_URL]})
59
+ config.url_access_allowed?('http://bar.com' + '/x').should == false
60
+ end
61
+
62
+ it 'disallows a non-repo url when whitelist is not empty' do
63
+ config = new_configuration
64
+ config.push_dataset({'url whitelist' => [WHITELIST_TEST_URL]})
65
+ config.url_access_allowed?('').should == false
66
+ end
67
+
68
+ it 'disallows a url with a different port (but the first part matches)' do
69
+ config = new_configuration
70
+ config.push_dataset({'url whitelist' => [WHITELIST_TEST_URL+':2000']})
71
+ config.url_access_allowed?(WHITELIST_TEST_URL+':20001').should == false
72
+ end
73
+ end
@@ -0,0 +1,62 @@
1
+ # coding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+
5
+ describe 'Fig' do
6
+ describe '--clean' do
7
+ before(:each) do
8
+ clean_up_test_environment
9
+ set_up_test_environment
10
+ cleanup_home_and_remote
11
+ end
12
+
13
+ it 'cleans a named package from the FIG_HOME' do
14
+ fig(%w<--publish foo/1.2.3 --set FOO=BAR>)[2].should == 0
15
+ fig(%w<--clean foo/1.2.3>)[2].should == 0
16
+ fail unless not File.directory? FIG_HOME + '/packages/foo/1.2.3'
17
+ end
18
+
19
+ it 'cleans a named package from the FIG_HOME and does not clean packages differing only by version' do
20
+ input = <<-END
21
+ config default
22
+ set FOO=BAR
23
+ end
24
+ END
25
+ fig(%w<--publish foo/1.2.3>, input)[2].should == 0
26
+ fig(%w<--publish foo/4.5.6>, input)[2].should == 0
27
+ fig(%w<--clean foo/1.2.3>)[2].should == 0
28
+ fail unless File.directory? FIG_HOME + '/packages/foo/4.5.6'
29
+ end
30
+
31
+ it 'should complain if you clean without a package descriptor' do
32
+ out, err, exit_code = fig(%w<--clean>, :no_raise_on_error => true)
33
+ err.should =~ /need to specify a descriptor/i
34
+ exit_code.should_not == 0
35
+ end
36
+
37
+ it %q<should complain if local repository isn't in the expected format version> do
38
+ fig(%w<--publish foo/1.2.3 --set FOO=BAR>)[2].should == 0
39
+
40
+ set_local_repository_format_to_future_version()
41
+ out, err, exit_code =
42
+ fig(%w<--clean foo/1.2.3>, :no_raise_on_error => true)
43
+ err.should =~
44
+ /Local repository is in version \d+ format. This version of fig can only deal with repositories in version \d+ format\./
45
+ exit_code.should_not == 0
46
+ end
47
+
48
+ %w< --update --update-if-missing >.each do
49
+ |option|
50
+
51
+ it %Q<should complain if #{option} is specified> do
52
+ fig(%w<--publish foo/1.2.3 --set FOO=BAR>)[2].should == 0
53
+
54
+ out, err, exit_code =
55
+ fig([option, '--clean', 'foo/1.2.3'], :no_raise_on_error => true)
56
+ err.should =~
57
+ /because they disagree on whether the base package should be loaded/
58
+ exit_code.should_not == 0
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+
5
+ describe 'Fig' do
6
+ before(:each) do
7
+ clean_up_test_environment
8
+ set_up_test_environment
9
+ end
10
+
11
+ describe 'command-line options vs package files' do
12
+ it %q<gives a "--set" option priority over a "set" statement> do
13
+ input = <<-END
14
+ config default
15
+ set TEST=package.fig
16
+ end
17
+ END
18
+ fig(%w<--set TEST=command-line --get TEST>, input)[0].should ==
19
+ 'command-line'
20
+ end
21
+
22
+ it %q<gives an "--add" option priority over an "append" statement> do
23
+ input = <<-END
24
+ config default
25
+ add TEST_PATH=package.fig
26
+ end
27
+ END
28
+ fig(%w<--append TEST_PATH=command-line --get TEST_PATH>, input)[0].should ==
29
+ "command-line#{File::PATH_SEPARATOR}package.fig"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,104 @@
1
+ # coding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+
5
+ describe 'Fig' do
6
+ describe 'package definition dumping' do
7
+ before(:each) do
8
+ clean_up_test_environment
9
+ set_up_test_environment
10
+ end
11
+
12
+ describe '--dump-package-definition-text' do
13
+ it %q<dumps the contents of a published package> do
14
+ input = <<-END
15
+ config default
16
+ set FOO=BAR
17
+ end
18
+ END
19
+ fig(%w<--publish foo/1.2.3>, input, :fork => false)
20
+
21
+ out, err =
22
+ fig(%w<foo/1.2.3 --dump-package-definition-text>, :fork => false)
23
+
24
+ # Content from the input.
25
+ out.should =~ /set FOO=BAR/
26
+
27
+ # Content that is added by publishing.
28
+ out.should =~ /publishing information for/i
29
+
30
+ err.should == ''
31
+ end
32
+
33
+ it %q<dumps the contents an unpublished package> do
34
+ input = <<-END
35
+ config default
36
+ set FOO=BAR
37
+ end
38
+ END
39
+ out, err =
40
+ fig(%w<--dump-package-definition-text>, input, :fork => false)
41
+
42
+ out.should == input.strip
43
+ err.should == ''
44
+ end
45
+
46
+ it %q<fails if there is no text> do
47
+ out, err, exit_code = fig(
48
+ %w<--dump-package-definition-text>,
49
+ :no_raise_on_error => true,
50
+ :fork => false
51
+ )
52
+ err.should =~ /no text/
53
+ out.should == ''
54
+ exit_code.should_not == 0
55
+ end
56
+ end
57
+
58
+ describe '--dump-package-definition-parsed' do
59
+ it %q<dumps the contents of a published package> do
60
+ input = <<-END
61
+ config default
62
+ set FOO=BAR
63
+ end
64
+ END
65
+ fig(%w<--publish foo/1.2.3>, input, :fork => false, :fork => false)
66
+
67
+ out, err =
68
+ fig(%w<foo/1.2.3 --dump-package-definition-parsed>, :fork => false)
69
+
70
+ # Content from the input.
71
+ out.should =~ /set FOO=BAR/
72
+
73
+ err.should == ''
74
+ end
75
+
76
+ it %q<dumps the contents an unpublished package> do
77
+ input = <<-END
78
+ config default
79
+ set FOO=BAR
80
+ end
81
+ END
82
+ out, err =
83
+ fig(%w<--dump-package-definition-parsed>, input, :fork => false)
84
+
85
+ [input, out].each do
86
+ |string|
87
+
88
+ string.gsub!(/^[ ]+/, '')
89
+ string.gsub!(/[ ]+/, ' ')
90
+ string.strip!
91
+ end
92
+
93
+ out.should be_include input
94
+ err.should == ''
95
+ end
96
+
97
+ it %q<emits the synthetic package if there is no text> do
98
+ out, err = fig(%w<--dump-package-definition-parsed>, :fork => false)
99
+ out.should =~ / ^ \s* config \s+ default \s+ end \s* \z /x
100
+ err.should == ''
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,62 @@
1
+ # coding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+
5
+ describe 'Fig' do
6
+ describe 'environment variables' do
7
+ before(:each) do
8
+ clean_up_test_environment
9
+ set_up_test_environment
10
+
11
+ # These shouldn't matter because the commands shouldn't look at the repositories.
12
+ set_local_repository_format_to_future_version()
13
+ set_remote_repository_format_to_future_version()
14
+ end
15
+
16
+ it 'sets variable from command line' do
17
+ fig(%w<--set FOO=BAR --get FOO>)[0].should == 'BAR'
18
+
19
+ fig(%w<--set NO_VALUE_WITH_EQUALS= --list-variables>)[0].should ==
20
+ 'NO_VALUE_WITH_EQUALS='
21
+ fig(%w<--set NO_VALUE_WITHOUT_EQUALS --list-variables>)[0].should ==
22
+ 'NO_VALUE_WITHOUT_EQUALS='
23
+ end
24
+
25
+ it 'sets variable from fig file' do
26
+ input = <<-END
27
+ config default
28
+ set FOO=BAR
29
+ end
30
+ END
31
+ fig(%w<--get FOO>, input)[0].should == 'BAR'
32
+ end
33
+
34
+ it 'appends variable from command line with --add' do
35
+ fig(%w<--add PATH=foo --get PATH>).should ==
36
+ ["foo#{File::PATH_SEPARATOR}#{ENV['PATH']}", '', 0]
37
+ end
38
+
39
+ it 'appends variable from command line with --append' do
40
+ fig(%w<--append PATH=foo --get PATH>).should ==
41
+ ["foo#{File::PATH_SEPARATOR}#{ENV['PATH']}", '', 0]
42
+ end
43
+
44
+ it 'appends variable from fig file' do
45
+ input = <<-END
46
+ config default
47
+ add PATH=foo
48
+ end
49
+ END
50
+ fig(%w<--get PATH>, input).should ==
51
+ ["foo#{File::PATH_SEPARATOR}#{ENV['PATH']}", '', 0]
52
+ end
53
+
54
+ it 'appends empty variable' do
55
+ fig(%w<--append XYZZY=foo --get XYZZY>).should == ['foo', '', 0]
56
+ end
57
+
58
+ it %q<doesn't expand variables without packages> do
59
+ fig(%w<--set FOO=@bar --get FOO>)[0].should == '@bar'
60
+ end
61
+ end
62
+ end