scout-essentials 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.vimproject +78 -0
  4. data/Gemfile +14 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +18 -0
  7. data/Rakefile +47 -0
  8. data/VERSION +1 -0
  9. data/lib/scout/cmd.rb +348 -0
  10. data/lib/scout/concurrent_stream.rb +284 -0
  11. data/lib/scout/config.rb +168 -0
  12. data/lib/scout/exceptions.rb +77 -0
  13. data/lib/scout/indiferent_hash/case_insensitive.rb +30 -0
  14. data/lib/scout/indiferent_hash/options.rb +115 -0
  15. data/lib/scout/indiferent_hash.rb +96 -0
  16. data/lib/scout/log/color.rb +224 -0
  17. data/lib/scout/log/color_class.rb +269 -0
  18. data/lib/scout/log/fingerprint.rb +69 -0
  19. data/lib/scout/log/progress/report.rb +244 -0
  20. data/lib/scout/log/progress/util.rb +173 -0
  21. data/lib/scout/log/progress.rb +106 -0
  22. data/lib/scout/log/trap.rb +107 -0
  23. data/lib/scout/log.rb +441 -0
  24. data/lib/scout/meta_extension.rb +100 -0
  25. data/lib/scout/misc/digest.rb +63 -0
  26. data/lib/scout/misc/filesystem.rb +25 -0
  27. data/lib/scout/misc/format.rb +255 -0
  28. data/lib/scout/misc/helper.rb +31 -0
  29. data/lib/scout/misc/insist.rb +56 -0
  30. data/lib/scout/misc/monitor.rb +66 -0
  31. data/lib/scout/misc/system.rb +73 -0
  32. data/lib/scout/misc.rb +10 -0
  33. data/lib/scout/named_array.rb +138 -0
  34. data/lib/scout/open/lock/lockfile.rb +587 -0
  35. data/lib/scout/open/lock.rb +68 -0
  36. data/lib/scout/open/remote.rb +135 -0
  37. data/lib/scout/open/stream.rb +491 -0
  38. data/lib/scout/open/util.rb +244 -0
  39. data/lib/scout/open.rb +170 -0
  40. data/lib/scout/path/find.rb +204 -0
  41. data/lib/scout/path/tmpfile.rb +8 -0
  42. data/lib/scout/path/util.rb +127 -0
  43. data/lib/scout/path.rb +51 -0
  44. data/lib/scout/persist/open.rb +17 -0
  45. data/lib/scout/persist/path.rb +15 -0
  46. data/lib/scout/persist/serialize.rb +157 -0
  47. data/lib/scout/persist.rb +104 -0
  48. data/lib/scout/resource/open.rb +8 -0
  49. data/lib/scout/resource/path.rb +80 -0
  50. data/lib/scout/resource/produce/rake.rb +69 -0
  51. data/lib/scout/resource/produce.rb +151 -0
  52. data/lib/scout/resource/scout.rb +3 -0
  53. data/lib/scout/resource/software.rb +178 -0
  54. data/lib/scout/resource/util.rb +59 -0
  55. data/lib/scout/resource.rb +40 -0
  56. data/lib/scout/simple_opt/accessor.rb +54 -0
  57. data/lib/scout/simple_opt/doc.rb +126 -0
  58. data/lib/scout/simple_opt/get.rb +57 -0
  59. data/lib/scout/simple_opt/parse.rb +67 -0
  60. data/lib/scout/simple_opt/setup.rb +26 -0
  61. data/lib/scout/simple_opt.rb +5 -0
  62. data/lib/scout/tmpfile.rb +129 -0
  63. data/lib/scout-essentials.rb +10 -0
  64. data/scout-essentials.gemspec +143 -0
  65. data/share/color/color_names +507 -0
  66. data/share/color/diverging_colors.hex +12 -0
  67. data/share/software/install_helpers +523 -0
  68. data/test/scout/indiferent_hash/test_case_insensitive.rb +16 -0
  69. data/test/scout/indiferent_hash/test_options.rb +46 -0
  70. data/test/scout/log/test_color.rb +0 -0
  71. data/test/scout/log/test_progress.rb +108 -0
  72. data/test/scout/misc/test_digest.rb +30 -0
  73. data/test/scout/misc/test_filesystem.rb +30 -0
  74. data/test/scout/misc/test_insist.rb +13 -0
  75. data/test/scout/misc/test_system.rb +21 -0
  76. data/test/scout/open/test_lock.rb +52 -0
  77. data/test/scout/open/test_remote.rb +25 -0
  78. data/test/scout/open/test_stream.rb +676 -0
  79. data/test/scout/open/test_util.rb +73 -0
  80. data/test/scout/path/test_find.rb +110 -0
  81. data/test/scout/path/test_util.rb +22 -0
  82. data/test/scout/persist/test_open.rb +37 -0
  83. data/test/scout/persist/test_path.rb +37 -0
  84. data/test/scout/persist/test_serialize.rb +114 -0
  85. data/test/scout/resource/test_path.rb +58 -0
  86. data/test/scout/resource/test_produce.rb +94 -0
  87. data/test/scout/resource/test_software.rb +24 -0
  88. data/test/scout/resource/test_util.rb +38 -0
  89. data/test/scout/simple_opt/test_doc.rb +16 -0
  90. data/test/scout/simple_opt/test_get.rb +11 -0
  91. data/test/scout/simple_opt/test_parse.rb +10 -0
  92. data/test/scout/simple_opt/test_setup.rb +77 -0
  93. data/test/scout/test_cmd.rb +85 -0
  94. data/test/scout/test_concurrent_stream.rb +29 -0
  95. data/test/scout/test_config.rb +66 -0
  96. data/test/scout/test_indiferent_hash.rb +26 -0
  97. data/test/scout/test_log.rb +32 -0
  98. data/test/scout/test_meta_extension.rb +80 -0
  99. data/test/scout/test_misc.rb +6 -0
  100. data/test/scout/test_named_array.rb +43 -0
  101. data/test/scout/test_open.rb +146 -0
  102. data/test/scout/test_path.rb +54 -0
  103. data/test/scout/test_persist.rb +186 -0
  104. data/test/scout/test_resource.rb +26 -0
  105. data/test/scout/test_tmpfile.rb +53 -0
  106. data/test/test_helper.rb +50 -0
  107. metadata +247 -0
@@ -0,0 +1,77 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require 'scout/simple_opt'
3
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
4
+
5
+ class TestSOPTSetup < Test::Unit::TestCase
6
+ def setup
7
+ SOPT.inputs = nil
8
+ SOPT.input_types = nil
9
+ SOPT.input_descriptions = nil
10
+ SOPT.input_shortcuts = nil
11
+ end
12
+
13
+ def test_setup
14
+ SOPT.setup <<-EOF
15
+ Test application
16
+
17
+ $ test cmd -arg 1
18
+
19
+ It does some imaginary stuff
20
+
21
+ -a--arg* Argument
22
+ -a2--arg2* Argument
23
+
24
+ EOF
25
+
26
+ assert_equal "test cmd -arg 1", SOPT.synopsys
27
+ assert SOPT.inputs.include? "arg"
28
+ assert SOPT.inputs.include? "arg2"
29
+ end
30
+
31
+ def test_setup_alt
32
+ SOPT.setup <<-EOF
33
+ Test application
34
+
35
+ It does some imaginary stuff
36
+
37
+ -a--arg* Argument
38
+ -a2--arg2* Argument
39
+
40
+ EOF
41
+
42
+ assert SOPT.inputs.include? "arg"
43
+ assert SOPT.inputs.include? "arg2"
44
+ end
45
+
46
+ def test_setup_alt2
47
+ SOPT.setup <<-EOF
48
+ Test application
49
+
50
+ -a--arg* Argument
51
+ -a2--arg2* Argument
52
+
53
+ EOF
54
+
55
+ assert SOPT.inputs.include? "arg"
56
+ assert SOPT.inputs.include? "arg2"
57
+ end
58
+
59
+ def test_setup_alt3
60
+ SOPT.setup <<-EOF
61
+ Pulls the values from a tsv colum
62
+
63
+ $ rbbt tsv values [options] <filename.tsv|->
64
+
65
+ Use - to read from STDIN
66
+
67
+ -tch--tokyocabinet File is a tokyocabinet hash database
68
+ -tcb--tokyocabinet_bd File is a tokyocabinet B database
69
+ -h--help Print this help
70
+ EOF
71
+
72
+ assert SOPT.inputs.include? "tokyocabinet"
73
+ end
74
+
75
+ end
76
+
77
+
@@ -0,0 +1,85 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/open'
5
+
6
+ class TestCmd < Test::Unit::TestCase
7
+
8
+ def test_cmd_option_string
9
+ assert_equal("--user-agent 'firefox'", CMD.process_cmd_options("--user-agent" => "firefox"))
10
+ assert_equal("--user-agent='firefox'", CMD.process_cmd_options("--user-agent=" => "firefox"))
11
+ assert_equal("-q", CMD.process_cmd_options("-q" => true))
12
+ assert_equal("", CMD.process_cmd_options("-q" => nil))
13
+ assert_equal("", CMD.process_cmd_options("-q" => false))
14
+
15
+ assert(CMD.process_cmd_options("--user-agent" => "firefox", "-q" => true) =~ /--user-agent 'firefox'/)
16
+ assert(CMD.process_cmd_options("--user-agent" => "firefox", "-q" => true) =~ /-q/)
17
+ end
18
+
19
+ def test_cmd
20
+ assert_equal("test\n", CMD.cmd("echo '{opt}' test").read)
21
+ assert_equal("test", CMD.cmd("echo '{opt}' test", "-n" => true).read)
22
+ assert_equal("test2\n", CMD.cmd("cut", "-f" => 2, "-d" => ' ', :in => "test1 test2").read)
23
+ end
24
+
25
+ def test_pipe
26
+ assert_equal("test\n", CMD.cmd("echo test", :pipe => true).read)
27
+ assert_equal("test\n", CMD.cmd("echo '{opt}' test", :pipe => true).read)
28
+ assert_equal("test", CMD.cmd("echo '{opt}' test", "-n" => true, :pipe => true).read)
29
+ assert_equal("test2\n", CMD.cmd("cut", "-f" => 2, "-d" => ' ', :in => "test1 test2", :pipe => true).read)
30
+ end
31
+
32
+ def test_error
33
+ Log.with_severity 6 do
34
+ assert_raise ProcessFailed do CMD.cmd('fake-command') end
35
+ assert_raise ProcessFailed do CMD.cmd('ls -fake_option') end
36
+
37
+ assert_raise ProcessFailed do CMD.cmd('fake-command', :stderr => true) end
38
+ assert_raise ProcessFailed do CMD.cmd('ls -fake_option', :stderr => true) end
39
+
40
+ assert_nothing_raised ProcessFailed do CMD.cmd('fake-command', :no_fail => true, :pipe => true) end
41
+ assert_nothing_raised ProcessFailed do CMD.cmd('ls -fake_option', :no_fail => true, :pipe => true) end
42
+
43
+ assert_raise ProcessFailed do CMD.cmd('fake-command', :stderr => true, :pipe => true).join end
44
+ assert_raise ConcurrentStreamProcessFailed do CMD.cmd('ls -fake_option', :stderr => true, :pipe => true).join end
45
+ end
46
+ end
47
+
48
+ def test_pipes
49
+ text = <<-EOF
50
+ line1
51
+ line2
52
+ line3
53
+ line11
54
+ line22
55
+ line33
56
+ EOF
57
+
58
+ TmpFile.with_file(text * 100) do |file|
59
+
60
+ Open.open(file) do |f|
61
+ io = CMD.cmd('tail -n 10', :in => f, :pipe => true)
62
+ io2 = CMD.cmd('head -n 10', :in => io, :pipe => true)
63
+ io3 = CMD.cmd('head -n 10', :in => io2, :pipe => true)
64
+ assert_equal 10, io3.read.split(/\n/).length
65
+ end
66
+ end
67
+ end
68
+
69
+ def test_STDIN_close
70
+ TmpFile.with_file("Hello") do |file|
71
+ STDIN.close
72
+ Open.open(file) do |f|
73
+ io = CMD.cmd("tr 'e' 'E'", :in => f, :pipe => true)
74
+ txt = io.read
75
+ io.join
76
+ assert_equal "HEllo", txt
77
+ end
78
+ end
79
+ end
80
+
81
+ def test_bash
82
+ assert_equal "TEST", CMD.bash("echo TEST").read.strip
83
+ assert_equal ENV["HOME"], CMD.bash("echo $HOME").read.strip
84
+ end
85
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/exceptions'
5
+ require 'scout/cmd'
6
+
7
+ class TestClass < Test::Unit::TestCase
8
+ def test_concurrent_stream_pipe
9
+ io = CMD.cmd("ls", :pipe => true, :autojoin => true)
10
+ io.read
11
+ io.close
12
+ end
13
+
14
+ def test_concurrent_stream_process_failed
15
+ assert_raise ConcurrentStreamProcessFailed do
16
+ io = CMD.cmd("grep . NONEXISTINGFILE", :pipe => true, :autojoin => true)
17
+ io.read
18
+ io.close
19
+ end
20
+ end
21
+
22
+ def test_concurrent_stream_process_failed_autojoin
23
+ assert_raise ConcurrentStreamProcessFailed do
24
+ io = CMD.cmd("grep . NONEXISTINGFILE", :pipe => true, :autojoin => true)
25
+ io.read
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,66 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestConfig < Test::Unit::TestCase
5
+ setup do
6
+ Scout::Config.set({:cpus => 30}, :test_config, :test)
7
+ Scout::Config.set(:cpus, 5, "slow::2", :test)
8
+ Scout::Config.set({:token => "token"}, "token")
9
+ Scout::Config.set(:notoken, "no_token")
10
+ Scout::Config.set({:emptytoken => "empty"})
11
+ end
12
+
13
+ def test_simple
14
+ assert_equal 30, Scout::Config.get(:cpus, :test_config)
15
+ end
16
+
17
+ def test_match
18
+ assert_equal({20 => ["token"]}, Scout::Config.match({["key:token"] => "token"}, "key:token"))
19
+ end
20
+
21
+ def test_simple_no_token
22
+ assert_equal "token", Scout::Config.get("token", "token")
23
+ assert_equal "no_token", Scout::Config.get("notoken", "key:notoken")
24
+ assert_equal 'token', Scout::Config.get("token", "key:token")
25
+ assert_equal 'token', Scout::Config.get("token")
26
+ assert_equal nil, Scout::Config.get("token", "someotherthing")
27
+ assert_equal "default_token", Scout::Config.get("token", 'unknown', :default => 'default_token')
28
+ assert_equal 'empty', Scout::Config.get("emptytoken", 'key:emptytoken')
29
+ end
30
+
31
+ def test_prio
32
+ assert_equal 5, Scout::Config.get(:cpus, :slow, :test)
33
+ end
34
+
35
+ def test_with_config
36
+ Scout::Config.add_entry 'key', 'valueA', 'token'
37
+ assert_equal "valueA", Scout::Config.get('key', 'token')
38
+ assert_equal "default", Scout::Config.get('key2', 'token', :default => 'default')
39
+
40
+ Scout::Config.with_config do
41
+ Scout::Config.add_entry 'key', 'valueB', 'token'
42
+ Scout::Config.add_entry 'key2', 'valueB2', 'token'
43
+ assert_equal "valueB", Scout::Config.get('key', 'token')
44
+ assert_equal "valueB2", Scout::Config.get('key2', 'token', :default => 'default')
45
+ end
46
+
47
+ assert_equal "valueA", Scout::Config.get('key', 'token')
48
+ assert_equal "default", Scout::Config.get('key2', 'token', :default => 'default')
49
+ end
50
+
51
+ def test_order
52
+ Scout::Config.add_entry 'key', 'V1', 'token1'
53
+ Scout::Config.add_entry 'key', 'V2', 'token2'
54
+ Scout::Config.add_entry 'key', 'V3', 'token2'
55
+
56
+ assert_equal "V3", Scout::Config.get('key', 'token2')
57
+ assert_equal "V1", Scout::Config.get('key', 'token1')
58
+ assert_equal "V3", Scout::Config.get('key', 'token2', 'token1')
59
+ assert_equal "V1", Scout::Config.get('key', 'token1', 'token2')
60
+ end
61
+
62
+ def test_default
63
+ Scout::Config.add_entry 'key', 'V1', 'token1'
64
+ assert_equal "V3", Scout::Config.get('key', 'token2', :default => 'V3')
65
+ end
66
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestClass < Test::Unit::TestCase
5
+ def test_indiferent_hash
6
+ a = {:a => 1, "b" => 2}
7
+ a.extend IndiferentHash
8
+
9
+ assert_equal 1, a[:a]
10
+ assert_equal 1, a["a"]
11
+ assert_equal 2, a["b"]
12
+ assert_equal 2, a[:b]
13
+ end
14
+
15
+ def test_case_insensitive_hash
16
+ a = {:a => 1, "b" => 2}
17
+ a.extend CaseInsensitiveHash
18
+
19
+ assert_equal 1, a[:a]
20
+ assert_equal 1, a["A"]
21
+ assert_equal 1, a[:A]
22
+ assert_equal 2, a["B"]
23
+ assert_equal 2, a[:b]
24
+ end
25
+ end
26
+
@@ -0,0 +1,32 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestLog < Test::Unit::TestCase
5
+ def test_get_level
6
+ assert_equal 0, Log.get_level(:debug)
7
+ assert_equal 1, Log.get_level(:low)
8
+ assert_equal 1, Log.get_level("LOW")
9
+ assert_equal 1, Log.get_level(1)
10
+ assert_equal 0, Log.get_level(nil)
11
+ end
12
+
13
+ def test_color
14
+ assert Log.color(:green, "green")
15
+ end
16
+
17
+ def test_iif
18
+ TmpFile.with_file do |tmp|
19
+ Log.logfile(tmp)
20
+ iif :foo
21
+ assert File.read(tmp).include? ":foo"
22
+ assert File.read(tmp).include? "INFO"
23
+ end
24
+ end
25
+
26
+ def test_tty_size
27
+ assert Integer === Log.tty_size
28
+ end
29
+
30
+ end
31
+
32
+
@@ -0,0 +1,80 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestMetaExtension < Test::Unit::TestCase
5
+ module ExtensionClass
6
+ extend MetaExtension
7
+
8
+ extension_attr :code, :code2
9
+ end
10
+
11
+ module ExtensionClass2
12
+ extend MetaExtension
13
+
14
+ extension_attr :code3, :code4
15
+ end
16
+
17
+
18
+ def test_setup_annotate
19
+ str = "String"
20
+ ExtensionClass.setup(str, :code)
21
+ assert ExtensionClass === str
22
+ assert_equal :code, str.code
23
+
24
+ str2 = "String2"
25
+ str.annotate(str2)
26
+ assert_equal :code, str2.code
27
+ end
28
+
29
+ def test_marshal
30
+ str = "String"
31
+ ExtensionClass.setup(str, :code)
32
+ assert ExtensionClass === str
33
+ assert_equal :code, str.code
34
+
35
+ str2 = Marshal.load(Marshal.dump(str))
36
+ assert_equal :code, str2.code
37
+ end
38
+
39
+ def test_setup_alternatives
40
+ str = "String"
41
+
42
+ ExtensionClass.setup(str, :code2 => :code)
43
+ assert_equal :code, str.code2
44
+
45
+ ExtensionClass.setup(str, code2: :code)
46
+ assert_equal :code, str.code2
47
+
48
+ ExtensionClass.setup(str, "code2" => :code)
49
+ assert_equal :code, str.code2
50
+
51
+ end
52
+
53
+ def test_setup_block
54
+ o = ExtensionClass.setup nil, :code => :c, :code2 => :c2 do
55
+ puts 1
56
+ end
57
+
58
+ assert o.extension_attr_hash.include?(:code)
59
+ assert o.extension_attr_hash.include?(:code2)
60
+ end
61
+
62
+ def test_twice
63
+ str = "String"
64
+
65
+ ExtensionClass.setup(str, :code2 => :code)
66
+ assert_equal :code, str.code2
67
+ assert_include str.instance_variable_get(:@extension_attrs), :code
68
+
69
+ str.extend ExtensionClass2
70
+ str.code3 = :code_alt
71
+ assert_equal :code, str.code2
72
+ assert_equal :code_alt, str.code3
73
+ assert_include str.instance_variable_get(:@extension_attrs), :code
74
+ assert_include str.instance_variable_get(:@extension_attrs), :code3
75
+
76
+ assert_include str.extension_attr_hash, :code
77
+ assert_include str.extension_attr_hash, :code3
78
+ end
79
+ end
80
+
@@ -0,0 +1,6 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestMisc < Test::Unit::TestCase
5
+ end
6
+
@@ -0,0 +1,43 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestNamedArray < Test::Unit::TestCase
5
+ def test_identify_names
6
+ names =<<-EOF.split("\n")
7
+ ValueA
8
+ ValueB (Entity type)
9
+ 15
10
+ EOF
11
+ assert_equal 0, NamedArray.identify_name(names, "ValueA")
12
+ assert_equal :key, NamedArray.identify_name(names, :key)
13
+ assert_equal 0, NamedArray.identify_name(names, nil)
14
+ assert_equal 1, NamedArray.identify_name(names, "ValueB (Entity type)")
15
+ assert_equal 1, NamedArray.identify_name(names, "ValueB")
16
+ assert_equal 1, NamedArray.identify_name(names, 1)
17
+ end
18
+
19
+ def test_missing_field
20
+ a = NamedArray.setup([1,2], [:a, :b])
21
+ assert_equal 1, a[:a]
22
+ assert_equal nil, a[:c]
23
+ end
24
+
25
+ def test_zip_fields
26
+ a = [%w(a b), %w(1 1)]
27
+ assert_equal [%w(a 1), %w(b 1)], NamedArray.zip_fields(a)
28
+ end
29
+
30
+ def test_add_zipped
31
+ a = [%w(a b), %w(1 1)]
32
+ NamedArray.add_zipped a, [%w(c), %w(1)]
33
+ NamedArray.add_zipped a, [%w(d), %w(1)]
34
+ assert_equal [%w(a b c d), %w(1 1 1 1)], a
35
+ end
36
+
37
+ def test_method_missing
38
+ a = NamedArray.setup([1,2], [:a, :b])
39
+ assert_equal 1, a.a
40
+ assert_equal 2, a.b
41
+ end
42
+ end
43
+
@@ -0,0 +1,146 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestOpen < Test::Unit::TestCase
5
+
6
+ def test_read
7
+ content =<<-EOF
8
+ 1
9
+ 2
10
+ 3
11
+ 4
12
+ EOF
13
+ TmpFile.with_file(content) do |file|
14
+ sum = 0
15
+ Open.read file do |line| sum += line.to_i end
16
+ assert_equal(1 + 2 + 3 + 4, sum)
17
+ assert_equal(content, Open.read(file))
18
+ end
19
+ end
20
+
21
+ def test_gzip
22
+ content =<<-EOF
23
+ 1
24
+ 2
25
+ 3
26
+ 4
27
+ EOF
28
+ TmpFile.with_file(content) do |file|
29
+ `gzip #{file}`
30
+ assert_equal(content, Open.read(file + '.gz'))
31
+ FileUtils.rm file + '.gz'
32
+ end
33
+ end
34
+
35
+
36
+
37
+ #def test_wget
38
+ # assert(Misc.fixutf8(Open.wget('http://google.com', :quiet => true).read) =~ /html/)
39
+ #end
40
+
41
+ #def test_nice
42
+ # nice = 0.5
43
+
44
+ # t = Time.now
45
+ # Open.wget('http://google.com', :quiet => true, :nice => nice).read
46
+ # assert(Time.now - t + 0.5 >= nice)
47
+
48
+ # Open.wget('http://google.com', :quiet => true, :nice => nice, :nice_key => 1).read
49
+ # t = Time.now
50
+ # Open.wget('http://google.com', :quiet => true, :nice => nice, :nice_key => 1).read
51
+ # assert(Time.now - t + 0.5 >= nice)
52
+ #end
53
+
54
+ #def test_remote?
55
+ # assert(Open.remote?('http://google.com'))
56
+ # assert(! Open.remote?('~/.bashrc'))
57
+ #end
58
+
59
+ #def test_open
60
+ # assert(Open.read('http://google.com', :quiet => true, :nocache => :update) =~ /html/)
61
+ #end
62
+
63
+ #def test_repo_dir
64
+ # file1 = "TEST"
65
+ # file2 = "TEST" * 1000
66
+ # TmpFile.with_file do |tmpdir|
67
+ # tmpdir = Rbbt.tmp.repo_dir.find
68
+ # normal = File.join(tmpdir, 'normal')
69
+ # repo = File.join(tmpdir, 'repo')
70
+
71
+ # Open.repository_dirs.push(repo)
72
+
73
+ # Misc.benchmark(100) do
74
+ # filename = "file" << (rand * 100).to_i.to_s
75
+ # Open.write(File.join(normal, filename), file2)
76
+ # 100.times do
77
+ # Open.read(File.join(normal, filename))
78
+ # end
79
+ # end
80
+
81
+ # Misc.benchmark(100) do
82
+ # filename = "file" << (rand * 100).to_i.to_s
83
+ # Open.write(File.join(repo, filename), file2)
84
+ # 100.times do
85
+ # Open.read(File.join(repo, filename))
86
+ # end
87
+ # end
88
+ # end
89
+ #end
90
+ #
91
+ #def test_repo_dir2
92
+ # TmpFile.with_file do |tmpdir|
93
+ # tmpdir = Rbbt.tmp.repo_dir.find
94
+ # repo = File.join(tmpdir, 'repo')
95
+
96
+ # Open.repository_dirs.push(repo)
97
+
98
+ # obj = { :a => "???a"}
99
+ # filename = "file" << (rand * 100).to_i.to_s
100
+ # Open.write(File.join(repo, filename), Marshal.dump(obj))
101
+ # dump = Open.read(File.join(repo, filename))
102
+ # obj_cp = Marshal.load(dump)
103
+ # assert_equal obj, obj_cp
104
+ # end
105
+ #end
106
+
107
+ #def test_repo_marshal
108
+ # TmpFile.with_file do |tmpdir|
109
+ # tmpdir = Rbbt.tmp.repo_dir.find
110
+ # repo = File.join(tmpdir, 'repo')
111
+
112
+ # filename = 'file'
113
+ # Open.repository_dirs.push(repo)
114
+
115
+ # obj = {:a => "string", :pid => nil, :num => 1000, :p => Rbbt.tmp.foo}
116
+ # Open.write(File.join(repo, filename), Marshal.dump(obj))
117
+ # new =Open.open(File.join(repo, filename)) do |f|
118
+ # Marshal.load(f)
119
+ # end
120
+
121
+ # assert_equal new, obj
122
+ # end
123
+
124
+ #end
125
+
126
+ #def test_write_stream_repo
127
+ # TmpFile.with_file do |tmpdir|
128
+ # tmpdir = Rbbt.tmp.repo_dir.find
129
+ # repo = File.join(tmpdir, 'repo')
130
+
131
+ # file = File.join(repo, 'file')
132
+ # Open.repository_dirs.push(repo)
133
+
134
+ # text = (["text"] * 5) * "\n"
135
+
136
+ # Misc.consume_stream(StringIO.new(text), false, file)
137
+
138
+ # assert_equal text, Open.read(file)
139
+ # assert !File.exist?(file)
140
+ # assert Open.exists? file
141
+ # end
142
+
143
+ #end
144
+
145
+ end
146
+
@@ -0,0 +1,54 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestPath < Test::Unit::TestCase
5
+ def test_join
6
+ path = '/tmp'
7
+ path.extend Path
8
+ assert_equal '/tmp/foo', path.join(:foo)
9
+ assert_equal '/tmp/foo/bar', path.join(:bar, :foo)
10
+ end
11
+
12
+ def test_get
13
+ path = '/tmp'
14
+ path.extend Path
15
+ assert_equal '/tmp/foo', path[:foo]
16
+ assert_equal '/tmp/foo/bar', path.foo[:bar]
17
+ assert_equal '/tmp/foo/bar', path[:bar, :foo]
18
+ end
19
+
20
+ def test_slash
21
+ path = '/tmp'
22
+ path.extend Path
23
+ assert_equal '/tmp/foo', path/:foo
24
+ assert_equal '/tmp/foo/bar', path/:foo/:bar
25
+ assert_equal '/tmp/foo/bar', path.foo/:bar
26
+ assert_equal '/tmp/foo/bar', path./(:bar, :foo)
27
+ end
28
+
29
+ def test_setup
30
+ path = 'tmp'
31
+ Path.setup(path)
32
+ assert_equal 'scout', path.pkgdir
33
+ assert path.libdir.end_with?("scout-essentials")
34
+ end
35
+
36
+ def test_lib_dir
37
+ TmpFile.with_file do |tmpdir|
38
+ Path.setup tmpdir
39
+ FileUtils.mkdir_p tmpdir.lib
40
+ lib_path = File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
41
+ lib_path = File.join(Path.caller_lib_dir, 'lib', lib_path)
42
+ File.write tmpdir.lib.file, <<-EOR
43
+ require '#{lib_path}'
44
+ a = "1"
45
+ Path.setup(a)
46
+ print a.libdir
47
+ EOR
48
+ Misc.in_dir tmpdir.tmp do
49
+ assert_equal tmpdir, `ruby #{tmpdir.lib.file}`
50
+ end
51
+ end
52
+ end
53
+ end
54
+