scout-essentials 1.0.0
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.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.vimproject +78 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/lib/scout/cmd.rb +348 -0
- data/lib/scout/concurrent_stream.rb +284 -0
- data/lib/scout/config.rb +168 -0
- data/lib/scout/exceptions.rb +77 -0
- data/lib/scout/indiferent_hash/case_insensitive.rb +30 -0
- data/lib/scout/indiferent_hash/options.rb +115 -0
- data/lib/scout/indiferent_hash.rb +96 -0
- data/lib/scout/log/color.rb +224 -0
- data/lib/scout/log/color_class.rb +269 -0
- data/lib/scout/log/fingerprint.rb +69 -0
- data/lib/scout/log/progress/report.rb +244 -0
- data/lib/scout/log/progress/util.rb +173 -0
- data/lib/scout/log/progress.rb +106 -0
- data/lib/scout/log/trap.rb +107 -0
- data/lib/scout/log.rb +441 -0
- data/lib/scout/meta_extension.rb +100 -0
- data/lib/scout/misc/digest.rb +63 -0
- data/lib/scout/misc/filesystem.rb +25 -0
- data/lib/scout/misc/format.rb +255 -0
- data/lib/scout/misc/helper.rb +31 -0
- data/lib/scout/misc/insist.rb +56 -0
- data/lib/scout/misc/monitor.rb +66 -0
- data/lib/scout/misc/system.rb +73 -0
- data/lib/scout/misc.rb +10 -0
- data/lib/scout/named_array.rb +138 -0
- data/lib/scout/open/lock/lockfile.rb +587 -0
- data/lib/scout/open/lock.rb +68 -0
- data/lib/scout/open/remote.rb +135 -0
- data/lib/scout/open/stream.rb +491 -0
- data/lib/scout/open/util.rb +244 -0
- data/lib/scout/open.rb +170 -0
- data/lib/scout/path/find.rb +204 -0
- data/lib/scout/path/tmpfile.rb +8 -0
- data/lib/scout/path/util.rb +127 -0
- data/lib/scout/path.rb +51 -0
- data/lib/scout/persist/open.rb +17 -0
- data/lib/scout/persist/path.rb +15 -0
- data/lib/scout/persist/serialize.rb +157 -0
- data/lib/scout/persist.rb +104 -0
- data/lib/scout/resource/open.rb +8 -0
- data/lib/scout/resource/path.rb +80 -0
- data/lib/scout/resource/produce/rake.rb +69 -0
- data/lib/scout/resource/produce.rb +151 -0
- data/lib/scout/resource/scout.rb +3 -0
- data/lib/scout/resource/software.rb +178 -0
- data/lib/scout/resource/util.rb +59 -0
- data/lib/scout/resource.rb +40 -0
- data/lib/scout/simple_opt/accessor.rb +54 -0
- data/lib/scout/simple_opt/doc.rb +126 -0
- data/lib/scout/simple_opt/get.rb +57 -0
- data/lib/scout/simple_opt/parse.rb +67 -0
- data/lib/scout/simple_opt/setup.rb +26 -0
- data/lib/scout/simple_opt.rb +5 -0
- data/lib/scout/tmpfile.rb +129 -0
- data/lib/scout-essentials.rb +10 -0
- data/scout-essentials.gemspec +143 -0
- data/share/color/color_names +507 -0
- data/share/color/diverging_colors.hex +12 -0
- data/share/software/install_helpers +523 -0
- data/test/scout/indiferent_hash/test_case_insensitive.rb +16 -0
- data/test/scout/indiferent_hash/test_options.rb +46 -0
- data/test/scout/log/test_color.rb +0 -0
- data/test/scout/log/test_progress.rb +108 -0
- data/test/scout/misc/test_digest.rb +30 -0
- data/test/scout/misc/test_filesystem.rb +30 -0
- data/test/scout/misc/test_insist.rb +13 -0
- data/test/scout/misc/test_system.rb +21 -0
- data/test/scout/open/test_lock.rb +52 -0
- data/test/scout/open/test_remote.rb +25 -0
- data/test/scout/open/test_stream.rb +676 -0
- data/test/scout/open/test_util.rb +73 -0
- data/test/scout/path/test_find.rb +110 -0
- data/test/scout/path/test_util.rb +22 -0
- data/test/scout/persist/test_open.rb +37 -0
- data/test/scout/persist/test_path.rb +37 -0
- data/test/scout/persist/test_serialize.rb +114 -0
- data/test/scout/resource/test_path.rb +58 -0
- data/test/scout/resource/test_produce.rb +94 -0
- data/test/scout/resource/test_software.rb +24 -0
- data/test/scout/resource/test_util.rb +38 -0
- data/test/scout/simple_opt/test_doc.rb +16 -0
- data/test/scout/simple_opt/test_get.rb +11 -0
- data/test/scout/simple_opt/test_parse.rb +10 -0
- data/test/scout/simple_opt/test_setup.rb +77 -0
- data/test/scout/test_cmd.rb +85 -0
- data/test/scout/test_concurrent_stream.rb +29 -0
- data/test/scout/test_config.rb +66 -0
- data/test/scout/test_indiferent_hash.rb +26 -0
- data/test/scout/test_log.rb +32 -0
- data/test/scout/test_meta_extension.rb +80 -0
- data/test/scout/test_misc.rb +6 -0
- data/test/scout/test_named_array.rb +43 -0
- data/test/scout/test_open.rb +146 -0
- data/test/scout/test_path.rb +54 -0
- data/test/scout/test_persist.rb +186 -0
- data/test/scout/test_resource.rb +26 -0
- data/test/scout/test_tmpfile.rb +53 -0
- data/test/test_helper.rb +50 -0
- metadata +247 -0
@@ -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
|
+
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require 'scout/path'
|
3
|
+
require 'scout/misc'
|
4
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
5
|
+
|
6
|
+
class TestPathFind < Test::Unit::TestCase
|
7
|
+
def test_parts
|
8
|
+
path = Path.setup("share/data/some_file", 'scout')
|
9
|
+
assert_equal "share", path._toplevel
|
10
|
+
assert_equal "data/some_file", path._subpath
|
11
|
+
|
12
|
+
path = Path.setup("data", 'scout')
|
13
|
+
assert_equal "", path._toplevel
|
14
|
+
assert_equal "data", path._subpath
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_find_local
|
18
|
+
map = File.join('/usr/local', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}")
|
19
|
+
path = Path.setup("share/data/some_file", 'scout')
|
20
|
+
target = "/usr/local/share/scout/data/some_file"
|
21
|
+
assert_equal target, Path.follow(path, map)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_find
|
25
|
+
path = Path.setup("share/data/some_file", 'scout')
|
26
|
+
assert_equal "/usr/share/scout/data/some_file", path.find(:usr)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_current
|
30
|
+
path = Path.setup("share/data/some_file", 'scout')
|
31
|
+
TmpFile.in_dir do |tmpdir|
|
32
|
+
assert_equal_path File.join(tmpdir,"share/data/some_file"), path.find(:current)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_current_find
|
37
|
+
path = Path.setup("share/data/some_file", 'scout')
|
38
|
+
TmpFile.in_dir do |tmpdir|
|
39
|
+
FileUtils.mkdir_p(File.dirname(File.join(tmpdir, path)))
|
40
|
+
File.write(File.join(tmpdir, path), 'string')
|
41
|
+
assert_equal_path File.join(tmpdir,"share/data/some_file"), path.find
|
42
|
+
assert_equal :current, path.find.where
|
43
|
+
assert_equal "share/data/some_file", path.find.original
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_current_find_all
|
48
|
+
path = Path.setup("share/data/some_file", 'scout')
|
49
|
+
TmpFile.with_dir do |tmpdir|
|
50
|
+
Path.setup tmpdir
|
51
|
+
|
52
|
+
FileUtils.mkdir_p(tmpdir.lib)
|
53
|
+
FileUtils.mkdir_p(tmpdir.share.data)
|
54
|
+
File.write(tmpdir.share.data.some_file, 'string')
|
55
|
+
|
56
|
+
FileUtils.mkdir_p(tmpdir.subdir.share.data)
|
57
|
+
File.write(tmpdir.subdir.share.data.some_file, 'string')
|
58
|
+
|
59
|
+
path.libdir = tmpdir
|
60
|
+
Misc.in_dir tmpdir.subdir do
|
61
|
+
assert_equal 2, path.find_all.length
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_located?
|
67
|
+
|
68
|
+
p = Path.setup("/tmp/foo/bar")
|
69
|
+
assert p.located?
|
70
|
+
assert_equal_path p, p.find
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_custom
|
74
|
+
path = Path.setup("share/data/some_file", 'scout')
|
75
|
+
TmpFile.with_file do |tmpdir|
|
76
|
+
path.path_maps[:custom] = [tmpdir, '{PATH}'] * "/"
|
77
|
+
assert_equal_path File.join(tmpdir,"share/data/some_file"), path.find(:custom)
|
78
|
+
|
79
|
+
path.path_maps[:custom] = [tmpdir, '{TOPLEVEL}/{PKGDIR}/{SUBPATH}'] * "/"
|
80
|
+
assert_equal_path File.join(tmpdir,"share/scout/data/some_file"), path.find(:custom)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_pkgdir
|
85
|
+
path = Path.setup("share/data/some_file", 'scout')
|
86
|
+
TmpFile.with_file do |tmpdir|
|
87
|
+
path.pkgdir = 'scout_alt'
|
88
|
+
path.path_maps[:custom] = [tmpdir, '{TOPLEVEL}/{PKGDIR}/{SUBPATH}'] * "/"
|
89
|
+
assert_equal_path File.join(tmpdir,"share/scout_alt/data/some_file"), path.find(:custom)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_sub
|
94
|
+
path = Path.setup("bin/scout/find")
|
95
|
+
|
96
|
+
assert_equal "/some_dir/bin/scout_commands/find", Path.follow(path, "/some_dir/{PATH/scout/scout_commands}")
|
97
|
+
assert_equal "/some_dir/scout_commands/find", Path.follow(path, '/some_dir/{PATH/bin\/scout/scout_commands}')
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_gz
|
101
|
+
TmpFile.with_file do |tmpdir|
|
102
|
+
Path.setup(tmpdir)
|
103
|
+
Open.write(tmpdir.somefile + '.gz', "FOO")
|
104
|
+
assert_equal_path tmpdir.somefile + '.gz', tmpdir.somefile.find
|
105
|
+
assert Open.exist?(tmpdir.somefile)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require 'scout/path'
|
3
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
4
|
+
|
5
|
+
class TestPathUtil < Test::Unit::TestCase
|
6
|
+
def test_dirname
|
7
|
+
p = Path.setup("/usr/share/scout/data")
|
8
|
+
|
9
|
+
assert_equal "/usr/share/scout", p.dirname
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_glob
|
13
|
+
TmpFile.in_dir :erase => false do |tmpdir|
|
14
|
+
Path.setup tmpdir
|
15
|
+
File.write(tmpdir.foo, 'foo')
|
16
|
+
File.write(tmpdir.bar, 'bar')
|
17
|
+
assert_equal 2, tmpdir.glob.length
|
18
|
+
assert_equal %w(foo bar).sort, tmpdir.glob.collect{|p| p.basename }.sort
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -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,58 @@
|
|
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/resource'
|
5
|
+
require 'scout/resource/scout'
|
6
|
+
|
7
|
+
class TestResourcePath < Test::Unit::TestCase
|
8
|
+
module TestResource
|
9
|
+
extend Resource
|
10
|
+
|
11
|
+
self.subdir = Path.setup('tmp/test-resource_alt')
|
12
|
+
|
13
|
+
claim self.tmp.test.string, :string, "TEST"
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
FileUtils.rm_rf TestResource.root.find
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_read
|
21
|
+
assert_include TestResource.tmp.test.string.read, "TEST"
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_open
|
25
|
+
str = ""
|
26
|
+
TestResource.tmp.test.string.open do |f|
|
27
|
+
str = f.read
|
28
|
+
end
|
29
|
+
assert_include str, "TEST"
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_write
|
33
|
+
TmpFile.with_file do |tmpfile|
|
34
|
+
Path.setup(tmpfile)
|
35
|
+
tmpfile.foo.bar.write do |f|
|
36
|
+
f.puts "TEST"
|
37
|
+
end
|
38
|
+
assert_include tmpfile.foo.bar.read, "TEST"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_identify
|
43
|
+
p = Scout.data.file.find(:lib)
|
44
|
+
assert p.located?
|
45
|
+
assert_equal "data/file", p.identify
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_with_extension
|
49
|
+
dir = tmpdir.directory[__method__]
|
50
|
+
list = %w(a b)
|
51
|
+
Misc.in_dir(dir) do
|
52
|
+
file = dir.foo
|
53
|
+
Open.write(file.set_extension('list'), list * "\n")
|
54
|
+
assert_equal list, file.list
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,94 @@
|
|
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
|
+
require 'scout/resource/scout'
|
6
|
+
|
7
|
+
class TestResourceUnit < Test::Unit::TestCase
|
8
|
+
module TestResource
|
9
|
+
extend Resource
|
10
|
+
|
11
|
+
self.subdir = Path.setup('tmp/test-resource')
|
12
|
+
|
13
|
+
claim self.tmp.test.google, :url, "http://google.com"
|
14
|
+
claim self.tmp.test.string, :string, "TEST"
|
15
|
+
claim self.tmp.test.proc, :proc do
|
16
|
+
"PROC TEST"
|
17
|
+
end
|
18
|
+
|
19
|
+
claim self.tmp.test.rakefiles.Rakefile , :string , <<-EOF
|
20
|
+
file('foo') do |t|
|
21
|
+
Open.write(t.name, "FOO")
|
22
|
+
end
|
23
|
+
|
24
|
+
rule(/.*/) do |t|
|
25
|
+
Open.write(t.name, "OTHER")
|
26
|
+
end
|
27
|
+
EOF
|
28
|
+
|
29
|
+
claim self.tmp.test.work.footest, :rake, TestResource.tmp.test.rakefiles.Rakefile
|
30
|
+
|
31
|
+
claim self.tmp.test.work.file_proc, :file_proc do |file,filename|
|
32
|
+
Open.write(filename, file)
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def teardown
|
38
|
+
FileUtils.rm_rf TestResource.root.find
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_proc
|
42
|
+
TestResource.produce TestResource.tmp.test.proc
|
43
|
+
assert_include File.open(TestResource.tmp.test.proc.find).read, "PROC TEST"
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_string
|
47
|
+
TestResource.produce TestResource.tmp.test.string
|
48
|
+
assert_include File.open(TestResource.tmp.test.string.find).read, "TEST"
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_url
|
52
|
+
TestResource.produce TestResource.tmp.test.google
|
53
|
+
assert_include File.open(TestResource.tmp.test.google.find).read, "html"
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_rake
|
57
|
+
TestResource.produce TestResource.tmp.test.work.footest.foo
|
58
|
+
TestResource.produce TestResource.tmp.test.work.footest.bar
|
59
|
+
TestResource.produce TestResource.tmp.test.work.footest.foo_bar
|
60
|
+
assert_include File.open(TestResource.tmp.test.work.footest.foo.find).read, "FOO"
|
61
|
+
assert_include File.open(TestResource.tmp.test.work.footest.bar.find).read, "OTHER"
|
62
|
+
assert_include File.open(TestResource.tmp.test.work.footest.foo_bar.find).read, "OTHER"
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_produce_with_extension
|
66
|
+
dir = tmpdir.directory[__method__]
|
67
|
+
dir.pkgdir = Scout
|
68
|
+
list = %w(a b)
|
69
|
+
|
70
|
+
Scout.claim dir["foo.list"], :proc do
|
71
|
+
list
|
72
|
+
end
|
73
|
+
|
74
|
+
Misc.in_dir(dir) do
|
75
|
+
file = dir.foo
|
76
|
+
assert_equal list, file.list
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_produce_compressed
|
81
|
+
dir = tmpdir.directory[__method__]
|
82
|
+
dir.pkgdir = Scout
|
83
|
+
list = %w(a b)
|
84
|
+
|
85
|
+
Scout.claim dir["foo.gz"], :proc do |filename|
|
86
|
+
list
|
87
|
+
end
|
88
|
+
|
89
|
+
Misc.in_dir(dir) do
|
90
|
+
file = dir.foo
|
91
|
+
assert_include file.produce.find, '.gz'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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 TestResourceSoftware < Test::Unit::TestCase
|
5
|
+
module TestResource
|
6
|
+
extend Resource
|
7
|
+
|
8
|
+
self.subdir = Path.setup('tmp/test-resource')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_install
|
12
|
+
Resource.install nil, "scout_install_example", tmpdir.software do
|
13
|
+
<<-EOF
|
14
|
+
echo "#!/bin/bash\necho WORKING" > $OPT_BIN_DIR/scout_install_example
|
15
|
+
chmod +x $OPT_BIN_DIR/scout_install_example
|
16
|
+
EOF
|
17
|
+
end
|
18
|
+
assert_nothing_raised do
|
19
|
+
CMD.cmd(tmpdir.software.opt.bin.scout_install_example).read
|
20
|
+
end
|
21
|
+
assert_equal "WORKING", CMD.cmd('scout_install_example').read.strip
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,38 @@
|
|
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/resource/scout'
|
5
|
+
|
6
|
+
class TestResourceUtil < Test::Unit::TestCase
|
7
|
+
def test_identify
|
8
|
+
path = Path.setup('share/data/somedir/somepath').find
|
9
|
+
assert_equal 'share/data/somedir/somepath', Scout.identify(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_identify_with_subdir
|
13
|
+
m = Module.new
|
14
|
+
m.extend Resource
|
15
|
+
m.subdir = 'test/subdir'
|
16
|
+
path = m.root['share/data/somedir/somepath'].find
|
17
|
+
assert_equal 'share/data/somedir/somepath', m.identify(path)
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def test_relocate
|
22
|
+
TmpFile.with_file do |dir|
|
23
|
+
Path.setup dir
|
24
|
+
|
25
|
+
path_base = Path.setup("basedir").someother.file
|
26
|
+
path_base.path_maps[:subdir1] = File.join(dir, 'subdir1', '{PATH}')
|
27
|
+
path_base.path_maps[:subdir2] = File.join(dir, 'subdir2', '{PATH}')
|
28
|
+
|
29
|
+
path1 = path_base.find(:subdir1)
|
30
|
+
path2 = path_base.find(:subdir2)
|
31
|
+
|
32
|
+
Open.write(path1, "TEST")
|
33
|
+
Open.mv path1, path2
|
34
|
+
assert_equal path2, Resource.relocate(path1)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,16 @@
|
|
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 TestSimpleOptDoc < Test::Unit::TestCase
|
5
|
+
def test_input_format
|
6
|
+
assert_match 'default: :def', SOPT.input_format(:name, :type, :def, :n)
|
7
|
+
end
|
8
|
+
def test_input_doc
|
9
|
+
inputs =<<-EOF.split("\n").collect{|l| l.split(" ") }
|
10
|
+
input1 integer Integer_input 10 i1
|
11
|
+
input2 float Float_input 0.2 i2
|
12
|
+
EOF
|
13
|
+
assert SOPT.input_array_doc(inputs).include?('-i1,--input1')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,11 @@
|
|
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 TestSOPTParse < Test::Unit::TestCase
|
6
|
+
def test_consume
|
7
|
+
SOPT.parse("-f--first* first arg:-f--fun")
|
8
|
+
args = "-f myfile --fun".split(" ")
|
9
|
+
assert_equal "myfile", SOPT.consume(args)[:first]
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require 'scout/path'
|
3
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
4
|
+
|
5
|
+
class TestSOPTParse < Test::Unit::TestCase
|
6
|
+
def test_parse
|
7
|
+
SOPT.parse("-f--first* first arg:-f--fun")
|
8
|
+
assert_equal "fun", SOPT.shortcuts["fu"]
|
9
|
+
end
|
10
|
+
end
|