rant 0.4.4 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/NEWS +38 -0
  2. data/README +4 -2
  3. data/Rantfile +50 -12
  4. data/doc/examples/c_cpp/c++/problem_1_1/another_test.cpp +6 -0
  5. data/doc/examples/c_cpp/c++/problem_1_1/another_test.h +5 -0
  6. data/doc/examples/c_cpp/c++/problem_1_1/main.cpp +12 -0
  7. data/doc/examples/c_cpp/c++/problem_1_1/test.cpp +6 -0
  8. data/doc/examples/c_cpp/c++/problem_1_1/test.h +5 -0
  9. data/doc/examples/c_cpp/c++/template.rf +15 -0
  10. data/doc/examples/c_cpp/c/problem_1_1/another_test.c +6 -0
  11. data/doc/examples/c_cpp/c/problem_1_1/another_test.h +7 -0
  12. data/doc/examples/c_cpp/c/problem_1_1/main.c +12 -0
  13. data/doc/examples/c_cpp/c/problem_1_1/test.c +6 -0
  14. data/doc/examples/c_cpp/c/problem_1_1/test.h +7 -0
  15. data/doc/examples/c_cpp/c/template.rf +15 -0
  16. data/doc/examples/c_cpp/root.rant +46 -0
  17. data/doc/homepage/index.html +115 -0
  18. data/doc/homepage/rant_home.css +98 -0
  19. data/doc/rant.1 +129 -0
  20. data/doc/rant.rdoc +5 -6
  21. data/doc/rantfile.rdoc +55 -32
  22. data/doc/subdirs.rdoc +147 -0
  23. data/lib/rant.rb +47 -49
  24. data/lib/rant/coregen.rb +20 -20
  25. data/lib/rant/import.rb +63 -11
  26. data/lib/rant/import/archive.rb +47 -15
  27. data/lib/rant/import/archive/tgz.rb +1 -1
  28. data/lib/rant/import/autoclean.rb +28 -26
  29. data/lib/rant/import/c/dependencies.rb +1 -1
  30. data/lib/rant/import/directedrule.rb +1 -4
  31. data/lib/rant/import/metadata.rb +30 -7
  32. data/lib/rant/import/nodes/default.rb +67 -13
  33. data/lib/rant/import/rubypackage.rb +1 -1
  34. data/lib/rant/import/rubytest.rb +25 -19
  35. data/lib/rant/import/signedfile.rb +14 -8
  36. data/lib/rant/import/sys/more.rb +22 -0
  37. data/lib/rant/import/sys/tgz.rb +43 -0
  38. data/lib/rant/import/sys/zip.rb +42 -0
  39. data/lib/rant/node.rb +19 -13
  40. data/lib/rant/plugin/configure.rb +1 -1
  41. data/lib/rant/progress.rb +33 -0
  42. data/lib/rant/rantenv.rb +7 -7
  43. data/lib/rant/rantlib.rb +246 -256
  44. data/lib/rant/rantsys.rb +61 -22
  45. data/lib/rant/rantvar.rb +7 -9
  46. data/misc/TODO +18 -0
  47. data/misc/devel-notes +4 -1
  48. data/test/Rantfile +17 -3
  49. data/test/deprecated/README +6 -0
  50. data/test/deprecated/test_0_4_8.rb +41 -0
  51. data/test/deprecated/test_0_5_2.rb +33 -0
  52. data/test/import/md5/root.rant +9 -0
  53. data/test/import/md5/test_md5.rb +45 -0
  54. data/test/import/metadata/Rantfile +2 -2
  55. data/test/import/metadata/test_metadata.rb +2 -2
  56. data/test/import/package/test_package.rb +40 -1
  57. data/test/import/signedfile/sub1/Rantfile +1 -1
  58. data/test/import/sys/data/pkg.tgz +0 -0
  59. data/test/import/sys/data/pkg.zip +0 -0
  60. data/test/import/sys/data/pkg/bin/test +0 -0
  61. data/test/import/sys/data/pkg/bin/test.o +0 -0
  62. data/test/import/sys/data/pkg/test.c +6 -0
  63. data/test/import/sys/data/pkg/test.h +7 -0
  64. data/test/import/sys/data/pkg2.zip +0 -0
  65. data/test/import/sys/test_tgz.rb +38 -0
  66. data/test/import/sys/test_zip.rb +68 -0
  67. data/test/import/sys/tgz.rf +6 -0
  68. data/test/import/sys/zip.rf +15 -0
  69. data/test/project2/{rantfile.rb → root.rant} +0 -0
  70. data/test/project2/test_project.rb +3 -8
  71. data/test/project_rb1/{rantfile.rb → rantfile} +1 -1
  72. data/test/project_rb1/test_project_rb1.rb +3 -5
  73. data/test/rant-import/test_rant-import.rb +22 -10
  74. data/test/subdirs/sub1/Rantfile +1 -1
  75. data/test/subdirs/sub2/{rantfile.rb → rantfile} +0 -0
  76. data/test/subdirs/sub2/sub/rantfile +1 -1
  77. data/test/subdirs2/root.rant +36 -0
  78. data/test/subdirs2/sub00/sub.rant +8 -0
  79. data/test/subdirs2/sub1/sub.rant +13 -0
  80. data/test/subdirs2/test_subdirs2.rb +239 -0
  81. data/test/test_examples.rb +91 -0
  82. data/test/test_filetask.rb +51 -11
  83. data/test/test_rant_interface.rb +24 -0
  84. data/test/test_rantfile_api.rb +54 -2
  85. data/test/test_sourcenode.rb +30 -0
  86. data/test/test_sys.rb +143 -15
  87. data/test/test_task.rb +16 -22
  88. data/test/tutil.rb +22 -38
  89. metadata +67 -9
@@ -63,4 +63,28 @@ class TestRantInterface < Test::Unit::TestCase
63
63
  assert(op.split("\n").size > 15,
64
64
  "rant --help should print at least 16 lines to STDOUT")
65
65
  end
66
+ def test_opt_version
67
+ out, err = assert_rant("--version")
68
+ assert err.empty?
69
+ lines = out.split(/\n/)
70
+ assert_equal 1, lines.size
71
+ assert_match(/^rant \d\.\d\.\d$/i, lines.first)
72
+ out2, err2 = assert_rant("-V")
73
+ assert_equal err, err2
74
+ assert_equal out, out2
75
+ end
76
+ def test_no_such_option
77
+ out, err = assert_rant :fail, "-n"
78
+ assert out.empty?
79
+ lines = err.split(/\n/)
80
+ assert lines.size < 3
81
+ assert_match(/\[ERROR\].*option.*\bn\b/, lines.first)
82
+ end
83
+ def test_no_such_long_option
84
+ out, err = assert_rant :fail, "--nix"
85
+ assert out.empty?
86
+ lines = err.split(/\n/)
87
+ assert lines.size < 3
88
+ assert_match(/\[ERROR\].*option.*\bnix\b/, lines.first)
89
+ end
66
90
  end
@@ -1,12 +1,12 @@
1
1
 
2
2
  require 'test/unit'
3
- require 'rant/rantlib'
4
3
  require 'tutil'
5
- require 'fileutils'
6
4
 
7
5
  $testDir ||= File.expand_path(File.dirname(__FILE__))
8
6
 
9
7
  class TestRantfileAPI < Test::Unit::TestCase
8
+ include Rant::TestUtil
9
+
10
10
  def setup
11
11
  # Ensure we run in test directory.
12
12
  Dir.chdir $testDir
@@ -139,4 +139,56 @@ class TestRantfileAPI < Test::Unit::TestCase
139
139
  assert_equal("test\n", out)
140
140
  assert(err.empty?)
141
141
  end
142
+ def test_task_no_arguments
143
+ in_local_temp_dir do
144
+ write_to_file "Rantfile", <<-EOF
145
+ task
146
+ task :default do
147
+ puts "hello"
148
+ end
149
+ EOF
150
+ out, err = assert_rant :fail
151
+ assert out.empty?
152
+ lines = err.split(/\n/)
153
+ assert lines.size < 4
154
+ assert_match(/\[ERROR\].*Rantfile\b.*\b1\b/, lines[0])
155
+ assert_match(/argument/, lines[1])
156
+ end
157
+ end
158
+ def test_file_too_many_hash_elements
159
+ in_local_temp_dir do
160
+ write_to_file "root.rant", <<-EOF
161
+
162
+ file :a => :b, :c => :d do |t|
163
+ sys.touch t.name
164
+ end
165
+ EOF
166
+ out, err = assert_rant :fail
167
+ assert out.empty?
168
+ assert !test(?e, "a")
169
+ assert !test(?e, "c")
170
+ lines = err.split(/\n/)
171
+ assert lines.size < 4
172
+ assert_match(/\[ERROR\].*root\.rant\b.*\b2\b/, lines[0])
173
+ assert_match(/\btoo many\b.*\bone\b/i, lines[1])
174
+ end
175
+ end
176
+ def test_task_string_or_symbol_required
177
+ in_local_temp_dir do
178
+ write_to_file "root.rant", <<-EOF
179
+ task Object.new
180
+ EOF
181
+ out, err = assert_rant :fail
182
+ assert out.empty?
183
+ lines = err.split(/\n/)
184
+ assert lines.size < 4
185
+ assert_match(/\[ERROR\].*root\.rant\b.*\b1\b/, lines[0])
186
+ assert_match(/string or symbol/i, lines[1])
187
+ end
188
+ end
189
+ def test_make_plain_task
190
+ out, err = assert_rant "call-make"
191
+ assert err.empty?
192
+ assert_equal "print_name.t\ncall-make\n", out
193
+ end
142
194
  end
@@ -160,4 +160,34 @@ class TestSourceNode < Test::Unit::TestCase
160
160
  assert_equal(th, th.join(0.5))
161
161
  end
162
162
  end
163
+ def test_file_pre
164
+ @rf = <<-EOF
165
+ import "autoclean"
166
+ file "f.t" => "a.t" do |t|
167
+ sys.touch t.name
168
+ end
169
+ gen SourceNode, "a.t" => ["b.t", "c.t"]
170
+ file "b.t" do |t|
171
+ sys.touch t.name
172
+ end
173
+ gen AutoClean
174
+ EOF
175
+ FileUtils.touch "c.t"
176
+ FileUtils.touch "a.t"
177
+ tmp_rf do
178
+ out, err = assert_rant("-frf.t")
179
+ assert(err.empty?)
180
+ assert(!out.empty?)
181
+ assert(test(?f, "f.t"))
182
+ assert(test(?f, "b.t"))
183
+ out, err = assert_rant("-frf.t")
184
+ assert(err.empty?)
185
+ assert(out.empty?)
186
+ assert_rant("-frf.t", "autoclean")
187
+ assert(!test(?f, "f.t"))
188
+ assert(!test(?f, "b.t"))
189
+ assert(test(?f, "a.t"))
190
+ assert(test(?f, "c.t"))
191
+ end
192
+ end
163
193
  end
data/test/test_sys.rb CHANGED
@@ -1,46 +1,145 @@
1
1
 
2
2
  require 'test/unit'
3
- require 'rant/rantlib'
4
3
  require 'tutil'
5
4
 
6
5
  $testDir ||= File.expand_path(File.dirname(__FILE__))
7
6
 
8
7
  class TestSys < Test::Unit::TestCase
9
8
  include Rant::Sys
9
+ include Rant::TestUtil
10
10
 
11
11
  def setup
12
12
  # Ensure we run in test directory.
13
- Dir.chdir($testDir) unless Dir.pwd == $testDir
13
+ Dir.chdir($testDir)
14
14
  end
15
- def teardown
16
- end
17
-
18
15
  def test_ruby
16
+ cx = Rant::RantApp.new.cx
17
+ block_executed = false
19
18
  op = capture_stdout do
20
- ruby('-e ""') { |succ, stat|
21
- assert(succ)
22
- assert_equal(stat, 0)
19
+ cx.sys.ruby('-e ""') { |stat|
20
+ block_executed = true
21
+ assert_equal(0, stat)
23
22
  }
24
23
  end
24
+ assert(block_executed)
25
25
  assert(op =~ /\-e/i,
26
- "Sys should print command with arguments to $stdout")
26
+ "sys should print command with arguments to $stdout")
27
+ end
28
+ def test_ruby_no_block
29
+ assert(!test(?e, "a.t"))
30
+ out, err = capture_std do
31
+ assert_nothing_raised { ruby '-e', 'open "a.t", "w" do end' }
32
+ end
33
+ assert(test(?f, "a.t"))
34
+ ensure
35
+ FileUtils.rm_f "a.t"
36
+ end
37
+ def test_ruby_exit_code
38
+ cx = Rant::RantApp.new.cx
39
+ block_executed = false
40
+ out, err = capture_std do
41
+ cx.sys.ruby('-e', 'exit 2') { |stat|
42
+ block_executed = true
43
+ assert_equal(2, stat.exitstatus)
44
+ }
45
+ end
46
+ assert(block_executed)
47
+ assert(err.empty?)
48
+ assert_match(/. -e exit 2\n\z/m, out)
27
49
  end
28
- def test_split_path
29
- pl = split_path("/home/stefan")
50
+ def test_ruby_fail
51
+ out, err = capture_std do
52
+ assert_raises(Rant::CommandError) { ruby '-e exit 1' }
53
+ end
54
+ end
55
+ def test_split_all
56
+ pl = split_all("/home/stefan")
30
57
  assert_equal(pl.size, 3,
31
58
  "/home/stefan should get split into 3 parts")
32
59
  assert_equal(pl[0], "/")
33
60
  assert_equal(pl[1], "home")
34
61
  assert_equal(pl[2], "stefan")
35
- pl = split_path("../")
62
+ pl = split_all("../")
36
63
  assert_equal(pl.size, 1,
37
64
  '../ should be "split" into one element')
38
65
  assert_equal(pl[0], "..")
39
66
  end
67
+ def test_expand_path
68
+ in_local_temp_dir do
69
+ rootdir = Dir.pwd
70
+ write_to_file "root.rant", <<-EOF
71
+ task :a do
72
+ puts sys.expand_path("@")
73
+ end
74
+ subdirs "sub"
75
+ EOF
76
+ in_local_temp_dir "sub" do
77
+ write_to_file "sub.rant", <<-'EOF'
78
+ task :a do
79
+ puts sys.expand_path("@")
80
+ end
81
+ task :b do
82
+ puts sys.expand_path("@/abc")
83
+ end
84
+ task :c do
85
+ puts sys.expand_path("@abc")
86
+ end
87
+ task :d do
88
+ puts sys.expand_path("../abc")
89
+ end
90
+ task :e do
91
+ puts sys.expand_path(nil)
92
+ end
93
+ task :f do
94
+ puts sys.expand_path("@/../abc")
95
+ end
96
+ task :g do
97
+ puts sys.expand_path("a@b")
98
+ end
99
+ task :h do
100
+ puts sys.expand_path("@a@b")
101
+ end
102
+ task :i do
103
+ puts sys.expand_path('\@a@b')
104
+ end
105
+ task :j do
106
+ puts sys.expand_path(nil)
107
+ end
108
+ EOF
109
+ Dir.chdir ".."
110
+ out, err = assert_rant "a"
111
+ assert_equal rootdir, out.chomp
112
+ out, err = assert_rant "sub/a"
113
+ assert_equal rootdir, out.split(/\n/).last
114
+ Dir.chdir "sub"
115
+ out, err = assert_rant "a"
116
+ assert_equal rootdir, out.split(/\n/).last
117
+ out, err = assert_rant "b"
118
+ assert_equal "#{rootdir}/abc", out.split(/\n/).last
119
+ out, err = assert_rant "c"
120
+ assert_equal "#{rootdir}/abc", out.split(/\n/).last
121
+ out, err = assert_rant "d"
122
+ assert_equal "#{rootdir}/abc", out.split(/\n/).last
123
+ out, err = assert_rant "e"
124
+ assert_equal "#{rootdir}/sub", out.split(/\n/).last
125
+ out, err = assert_rant "f"
126
+ assert_equal "#{File.dirname(rootdir)}/abc", out.split(/\n/).last
127
+ out, err = assert_rant "g"
128
+ assert_equal "#{rootdir}/sub/a@b", out.split(/\n/).last
129
+ out, err = assert_rant "h"
130
+ assert_equal "#{rootdir}/a@b", out.split(/\n/).last
131
+ out, err = assert_rant "i"
132
+ assert_equal "#{rootdir}/sub/@a@b", out.split(/\n/).last
133
+ out, err = assert_rant "e"
134
+ assert_equal "#{rootdir}/sub", out.split(/\n/).last
135
+ end
136
+ end
137
+ end
40
138
  # perhaps this test should go into a seperate file
41
139
  def test_toplevel
42
- assert_match(/\btd\b/, run_rant("-ftoplevel.rf"),
43
- "Sys module should print commands to stdout")
140
+ out = run_rant("-ftoplevel.rf")
141
+ #assert_match(/\btd\b/, out,
142
+ # "Sys module should print commands to stdout")
44
143
  assert_equal(0, $?,
45
144
  "rant -ftoplevel.rf in test/ should be successfull")
46
145
  ensure
@@ -54,7 +153,10 @@ class TestSys < Test::Unit::TestCase
54
153
  out, err = capture_std do
55
154
  assert_equal(1, Rant.run("-fname_error.rf"))
56
155
  end
57
- assert_match(/Name\s*Error/i, err.split("\n").first)
156
+ lines = err.split(/\n/)
157
+ assert_equal(3, lines.size)
158
+ assert_match(/\bname_error\.rf\b.*\b1\b/, lines[0])
159
+ assert_match(/Name\s*Error/i, lines[1])
58
160
  ensure
59
161
  File.delete "name_error.rf" if File.exist? "name_error.rf"
60
162
  end
@@ -82,4 +184,30 @@ class TestSys < Test::Unit::TestCase
82
184
  ensure
83
185
  FileUtils.rm_rf %w(cp.t a.t b.t)
84
186
  end
187
+ def test_sys_with_block
188
+ open "exit_1.t", "w" do |f|
189
+ f << <<-EOF
190
+ exit 1
191
+ EOF
192
+ end
193
+ open "rf.t", "w" do |f|
194
+ f << <<-EOF
195
+ task :rbexit1_block do
196
+ sys Env::RUBY, "exit_1.t" do |status|
197
+ puts "no success" if status != 0
198
+ puts status.exitstatus
199
+ end
200
+ end
201
+ task :rbexit1 do
202
+ sys.ruby "exit_1.t"
203
+ end
204
+ EOF
205
+ end
206
+ out, err = assert_rant("-frf.t")
207
+ assert(err.empty?)
208
+ assert_equal(["no success", "1"], out.split(/\n/)[1..-1])
209
+ out, err = assert_rant(:fail, "-frf.t", "rbexit1")
210
+ ensure
211
+ FileUtils.rm_f %w(exit_1.t rf.t)
212
+ end
85
213
  end
data/test/test_task.rb CHANGED
@@ -1,42 +1,37 @@
1
1
 
2
2
  require 'test/unit'
3
- require 'rant/rantlib'
3
+ require 'tutil'
4
4
 
5
5
  $-w = true
6
6
 
7
7
  class TestTask < Test::Unit::TestCase
8
8
  def setup
9
+ @rant = Rant::RantApp.new
9
10
  end
10
- def teardown
11
- end
12
-
13
11
  def test_version
14
12
  assert(Rant::VERSION.length >= 5)
15
13
  end
16
-
17
14
  def test_needed
18
15
  run = false
19
- t = Rant::Task.new(nil, :non_existent) { run = true }
16
+ t = Rant::Task.new(@rant, :non_existent) { run = true }
20
17
  assert(t.needed?,
21
18
  "Rant::Task should always be 'needed?' before first invocation")
22
19
  assert(!run,
23
20
  "Rant::Task shouldn't get run when 'needed?' is called")
24
21
  end
25
-
26
22
  def test_invoke
27
23
  run = false
28
24
  block = lambda { run = true }
29
- task = Rant::Task.new(nil, :test_run, &block)
25
+ task = Rant::Task.new(@rant, :test_run, &block)
30
26
  task.invoke
31
27
  assert(run, "block should have been executed")
32
28
  assert(task.done?, "task is done")
33
29
  assert(!task.needed?,
34
30
  "task is done, so 'needed?' should return false")
35
31
  end
36
-
37
32
  def test_fail
38
33
  block = lambda { |t| t.fail "this task abortet itself" }
39
- task = Rant::Task.new(nil, :test_fail, &block)
34
+ task = Rant::Task.new(@rant, :test_fail, &block)
40
35
  assert_raise(Rant::TaskFail,
41
36
  "run should throw Rant::TaskFail if block raises Exception") {
42
37
  task.invoke
@@ -44,11 +39,10 @@ class TestTask < Test::Unit::TestCase
44
39
  assert(task.fail?)
45
40
  assert(task.invoked?, "although task failed, it was invoked")
46
41
  end
47
-
48
42
  def test_dependent
49
43
  r1 = r2 = false
50
- t1 = Rant::Task.new(nil, :t1) { r1 = true }
51
- t2 = Rant::Task.new(nil, :t2) { r2 = true }
44
+ t1 = Rant::Task.new(@rant, :t1) { r1 = true }
45
+ t2 = Rant::Task.new(@rant, :t2) { r2 = true }
52
46
  t1 << t2
53
47
  t1.invoke
54
48
  assert(r1)
@@ -60,8 +54,8 @@ class TestTask < Test::Unit::TestCase
60
54
  end
61
55
 
62
56
  def test_dependency_fails
63
- t1 = Rant::Task.new(nil, :t1) { true }
64
- t2 = Rant::Task.new(nil, :t2) { |t| t.fail }
57
+ t1 = Rant::Task.new(@rant, :t1) { true }
58
+ t2 = Rant::Task.new(@rant, :t2) { |t| t.fail }
65
59
  t1 << t2
66
60
  assert_raise(Rant::TaskFail,
67
61
  "dependency t2 failed, so t1 should fail too") {
@@ -75,7 +69,7 @@ class TestTask < Test::Unit::TestCase
75
69
 
76
70
  def test_task
77
71
  run = false
78
- t = Rant.rac.task :t do |t|
72
+ t = @rant.task :t do |t|
79
73
  run = true
80
74
  end
81
75
  t.invoke
@@ -84,7 +78,7 @@ class TestTask < Test::Unit::TestCase
84
78
 
85
79
  def test_dep_on_self
86
80
  run = false
87
- t = Rant.rac.task :t => "t" do |t|
81
+ t = @rant.task :t => "t" do |t|
88
82
  run = true
89
83
  end
90
84
  th = Thread.new { t.invoke }
@@ -97,11 +91,11 @@ class TestTask < Test::Unit::TestCase
97
91
  def test_circular_dependency
98
92
  t1r = false
99
93
  t2r = false
100
- t1 = Rant.rac.task :t1 => :t2 do |t|
94
+ t1 = @rant.task :t1 => :t2 do |t|
101
95
  assert(t2r)
102
96
  t1r = true
103
97
  end
104
- t2 = Rant.rac.task :t2 => :t1 do |t|
98
+ t2 = @rant.task :t2 => :t1 do |t|
105
99
  t2r = true
106
100
  end
107
101
  out, err = capture_std do
@@ -117,13 +111,13 @@ class TestTask < Test::Unit::TestCase
117
111
  end
118
112
  def test_dep_on_self_in_deplist
119
113
  rl = []
120
- t1 = Rant.rac.task :t1 do |t|
114
+ t1 = @rant.task :t1 do |t|
121
115
  rl << t.name
122
116
  end
123
- t2 = Rant.rac.task :t2 do |t|
117
+ t2 = @rant.task :t2 do |t|
124
118
  rl << t.name
125
119
  end
126
- t3 = Rant.rac.task :t3 => [:t1, :t3, :t2] do |t|
120
+ t3 = @rant.task :t3 => [:t1, :t3, :t2] do |t|
127
121
  rl << t.name
128
122
  end
129
123
  th = Thread.new { t3.invoke }