csd 0.1.8 → 0.1.9

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.
@@ -0,0 +1,28 @@
1
+ # -*- encoding: UTF-8 -*-
2
+ require 'csd/user_interface/base'
3
+
4
+ module CSD
5
+ module UserInterface
6
+ class Silent < Base
7
+
8
+ def separator
9
+ end
10
+
11
+ def indicate_activity
12
+ end
13
+
14
+ def debug(message)
15
+ end
16
+
17
+ def info(message)
18
+ end
19
+
20
+ def warn(message)
21
+ end
22
+
23
+ def error(message)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ # -*- encoding: UTF-8 -*-
2
+
3
+ module CSD
4
+ module Vendor
5
+ # Author
6
+ #
7
+ # Copyright (c) 2005-2010 David Heinemeier Hansson
8
+ # This module is taken from Ruby on Rails' ActiveSupport
9
+ # Link: http://github.com/rails/rails/tree/master/activesupport
10
+ #
11
+ # License
12
+ #
13
+ # Active Support is released under the MIT license.
14
+ #
15
+ module ActiveSupport
16
+ # This module comprises extensions to Object (the parent of all classes).
17
+ #
18
+ module ObjectExtensions
19
+
20
+ # Makes backticks behave (somewhat more) similarly on all platforms.
21
+ # On win32 `nonexistent_command` raises Errno::ENOENT; on Unix, the
22
+ # spawned shell prints a message to stderr and sets $?. We emulate
23
+ # Unix on the former but not the latter.
24
+ def `(command) #:nodoc:
25
+ super
26
+ rescue Errno::ENOENT => e
27
+ STDERR.puts "#$0: #{e}"
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ class Object #:nodoc:
36
+ include CSD::Vendor::ActiveSupport::ObjectExtensions
37
+ end
@@ -5,21 +5,21 @@ class TestDir < Test::Unit::TestCase
5
5
 
6
6
  include CSD
7
7
 
8
- context "The Minisip application" do
8
+ context "The Minisip Base application" do
9
9
 
10
10
  setup do
11
+ ARGV.clear
11
12
  Options.clear
13
+ ARGV.push(@name)
14
+ Applications.current!
12
15
  @app = Application::Minisip::Base.new
13
16
  end
14
-
15
- teardown do
16
- end
17
17
 
18
- should "respond to valid actions" do
18
+ should "respond to a valid action" do
19
19
  assert @app.respond_to?(:compile)
20
20
  end
21
21
 
22
- should "know how to identify a subset of libraries with --only" do
22
+ should "know how to identify and sort a subset of internal MiniSIP libraries with --only" do
23
23
  Options.only = nil
24
24
  assert_equal Application::Minisip::Base::LIBRARIES, @app.libraries
25
25
  Options.only = %w{ libmcrypto }
@@ -32,8 +32,13 @@ class TestDir < Test::Unit::TestCase
32
32
  assert_equal %w{ libmutil minisip }, @app.libraries
33
33
  end
34
34
 
35
+
36
+
37
+
38
+
39
+
35
40
  context "when downloading source code" do
36
-
41
+
37
42
  should "dummy" do
38
43
  assert true
39
44
  end
@@ -0,0 +1,56 @@
1
+ require 'helper'
2
+ require 'ostruct'
3
+ require 'tmpdir'
4
+
5
+ class TestApplicationBase < Test::Unit::TestCase
6
+
7
+ include CSD
8
+
9
+ context "An application instance" do
10
+
11
+ setup do
12
+ ARGV.clear
13
+ Options.clear
14
+ @name = 'minisip'
15
+ ARGV.push(@name)
16
+ assert @app = Applications.find(@name).instance
17
+ end
18
+
19
+ should "use a temporary directory as working directory when the --temp options is given" do
20
+ Options.temp = true
21
+ @app.define_working_directory
22
+ assert_kind_of Pathname, Path.work
23
+ # We verify whether this is a tempory directory by comparing the first six characters
24
+ # of the working directory path with the path of a freshly created tmp-directory.
25
+ # TODO: Find a better way to test the creation of temporary directories
26
+ tmp_dir = Pathname.new Dir.mktmpdir
27
+ assert_equal tmp_dir.to_s[0..5], Path.work.to_s[0..5]
28
+ # Cleanup
29
+ assert Path.work.rmdir
30
+ assert tmp_dir.rmdir
31
+ end
32
+
33
+ should "accept a manual working directory parameter" do
34
+ Options.work_dir = '/my/cool/working/dir'
35
+ @app.define_working_directory
36
+ assert_kind_of Pathname, Path.work
37
+ assert_equal '/my/cool/working/dir', Path.work.to_s
38
+ end
39
+
40
+ should "overwrite the --temp option when the --work-dir option is given" do
41
+ Options.temp = true
42
+ Options.work_dir = '/'
43
+ @app.define_working_directory
44
+ assert_kind_of Pathname, Path.work
45
+ assert_equal '/', Path.work.to_s
46
+ end
47
+
48
+ should "take the current pwd with a subdirectory in the name of the application as working directory by default" do
49
+ @app.define_working_directory
50
+ assert_kind_of Pathname, Path.work
51
+ assert_equal File.join(Dir.pwd, "#{@name}.ai"), Path.work.to_s
52
+ end
53
+
54
+ end # context "An application instance"
55
+
56
+ end
@@ -0,0 +1,33 @@
1
+ require 'helper'
2
+ require 'ostruct'
3
+ require 'tmpdir'
4
+
5
+ module CSD
6
+ module Application
7
+ # This is our dummy application for testing
8
+ #
9
+ module Chess
10
+ class << self
11
+ include CSD::Application::Default
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ class TestApplicationDefault < Test::Unit::TestCase
18
+
19
+ include CSD
20
+
21
+ context "the empty, default application module" do
22
+
23
+ setup do
24
+ @mod = Application::Chess
25
+ end
26
+
27
+ should "raise an error if the instance method was called" do
28
+ assert_raise(Error::Application::NoInstanceMethod) { @mod.instance }
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -1,5 +1,6 @@
1
1
  require 'helper'
2
2
  require 'ostruct'
3
+ require 'tmpdir'
3
4
 
4
5
  class TestApplications < Test::Unit::TestCase
5
6
 
@@ -13,31 +14,31 @@ class TestApplications < Test::Unit::TestCase
13
14
  Options.clear
14
15
  end
15
16
 
16
- context "and considering a valid application" do
17
+ context "and considering an application module which can be loaded" do
17
18
 
18
19
  setup do
19
- @app = 'minisip'
20
- assert Applications.find(@app)
20
+ @name = 'minisip'
21
+ assert Applications.find(@name)
21
22
  end
22
23
 
23
24
  context "the find function" do
24
25
 
25
26
  should "find an application in the first argument" do
26
- ARGV.push(@app)
27
- assert_equal @app, Applications.current!.name
27
+ ARGV.push(@name)
28
+ assert_equal @name, Applications.current!.name
28
29
  end
29
30
 
30
31
  should "find an application in the second argument" do
31
32
  ARGV.push('dummy')
32
- ARGV.push(@app)
33
- assert_equal @app, Applications.current!.name
33
+ ARGV.push(@name)
34
+ assert_equal @name, Applications.current!.name
34
35
  end
35
36
 
36
37
  should "find an application in the third argument" do
37
38
  ARGV.push('foo')
38
39
  ARGV.push('bar')
39
- ARGV.push(@app)
40
- assert_equal @app, Applications.current!.name
40
+ ARGV.push(@name)
41
+ assert_equal @name, Applications.current!.name
41
42
  end
42
43
 
43
44
  should "set nothing, if there is no valid app" do
@@ -50,17 +51,21 @@ class TestApplications < Test::Unit::TestCase
50
51
  end # context "the find function"
51
52
 
52
53
  context "the application module" do
54
+
55
+ should "implement an instance method" do
56
+ assert Applications.find(@name).respond_to?(:instance)
57
+ end
53
58
 
54
59
  should "know its name" do
55
- assert_equal @app, Applications.find(@app).name
60
+ assert_equal @name, Applications.find(@name).name
56
61
  end
57
62
 
58
63
  should "respond to options with a string" do
59
- assert_kind_of(String, Applications.find(@app).options)
60
- assert_kind_of(String, Applications.find(@app).options('install'))
61
- assert_kind_of(String, Applications.find(@app).options('not_a_valid_action'))
64
+ assert_kind_of(String, Applications.find(@name).options)
65
+ assert_kind_of(String, Applications.find(@name).options('install'))
66
+ assert_kind_of(String, Applications.find(@name).options('not_a_valid_action'))
62
67
  end
63
-
68
+
64
69
  end # context "the application module"
65
70
 
66
71
  end # context "and considering a valid application, find"
@@ -0,0 +1,80 @@
1
+ require 'helper'
2
+
3
+ class TestApplications < Test::Unit::TestCase
4
+
5
+ include CSD
6
+
7
+ context "The CLI instance" do
8
+
9
+ setup do
10
+ Options.clear
11
+ Options.testmode = true
12
+ Options.silent = false
13
+ assert_instance_of UserInterface::CLI, CSD.ui
14
+ end
15
+
16
+ should "be able to indicate activity by printing periods" do
17
+ out, err = capture do
18
+ UI.indicate_activity
19
+ UI.indicate_activity
20
+ UI.indicate_activity
21
+ end
22
+ assert_equal '...', out
23
+ assert_equal '', err
24
+ end
25
+
26
+ should "represent a separator by a new line" do
27
+ out, err = capture do
28
+ UI.separator
29
+ UI.separator
30
+ UI.separator
31
+ end
32
+ assert_equal "\n\n\n", out
33
+ assert_equal '', err
34
+ end
35
+
36
+ should "log debugging messages in debug mode" do
37
+ Options.debug = true
38
+ out, err = capture do
39
+ UI.debug "debugging"
40
+ end
41
+ assert_match /debugging/, out
42
+ assert_equal '', err
43
+ end
44
+
45
+ should "NOT log debugging messages UNLESS debug mode" do
46
+ Options.debug = false
47
+ out, err = capture do
48
+ UI.debug "debugging"
49
+ end
50
+ assert_equal '', out
51
+ assert_equal '', err
52
+ end
53
+
54
+ should "log info messages" do
55
+ out, err = capture do
56
+ UI.info "informing"
57
+ end
58
+ assert_match /informing/, out
59
+ assert_equal '', err
60
+ end
61
+
62
+ should "log warning messages" do
63
+ out, err = capture do
64
+ UI.warn "waaarning"
65
+ end
66
+ assert_match /waaarning/, out
67
+ assert_equal '', err
68
+ end
69
+
70
+ should "log error messages to STDOUT" do
71
+ out, err = capture do
72
+ UI.error "erroring"
73
+ end
74
+ assert_equal '', out
75
+ assert_match /erroring/, err
76
+ end
77
+
78
+ end # context "An CLI instance"
79
+
80
+ end
@@ -72,18 +72,23 @@ That we in truth can nothing know!}
72
72
  ensure_mkdir(@dir)
73
73
  @dir.chmod(0000)
74
74
  assert_kind_of(CommandResult, result = Cmd.mkdir(File.join(@dir, 'subdir_in_readonly_dir'), :die_on_failure => false))
75
- assert !result.success?
75
+ if superuser?
76
+ assert result.success?
77
+ assert result.writable?
78
+ else
79
+ assert !result.success?
80
+ assert !result.writable?
81
+ end
76
82
  assert !result.already_existed?
77
- assert !result.writable?
78
83
  @dir.chmod(0777) # Cleanup
79
84
  end
80
85
 
81
86
  should "notify if there is no permission to create a new directory with die_on_failure" do
82
87
  ensure_mkdir(@dir)
83
88
  @dir.chmod(0000)
84
- assert_raise(Error::UI::Die) {
89
+ assert_raise(Error::Command::MkdirFailed) {
85
90
  Cmd.mkdir(File.join(@dir, 'subdir_in_readonly_dir'), :die_on_failure => true)
86
- }
91
+ } unless superuser?
87
92
  @dir.chmod(0777) # Cleanup
88
93
  end
89
94
 
@@ -93,7 +98,7 @@ That we in truth can nothing know!}
93
98
  assert_kind_of(CommandResult, result = Cmd.mkdir(@dir))
94
99
  assert result.success?
95
100
  assert result.already_existed?
96
- assert !result.writable?
101
+ superuser? ? assert(result.writable?) : assert(!result.writable?)
97
102
  @dir.chmod(0777) # Cleanup
98
103
  end
99
104
 
@@ -117,7 +122,7 @@ That we in truth can nothing know!}
117
122
 
118
123
  should "realize when the target is not a directory, but a file or something with die_on_failure" do
119
124
  testfile_path = File.join(@tmp, 'testfile')
120
- assert_raise(Error::UI::Die) {
125
+ assert_raise(Error::Command::CdFailed) {
121
126
  Cmd.cd(testfile_path, :die_on_failure => true)
122
127
  }
123
128
  end
@@ -128,7 +133,7 @@ That we in truth can nothing know!}
128
133
  end
129
134
 
130
135
  should "realize when the target doesn't exist with die_on_failure" do
131
- assert_raise(Error::UI::Die) {
136
+ assert_raise(Error::Command::CdFailed) {
132
137
  Cmd.cd('/i/for/sure/dont/exist', :die_on_failure => true)
133
138
  }
134
139
  end
@@ -189,7 +194,7 @@ That we in truth can nothing know!}
189
194
  end
190
195
 
191
196
  should "know when a source file doesn't exist with die_on_failure" do
192
- assert_raise(Error::UI::Die) {
197
+ assert_raise(Error::Command::CopyFailed) {
193
198
  Cmd.copy('/no/source', @subdir, :die_on_failure => true)
194
199
  }
195
200
  end
@@ -200,7 +205,7 @@ That we in truth can nothing know!}
200
205
  end
201
206
 
202
207
  should "know when a destination directory doesn't exist with die_on_failure" do
203
- assert_raise(Error::UI::Die) {
208
+ assert_raise(Error::Command::CopyFailed) {
204
209
  Cmd.copy(@file1, '/no/destination', :die_on_failure => true)
205
210
  }
206
211
  end
@@ -231,7 +236,7 @@ That we in truth can nothing know!}
231
236
  end
232
237
 
233
238
  should "know when a source file doesn't exist with die_on_failure" do
234
- assert_raise(Error::UI::Die) {
239
+ assert_raise(Error::Command::MoveFailed) {
235
240
  Cmd.move('/no/source', @subdir, :die_on_failure => true)
236
241
  }
237
242
  end
@@ -257,7 +262,7 @@ That we in truth can nothing know!}
257
262
  end
258
263
 
259
264
  should "be unsuccessful if the file doesn't exist with die_on_failure" do
260
- assert_raise(Error::UI::Die) {
265
+ assert_raise(Error::Command::ReplaceFailed) {
261
266
  Cmd.replace('/i/am/not/there', 'FAUST', 'GOETHE')
262
267
  }
263
268
  end
@@ -290,39 +295,78 @@ That we in truth can nothing know!}
290
295
  end # context "As a directory function"
291
296
 
292
297
  context "run" do
293
-
294
- setup do
295
- Options.silent = true
296
- Options.reveal = false
297
- Options.online = true # Some tests need an uplink to the Internet. For now, we will hardcode here so that they should be executed.
298
- Options.testmode = true # This puts us in test-mode, basically to prevent STDOUT and STDERR to show unnecessary output.
299
- end
300
298
 
301
- should "return a successfull CommandResult if the command was OK" do
302
- assert_kind_of(CommandResult, result = Cmd.run('cd'))
303
- assert_kind_of(Process::Status, result.status)
304
- assert result.success?
305
- end
306
-
307
- should "not produce any output in :internal mode and in non-verbose mode" do
308
- Options.testmode = false
309
- out, err = capture do
310
- assert_kind_of(CommandResult, result = Cmd.run('ls', :internal => true))
299
+ context "in normal mode" do
300
+
301
+ setup do
302
+ Options.clear
303
+ Options.testmode = true
304
+ Options.silent = false
311
305
  end
312
- assert_equal '', out
313
- end
314
306
 
315
- should "should produce output in NON-:internal mode and in non-verbose mode" do
316
- out, err = capture do
317
- assert_kind_of(CommandResult, result = Cmd.run('which ls', :internal => false))
307
+ should "not produce any output in :internal mode" do
308
+ out, err = capture do
309
+ assert_kind_of(CommandResult, result = Cmd.run('ls', :internal => true))
310
+ end
311
+ assert_equal '', out
312
+ assert_equal '', err
318
313
  end
319
- assert_equal('.', out)
320
- end
314
+
315
+ should "produce output in :internal mode" do
316
+ out, err = capture do
317
+ assert_kind_of(CommandResult, result = Cmd.run('ls', :internal => false))
318
+ end
319
+ assert_match /\.+/, out # Make sure it contains only periods
320
+ assert_equal '', err
321
+ end
322
+
323
+ context "in verbose mode" do
324
+
325
+ setup do
326
+ Options.verbose = true
327
+ end
328
+
329
+ should "produce verbose output" do
330
+ out, err = capture do
331
+ assert_kind_of(CommandResult, result = Cmd.run('ls', :internal => false))
332
+ end
333
+ assert out.size > 0
334
+ assert_match /[^\.]/, out # Match anything that is not a period
335
+ assert_equal '', err
336
+ end
321
337
 
322
- should "return a non-successfull CommandResult if the command was bad without die_on_failure" do
323
- assert_kind_of(CommandResult, result = Cmd.run('this-command-does-not-exist', :die_on_failure => false))
324
- assert !result.success?
325
- end
338
+ end # context "in verbose mode"
339
+
340
+ end # context "in normal mode"
341
+
342
+ context "in silent mode" do
343
+
344
+ setup do
345
+ Options.clear
346
+ Options.testmode = true
347
+ Options.silent = true
348
+ end
349
+
350
+ should "return a successfull CommandResult if the command was OK" do
351
+ assert_kind_of(CommandResult, result = Cmd.run('cd'))
352
+ assert_kind_of(Process::Status, result.status)
353
+ assert result.success?
354
+ end
355
+
356
+ should "not produce any output" do
357
+ out, err = capture do
358
+ assert_kind_of(CommandResult, result = Cmd.run('ls', :internal => false))
359
+ end
360
+ assert_equal '', out
361
+ end
362
+
363
+ should "return a non-successfull CommandResult if the command was bad without die_on_failure" do
364
+ assert_kind_of(CommandResult, result = Cmd.run('this-command-does-not-exist', :die_on_failure => false))
365
+ assert !result.success?
366
+ end
367
+
368
+
369
+ end # context "in silent mode"
326
370
 
327
371
  end
328
372
 
@@ -348,7 +392,7 @@ That we in truth can nothing know!}
348
392
  assert result.success?
349
393
  assert @dir.directory?
350
394
  assert File.exist?(File.join(@dir, 'dummy.txt'))
351
- end if Options.online
395
+ end if ONLINE
352
396
 
353
397
  should "do nothing at the destination in reveal mode" do
354
398
  Options.reveal = true