scout-gear 2.0.0 → 5.1.1

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 (91) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +59 -2
  3. data/VERSION +1 -1
  4. data/bin/scout +231 -24
  5. data/lib/scout/cmd.rb +344 -0
  6. data/lib/scout/concurrent_stream.rb +259 -0
  7. data/lib/scout/exceptions.rb +15 -8
  8. data/lib/scout/indiferent_hash/options.rb +8 -26
  9. data/lib/scout/log/color.rb +2 -2
  10. data/lib/scout/log/fingerprint.rb +11 -1
  11. data/lib/scout/log/progress/report.rb +0 -1
  12. data/lib/scout/log/progress/util.rb +1 -1
  13. data/lib/scout/log/progress.rb +4 -4
  14. data/lib/scout/log.rb +10 -2
  15. data/lib/scout/meta_extension.rb +15 -1
  16. data/lib/scout/misc/digest.rb +56 -0
  17. data/lib/scout/misc/filesystem.rb +26 -0
  18. data/lib/scout/misc/format.rb +1 -2
  19. data/lib/scout/misc/insist.rb +56 -0
  20. data/lib/scout/misc.rb +4 -11
  21. data/lib/scout/open/lock.rb +61 -0
  22. data/lib/scout/open/remote.rb +120 -0
  23. data/lib/scout/open/stream.rb +372 -0
  24. data/lib/scout/open/util.rb +225 -0
  25. data/lib/scout/open.rb +169 -0
  26. data/lib/scout/path/find.rb +67 -21
  27. data/lib/scout/path/tmpfile.rb +8 -0
  28. data/lib/scout/path/util.rb +14 -1
  29. data/lib/scout/path.rb +6 -30
  30. data/lib/scout/persist/open.rb +17 -0
  31. data/lib/scout/persist/path.rb +15 -0
  32. data/lib/scout/persist/serialize.rb +140 -0
  33. data/lib/scout/persist.rb +54 -0
  34. data/lib/scout/resource/path.rb +15 -0
  35. data/lib/scout/resource/produce/rake.rb +69 -0
  36. data/lib/scout/resource/produce.rb +246 -0
  37. data/lib/scout/resource/scout.rb +3 -0
  38. data/lib/scout/resource.rb +37 -0
  39. data/lib/scout/simple_opt/accessor.rb +1 -1
  40. data/lib/scout/simple_opt/doc.rb +4 -22
  41. data/lib/scout/simple_opt/parse.rb +4 -3
  42. data/lib/scout/tmpfile.rb +39 -1
  43. data/lib/scout/workflow/definition.rb +72 -0
  44. data/lib/scout/workflow/documentation.rb +77 -0
  45. data/lib/scout/workflow/step/info.rb +77 -0
  46. data/lib/scout/workflow/step.rb +96 -0
  47. data/lib/scout/workflow/task/inputs.rb +112 -0
  48. data/lib/scout/workflow/task.rb +141 -0
  49. data/lib/scout/workflow/usage.rb +294 -0
  50. data/lib/scout/workflow/util.rb +11 -0
  51. data/lib/scout/workflow.rb +39 -0
  52. data/lib/scout-gear.rb +4 -0
  53. data/lib/scout.rb +1 -0
  54. data/lib/workflow-scout.rb +2 -0
  55. data/scout-gear.gemspec +66 -5
  56. data/scout_commands/alias +48 -0
  57. data/scout_commands/find +83 -0
  58. data/scout_commands/glob +0 -0
  59. data/scout_commands/rbbt +23 -0
  60. data/scout_commands/workflow/task +707 -0
  61. data/test/scout/indiferent_hash/test_options.rb +11 -1
  62. data/test/scout/misc/test_digest.rb +30 -0
  63. data/test/scout/misc/test_filesystem.rb +30 -0
  64. data/test/scout/misc/test_insist.rb +13 -0
  65. data/test/scout/open/test_lock.rb +52 -0
  66. data/test/scout/open/test_remote.rb +25 -0
  67. data/test/scout/open/test_stream.rb +515 -0
  68. data/test/scout/open/test_util.rb +73 -0
  69. data/test/scout/path/test_find.rb +28 -0
  70. data/test/scout/persist/test_open.rb +37 -0
  71. data/test/scout/persist/test_path.rb +37 -0
  72. data/test/scout/persist/test_serialize.rb +114 -0
  73. data/test/scout/resource/test_path.rb +40 -0
  74. data/test/scout/resource/test_produce.rb +62 -0
  75. data/test/scout/test_cmd.rb +85 -0
  76. data/test/scout/test_concurrent_stream.rb +29 -0
  77. data/test/scout/test_misc.rb +0 -7
  78. data/test/scout/test_open.rb +146 -0
  79. data/test/scout/test_path.rb +3 -1
  80. data/test/scout/test_persist.rb +83 -0
  81. data/test/scout/test_resource.rb +26 -0
  82. data/test/scout/test_workflow.rb +87 -0
  83. data/test/scout/workflow/step/test_info.rb +28 -0
  84. data/test/scout/workflow/task/test_inputs.rb +182 -0
  85. data/test/scout/workflow/test_step.rb +36 -0
  86. data/test/scout/workflow/test_task.rb +178 -0
  87. data/test/scout/workflow/test_usage.rb +26 -0
  88. data/test/scout/workflow/test_util.rb +17 -0
  89. data/test/test_helper.rb +17 -0
  90. data/test/test_scout-gear.rb +0 -0
  91. metadata +64 -3
@@ -0,0 +1,73 @@
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 TestOpenUtil < Test::Unit::TestCase
7
+ def test_read_grep
8
+ content =<<-EOF
9
+ 1
10
+ 2
11
+ 3
12
+ 4
13
+ EOF
14
+ TmpFile.with_file(content) do |file|
15
+ sum = 0
16
+ Open.read(file, :grep => '^1\|3') do |line| sum += line.to_i end
17
+ assert_equal(1 + 3, sum)
18
+ end
19
+
20
+ TmpFile.with_file(content) do |file|
21
+ sum = 0
22
+ Open.read(file, :grep => ["1","3"]) do |line| sum += line.to_i end
23
+ assert_equal(1 + 3, sum)
24
+ end
25
+ end
26
+
27
+ def test_read_grep_invert
28
+ content =<<-EOF
29
+ 1
30
+ 2
31
+ 3
32
+ 4
33
+ EOF
34
+ TmpFile.with_file(content) do |file|
35
+ sum = 0
36
+ Open.read(file, :grep => '^1\|3', :invert_grep => true) do |line| sum += line.to_i end
37
+ assert_equal(2 + 4, sum)
38
+ end
39
+
40
+ TmpFile.with_file(content) do |file|
41
+ sum = 0
42
+ Open.read(file, :grep => ["1","3"]) do |line| sum += line.to_i end
43
+ assert_equal(1 + 3, sum)
44
+ end
45
+ end
46
+
47
+ def test_ln_s
48
+ TmpFile.with_file do |directory|
49
+ Path.setup(directory)
50
+ file1 = directory.subdir1.file
51
+ file2 = directory.subdir2.file
52
+ Open.write(file1, "TEST")
53
+ Open.ln_s file1, file2
54
+ assert_equal "TEST", Open.read(file2)
55
+ Open.write(file1, "TEST2")
56
+ assert_equal "TEST2", Open.read(file2)
57
+ end
58
+ end
59
+
60
+ def test_ln_h
61
+ TmpFile.with_file do |directory|
62
+ Path.setup(directory)
63
+ file1 = directory.subdir1.file
64
+ file2 = directory.subdir2.file
65
+ Open.write(file1, "TEST")
66
+ Open.ln_s file1, file2
67
+ assert_equal "TEST", Open.read(file2)
68
+ Open.write(file1, "TEST2")
69
+ assert_equal "TEST2", Open.read(file2)
70
+ end
71
+ end
72
+ end
73
+
@@ -71,5 +71,33 @@ class TestPathFind < Test::Unit::TestCase
71
71
 
72
72
  end
73
73
 
74
+ def test_custom
75
+ path = Path.setup("share/data/some_file", 'scout')
76
+ TmpFile.with_file do |tmpdir|
77
+ path.path_maps[:custom] = [tmpdir, '{PATH}'] * "/"
78
+ assert_equal File.join(tmpdir,"share/data/some_file"), path.find(:custom)
79
+
80
+ path.path_maps[:custom] = [tmpdir, '{TOPLEVEL}/{PKGDIR}/{SUBPATH}'] * "/"
81
+ assert_equal File.join(tmpdir,"share/scout/data/some_file"), path.find(:custom)
82
+ end
83
+ end
84
+
85
+ def test_pkgdir
86
+ path = Path.setup("share/data/some_file", 'scout')
87
+ TmpFile.with_file do |tmpdir|
88
+ path.pkgdir = 'scout_alt'
89
+ path.path_maps[:custom] = [tmpdir, '{TOPLEVEL}/{PKGDIR}/{SUBPATH}'] * "/"
90
+ assert_equal File.join(tmpdir,"share/scout_alt/data/some_file"), path.find(:custom)
91
+ end
92
+ end
93
+
94
+ def test_sub
95
+ path = Path.setup("bin/scout/find")
96
+
97
+ assert_equal "/some_dir/bin/scout_commands/find", Path.follow(path, "/some_dir/{PATH/scout/scout_commands}")
98
+ assert_equal "/some_dir/scout_commands/find", Path.follow(path, '/some_dir/{PATH/bin\/scout/scout_commands}')
99
+ end
100
+
101
+
74
102
  end
75
103
 
@@ -0,0 +1,37 @@
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 TestPersistOpen < Test::Unit::TestCase
5
+
6
+ def obj
7
+ ["TEST", 2, :symbol, {"a" => [1,2], :b => 3}]
8
+ end
9
+
10
+ def test_json
11
+ obj = ["TEST", 2]
12
+ TmpFile.with_file(obj.to_json) do |tmpfile|
13
+ assert_equal obj, Open.json(tmpfile)
14
+ end
15
+ end
16
+
17
+ def test_yaml
18
+ TmpFile.with_file(obj.to_yaml) do |tmpfile|
19
+ assert_equal obj, Open.yaml(tmpfile)
20
+ end
21
+ end
22
+
23
+ def test_marshal
24
+ TmpFile.with_file(Marshal.dump(obj)) do |tmpfile|
25
+ assert_equal obj, Open.marshal(tmpfile)
26
+ end
27
+ end
28
+
29
+ def test_yaml_io
30
+ TmpFile.with_file(obj.to_yaml) do |tmpfile|
31
+ Open.open(tmpfile) do |f|
32
+ assert_equal obj, Open.yaml(f)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,37 @@
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 TestPersistPath < Test::Unit::TestCase
5
+ def obj
6
+ ["TEST", 2, :symbol, {"a" => [1,2], :b => 3}]
7
+ end
8
+
9
+ def test_json
10
+ obj = ["TEST", 2]
11
+ TmpFile.with_file(obj.to_json) do |tmpfile|
12
+ Path.setup(tmpfile)
13
+ assert_equal obj, tmpfile.json
14
+ end
15
+ end
16
+
17
+ def test_yaml
18
+ TmpFile.with_file(obj.to_yaml) do |tmpfile|
19
+ assert_equal obj, Open.yaml(tmpfile)
20
+ end
21
+ end
22
+
23
+ def test_marshal
24
+ TmpFile.with_file(Marshal.dump(obj)) do |tmpfile|
25
+ assert_equal obj, Open.marshal(tmpfile)
26
+ end
27
+ end
28
+
29
+ def test_yaml_io
30
+ TmpFile.with_file(obj.to_yaml) do |tmpfile|
31
+ Open.open(tmpfile) do |f|
32
+ assert_equal obj, Open.yaml(f)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,114 @@
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 TestPersistSerialize < Test::Unit::TestCase
5
+ def test_string
6
+ TmpFile.with_file do |tmpfile|
7
+ obj = "TEST"
8
+ Persist.save(obj, tmpfile, :string)
9
+ assert_equal obj, Persist.load(tmpfile, :string)
10
+ end
11
+ end
12
+
13
+ def test_string_io
14
+ TmpFile.with_file do |tmpfile|
15
+ obj = StringIO.new("TEST")
16
+ obj.rewind
17
+ Persist.save("TEST", tmpfile, :string)
18
+ assert_equal "TEST", Persist.load(tmpfile, :string)
19
+ end
20
+ end
21
+
22
+ def test_integer
23
+ TmpFile.with_file do |tmpfile|
24
+ obj = 1
25
+ Persist.save(obj, tmpfile, :integer)
26
+ assert_equal obj, Persist.load(tmpfile, :integer)
27
+ end
28
+ end
29
+
30
+ def test_float
31
+ TmpFile.with_file do |tmpfile|
32
+ obj = 1.210202
33
+ Persist.save(obj, tmpfile, :float)
34
+ assert_equal obj, Persist.load(tmpfile, :float)
35
+ end
36
+ end
37
+
38
+ def test_array
39
+ TmpFile.with_file do |tmpfile|
40
+ obj = %w(one two)
41
+ Persist.save(obj, tmpfile, :array)
42
+ assert_equal obj, Persist.load(tmpfile, :array)
43
+ end
44
+ end
45
+
46
+ def test_integer_array
47
+ TmpFile.with_file do |tmpfile|
48
+ obj = [1, 2]
49
+ Persist.save(obj, tmpfile, :integer_array)
50
+ assert_equal obj, Persist.load(tmpfile, :integer_array)
51
+ end
52
+ end
53
+
54
+ def test_float_array
55
+ TmpFile.with_file do |tmpfile|
56
+ obj = [1.1, 2.2]
57
+ Persist.save(obj, tmpfile, :float_array)
58
+ assert_equal obj, Persist.load(tmpfile, :float_array)
59
+ end
60
+ end
61
+
62
+ def test_boolean_array
63
+ TmpFile.with_file do |tmpfile|
64
+ obj = [true, false, true]
65
+ Persist.save(obj, tmpfile, :boolean_array)
66
+ assert_equal obj, Persist.load(tmpfile, :boolean_array)
67
+ end
68
+ end
69
+
70
+ def test_path_array
71
+ TmpFile.with_file do |tmpfile|
72
+ dir = Path.setup("test/dir")
73
+ obj = [dir.foo, dir.bar]
74
+ Persist.save(obj, tmpfile, :path_array)
75
+ assert_equal obj, Persist.load(tmpfile, :path_array)
76
+ assert_equal dir.foo.find, obj.first.find
77
+ end
78
+ end
79
+
80
+ def test_path_array_hash
81
+ TmpFile.with_file do |tmpfile|
82
+ dir = Path.setup("test/dir")
83
+ obj = [dir.foo, dir.bar]
84
+ hash = {}
85
+ Persist.save(obj, tmpfile, hash)
86
+ assert_equal obj, Persist.load(tmpfile, hash)
87
+ assert_equal dir.foo.find, obj.first.find
88
+ end
89
+ end
90
+
91
+ def test_relative_path
92
+ TmpFile.with_file do |dir|
93
+ Path.setup(dir)
94
+ file = dir.subdir.file
95
+ Open.write(file, "TEST")
96
+ Persist.save('./subdir/file', dir.file, :file)
97
+ assert_equal 'TEST', Open.read(Persist.load(dir.file, :file))
98
+ end
99
+ end
100
+
101
+ def test_relative_file_array
102
+ TmpFile.with_file do |dir|
103
+ Path.setup(dir)
104
+ file1 = dir.subdir1.file
105
+ Open.write(file1, "TEST1")
106
+ file2 = dir.subdir2.file
107
+ Open.write(file2, "TEST2")
108
+ Persist.save(["./subdir1/file", "./subdir2/file"], dir.file, :file_array)
109
+ assert_equal 'TEST1', Open.read(Persist.load(dir.file, :file_array)[0])
110
+ assert_equal 'TEST2', Open.read(Persist.load(dir.file, :file_array)[1])
111
+ end
112
+ end
113
+ end
114
+
@@ -0,0 +1,40 @@
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
+ require 'scout/resource'
4
+
5
+ class TestResourcePath < Test::Unit::TestCase
6
+ module TestResource
7
+ extend Resource
8
+
9
+ self.subdir = Path.setup('tmp/test-resource_alt')
10
+
11
+ claim self.tmp.test.string, :string, "TEST"
12
+ end
13
+
14
+ def teardown
15
+ FileUtils.rm_rf TestResource.root.find
16
+ end
17
+
18
+ def test_read
19
+ assert_include TestResource.tmp.test.string.read, "TEST"
20
+ end
21
+
22
+ def test_open
23
+ str = ""
24
+ TestResource.tmp.test.string.open do |f|
25
+ str = f.read
26
+ end
27
+ assert_include str, "TEST"
28
+ end
29
+
30
+ def test_write
31
+ TmpFile.with_file do |tmpfile|
32
+ Path.setup(tmpfile)
33
+ tmpfile.foo.bar.write do |f|
34
+ f.puts "TEST"
35
+ end
36
+ assert_include tmpfile.foo.bar.read, "TEST"
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,62 @@
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
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'../resource')
4
+
5
+ class TestResourceUnit < Test::Unit::TestCase
6
+ module TestResource
7
+ extend Resource
8
+
9
+ self.subdir = Path.setup('tmp/test-resource')
10
+
11
+ claim self.tmp.test.google, :url, "http://google.com"
12
+ claim self.tmp.test.string, :string, "TEST"
13
+ claim self.tmp.test.proc, :proc do
14
+ "PROC TEST"
15
+ end
16
+
17
+ claim self.tmp.test.rakefiles.Rakefile , :string , <<-EOF
18
+ file('foo') do |t|
19
+ Open.write(t.name, "FOO")
20
+ end
21
+
22
+ rule(/.*/) do |t|
23
+ Open.write(t.name, "OTHER")
24
+ end
25
+ EOF
26
+
27
+ claim self.tmp.test.work.footest, :rake, TestResource.tmp.test.rakefiles.Rakefile
28
+
29
+ claim self.tmp.test.work.file_proc, :file_proc do |file,filename|
30
+ Open.write(filename, file)
31
+ nil
32
+ end
33
+ end
34
+
35
+ def teardown
36
+ FileUtils.rm_rf TestResource.root.find
37
+ end
38
+
39
+ def test_proc
40
+ TestResource.produce TestResource.tmp.test.proc
41
+ assert_include File.open(TestResource.tmp.test.proc.find).read, "PROC TEST"
42
+ end
43
+
44
+ def test_string
45
+ TestResource.produce TestResource.tmp.test.string
46
+ assert_include File.open(TestResource.tmp.test.string.find).read, "TEST"
47
+ end
48
+
49
+ def test_url
50
+ TestResource.produce TestResource.tmp.test.google
51
+ assert_include File.open(TestResource.tmp.test.google.find).read, "html"
52
+ end
53
+
54
+ def test_rake
55
+ TestResource.produce TestResource.tmp.test.work.footest.foo
56
+ TestResource.produce TestResource.tmp.test.work.footest.bar
57
+ TestResource.produce TestResource.tmp.test.work.footest.foo_bar
58
+ assert_include File.open(TestResource.tmp.test.work.footest.foo.find).read, "FOO"
59
+ assert_include File.open(TestResource.tmp.test.work.footest.bar.find).read, "OTHER"
60
+ assert_include File.open(TestResource.tmp.test.work.footest.foo_bar.find).read, "OTHER"
61
+ end
62
+ end
@@ -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
+
@@ -2,12 +2,5 @@ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
2
  require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
3
 
4
4
  class TestMisc < Test::Unit::TestCase
5
- def test_in_dir
6
- TmpFile.with_file do |tmpdir|
7
- Misc.in_dir tmpdir do
8
- assert_equal tmpdir, FileUtils.pwd
9
- end
10
- end
11
- end
12
5
  end
13
6
 
@@ -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
+
@@ -37,8 +37,10 @@ class TestPath < Test::Unit::TestCase
37
37
  TmpFile.with_file do |tmpdir|
38
38
  Path.setup tmpdir
39
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)
40
42
  File.write tmpdir.lib.file, <<-EOR
41
- require '#{File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')}'
43
+ require '#{lib_path}'
42
44
  a = "1"
43
45
  Path.setup(a)
44
46
  print a.libdir