rant 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/NEWS +12 -0
  2. data/README +3 -3
  3. data/Rantfile +7 -1
  4. data/doc/Untitled-1~ +7 -0
  5. data/doc/command.rdoc +1 -1
  6. data/doc/csharp.rdoc +49 -72
  7. data/doc/csharp.rdoc~ +37 -0
  8. data/doc/csharp_deprecated.rdoc +73 -0
  9. data/doc/homepage/index.html +5 -8
  10. data/doc/homepage/index.html~ +134 -0
  11. data/doc/sys.rdoc +14 -0
  12. data/lib/rant/coregen.rb~ +262 -0
  13. data/lib/rant/csharp/base_compiler_adapter.rb +125 -0
  14. data/lib/rant/csharp/base_compiler_adapter.rb~ +105 -0
  15. data/lib/rant/csharp/compiler_adapter_factory.rb +40 -0
  16. data/lib/rant/csharp/compiler_adapter_factory.rb~ +39 -0
  17. data/lib/rant/csharp/csc_compiler.rb +15 -0
  18. data/lib/rant/csharp/csc_compiler.rb~ +39 -0
  19. data/lib/rant/csharp/gmcs_compiler.rb +9 -0
  20. data/lib/rant/csharp/gmcs_compiler.rb~ +10 -0
  21. data/lib/rant/csharp/mcs_compiler.rb +13 -0
  22. data/lib/rant/csharp/mcs_compiler.rb~ +40 -0
  23. data/lib/rant/csharp/msc_compiler.rb~ +39 -0
  24. data/lib/rant/import/csharp.rb +48 -0
  25. data/lib/rant/import/csharp.rb~ +58 -0
  26. data/lib/rant/import/nunittest.rb +32 -0
  27. data/lib/rant/import/resgen.rb +21 -0
  28. data/lib/rant/import/resgen.rb~ +20 -0
  29. data/lib/rant/init.rb +1 -1
  30. data/lib/rant/rantlib.rb +1 -0
  31. data/lib/rant/rantlib.rb~ +1376 -0
  32. data/lib/rant/rantsys.rb +6 -0
  33. data/run_import +1 -1
  34. data/run_rant +1 -1
  35. data/test/import/package/test_package.rb~ +628 -0
  36. data/test/rule.rf +4 -0
  37. data/test/test_filetask.rb~ +97 -0
  38. data/test/test_rule.rb +10 -0
  39. data/test/test_sys_methods.rb +22 -0
  40. data/test/units/csharp/test_base_compiler_adapter.rb +107 -0
  41. data/test/units/csharp/test_base_compiler_adapter.rb~ +73 -0
  42. data/test/units/csharp/test_compiler_adapter_factory.rb +66 -0
  43. data/test/units/csharp/test_compiler_adapter_factory.rb~ +66 -0
  44. data/test/units/csharp/test_csc_compiler.rb +23 -0
  45. data/test/units/csharp/test_csc_compiler.rb~ +23 -0
  46. data/test/units/csharp/test_gmsc_compiler.rb +19 -0
  47. data/test/units/csharp/test_gmsc_compiler.rb~ +19 -0
  48. data/test/units/csharp/test_msc_compiler.rb +23 -0
  49. data/test/units/csharp/test_msc_compiler.rb~ +23 -0
  50. data/test/units/csharp_test_helper.rb +6 -0
  51. data/test/units/import/test_csharp.rb +127 -0
  52. data/test/units/import/test_csharp.rb~ +126 -0
  53. data/test/units/import/test_nunittest.rb +122 -0
  54. data/test/units/import/test_resgen.rb +107 -0
  55. data/test/units/import/test_resgen.rb~ +88 -0
  56. metadata +269 -224
@@ -26,6 +26,10 @@ gen Rule, :rt => src do |t|
26
26
  sys.touch t.name
27
27
  end
28
28
 
29
+ gen Rule, :ett => :et do |t|
30
+ sys.touch t.name
31
+ end
32
+
29
33
  if var[:enhance_t]
30
34
  enhance "eh.t" do
31
35
  puts "eh.t created"
@@ -0,0 +1,97 @@
1
+
2
+ require 'test/unit'
3
+ require 'tutil'
4
+
5
+ $test_filetask_file = File.expand_path(__FILE__)
6
+ $test_dir ||= File.dirname($test_filetask_file)
7
+
8
+ class TestFileTask < Test::Unit::TestCase
9
+ include Rant::TestUtil
10
+
11
+ def setup
12
+ Dir.chdir $test_dir
13
+ @rant = Rant::RantApp.new
14
+ end
15
+ def test_needed_non_existent
16
+ run = false
17
+ t = Rant::FileTask.new(@rant, "non_existent") { run = true }
18
+ assert(t.needed?,
19
+ "`non_existent' doesn't exist, so filetask is needed")
20
+ assert(!run,
21
+ "only FileTask#needed? was called, which shouldn't run task block")
22
+ end
23
+ def test_needed_no_dep
24
+ run = false
25
+ t = @rant.file $test_filetask_file do
26
+ run = true
27
+ end
28
+ assert(!t.needed?,
29
+ "file exists and has no prerequisite, so needed? should return false")
30
+ assert(!run)
31
+ end
32
+ =begin
33
+ commented out due to a semantics change in 0.4.5
34
+ def test_single_dep
35
+ tr = false
36
+ t = @rant.task :t do
37
+ tr = true
38
+ end
39
+ run = false
40
+ f = @rant.file "testfile" => :t do
41
+ run = true
42
+ end
43
+ f.invoke
44
+ assert(tr)
45
+ assert(run)
46
+ end
47
+ =end
48
+ def test_prerequisites
49
+ @rant.file "a" do
50
+ true
51
+ end
52
+ @rant.file "b" do
53
+ true
54
+ end
55
+ f = @rant.file "c" => %w(a b) do |t|
56
+ assert_equal(t.prerequisites, %w(a b),
57
+ "prerequisites should always be an array of _strings_")
58
+ true
59
+ end
60
+ f.invoke
61
+ end
62
+ def test_no_invoke_task_dep
63
+ write_to_file "print_name.t", "b\n"
64
+ out, err = assert_rant "depends_name.t"
65
+ assert err.empty?
66
+ assert test(?f, "depends_name.t")
67
+ assert_equal "b\na\n", File.read("depends_name.t")
68
+ assert_match(/writing.*depends_name\.t/, out)
69
+ assert !out.include?("print_name.t"),
70
+ "file task mustn't invoke task as prerequisite"
71
+ out, err = assert_rant "depends_name.t"
72
+ assert err.empty?
73
+ assert out.empty?
74
+ assert test(?f, "depends_name.t")
75
+ assert_equal "b\na\n", File.read("depends_name.t")
76
+ ensure
77
+ Rant::Sys.rm_f %w(print_name.t depends_name.t)
78
+ end
79
+ def test_no_invoke_task_dep_md5
80
+ write_to_file "print_name.t", "b\n"
81
+ out, err = assert_rant "-imd5", "depends_name.t"
82
+ assert err.empty?
83
+ assert test(?f, "depends_name.t")
84
+ assert_equal "b\na\n", File.read("depends_name.t")
85
+ assert_match(/writing.*depends_name\.t/, out)
86
+ assert !out.include?("print_name.t"),
87
+ "file task mustn't invoke task as prerequisite"
88
+ out, err = assert_rant "-imd5", "depends_name.t"
89
+ assert err.empty?
90
+ assert out.empty?
91
+ assert test(?f, "depends_name.t")
92
+ assert_equal "b\na\n", File.read("depends_name.t")
93
+ ensure
94
+ Rant::Sys.rm_f %w(auto.rf .rant.meta print_name.t depends_name.t)
95
+ Rant::Sys.rm_f Dir["*.t"]
96
+ end
97
+ end
@@ -185,4 +185,14 @@ if Rant::Env.find_bin("cc") && Rant::Env.find_bin("gcc")
185
185
  else
186
186
  $stderr.puts "*** cc/gcc not available, less rule tests ***"
187
187
  end
188
+ def test_abs_path_source
189
+ FileUtils.touch "abs_rule_test.et"
190
+ abs_target_path = File.expand_path "abs_rule_test.ett"
191
+ out, err = assert_rant("-frule.rf", abs_target_path)
192
+ assert test(?f, abs_target_path)
193
+ out, err = assert_rant("-frule.rf", abs_target_path)
194
+ assert out.empty?
195
+ ensure
196
+ Rant::Sys.rm_f ["abs_rule_test.et", "abs_rule_test.ett"]
197
+ end
188
198
  end
@@ -594,4 +594,26 @@ class TestSysMethods < Test::Unit::TestCase
594
594
  assert !Rant::Sys.root_dir?("C:/foo/bar")
595
595
  end
596
596
  end
597
+ def test_absolute_path?
598
+ assert Rant::Sys.absolute_path?("/foo")
599
+ assert Rant::Sys.absolute_path?("/foo/bar/baz.txt")
600
+ assert Rant::Sys.absolute_path?("/")
601
+ assert Rant::Sys.absolute_path?("//foo")
602
+ assert !Rant::Sys.absolute_path?("foo/")
603
+ assert !Rant::Sys.absolute_path?("")
604
+ assert !Rant::Sys.absolute_path?("foo\\bar")
605
+ if Rant::Env.on_windows?
606
+ assert Rant::Sys.absolute_path?("\\foo")
607
+ assert Rant::Sys.absolute_path?("\\")
608
+ assert Rant::Sys.absolute_path?("C:\\foo")
609
+ assert Rant::Sys.absolute_path?("C:/foo")
610
+ assert Rant::Sys.absolute_path?("C:\\")
611
+ assert Rant::Sys.absolute_path?("C:/")
612
+ else
613
+ assert !Rant::Sys.absolute_path?("C:/")
614
+ assert !Rant::Sys.absolute_path?("C:/foo")
615
+ assert !Rant::Sys.absolute_path?("\\")
616
+ assert !Rant::Sys.absolute_path?("C:\\")
617
+ end
618
+ end
597
619
  end
@@ -0,0 +1,107 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../csharp_test_helper')
2
+ require File.expand_path(File.dirname(__FILE__) +
3
+ '/../../../lib/rant/csharp/base_compiler_adapter')
4
+
5
+ class TestBaseCompilerAdapter < Test::Unit::TestCase
6
+ begin
7
+ require 'mocha'
8
+ @@mocha_required = true
9
+ rescue LoadError
10
+ @@mocha_required = false
11
+ end
12
+
13
+ def setup
14
+ @c = Rant::CSharp::BaseCompilerAdapter.new("testbin")
15
+ end
16
+
17
+ # Tests
18
+ def test_initialize_should_fail_with_blank_bin
19
+ assert_raise(Exception) { Rant::CSharp::BaseCompilerAdapter.new }
20
+ assert_raise(Exception) { Rant::CSharp::BaseCompilerAdapter.new("") }
21
+ end
22
+
23
+ def test_cmd_should_fail_with_blank_target
24
+ assert_raise(Exception) { @c.cmd("", nil, nil) }
25
+ end
26
+
27
+ def test_cmd_should_create_compile_line
28
+ assert_equal "testbin out:outfile target:library ",
29
+ @c.cmd("outfile", {}, mock_context)
30
+ end
31
+
32
+ def test_cmd_should_create_complex_compile_line
33
+ args = {:sources => ["a", "b"],
34
+ :libs => ["c", "d"],
35
+ :target => "exe",
36
+ :checked => false}
37
+
38
+ cmd = @c.cmd("outfile", args, mock_context)
39
+ # Order of arguments is undefined, so use regex to test
40
+ assert_regex "^testbin out:outfile " , cmd
41
+ assert_regex " target:exe " , cmd
42
+ assert_regex " checked- " , cmd
43
+ assert_regex " libs:c libs:d " , cmd
44
+ assert_regex "a b$" , cmd
45
+ end
46
+
47
+ def test_should_provide_default_map_target
48
+ assert_equal "string 1", @c.map_target("string 1")
49
+ assert_equal "string 2", @c.map_target("string 2")
50
+ end
51
+
52
+ def test_should_guess_module_target
53
+ assert_equal "module", @c.guess_target("outfile.netmodule")
54
+ end
55
+
56
+ def test_should_guess_exe_target_as_winexe
57
+ assert_equal "winexe", @c.guess_target("outfile.exe")
58
+ end
59
+
60
+ def test_should_default_to_library_target
61
+ assert_equal "library", @c.guess_target("outfile.dll")
62
+ assert_equal "library", @c.guess_target("outfile")
63
+ end
64
+
65
+ if @@mocha_required
66
+ def test_should_escape_sources_as_string
67
+ sys = mock()
68
+ sys.expects(:sp).with("outfile").returns("outfile")
69
+ sys.expects(:sp).with("a").returns("a")
70
+
71
+ context = mock()
72
+ context.expects(:sys).at_least_once.returns(sys)
73
+
74
+ @c.cmd("outfile", {:sources => "a"}, context)
75
+ end
76
+
77
+ def test_should_escape_sources_as_array
78
+ sys = mock()
79
+ sys.expects(:sp).with("outfile").returns("outfile")
80
+ sys.expects(:sp).with("a").returns("a").times(2)
81
+
82
+ context = mock()
83
+ context.expects(:sys).at_least_once.returns(sys)
84
+
85
+ @c.cmd("outfile", {:sources => ["a", "a"]}, context)
86
+ end
87
+ else
88
+ print "**** Could not run all tests for BaseCompilerAdapter, " +
89
+ "requires mocha libary ****\n"
90
+ end
91
+
92
+ # Helpers
93
+ def mock_context
94
+ Struct.new(:sys).new(MockSys.new)
95
+ end
96
+
97
+ def assert_regex regex, actual
98
+ assert actual =~ Regexp.new(regex), "<\"#{actual}\"> did not match /#{regex}/"
99
+ end
100
+
101
+ # Mocks
102
+ class MockSys
103
+ def sp(file)
104
+ file
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,73 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../csharp_test_helper')
2
+ require File.expand_path(File.dirname(__FILE__) +
3
+ '/../../../lib/rant/csharp/base_compiler_adapter')
4
+
5
+ class TestBaseCompilerAdapter < Test::Unit::TestCase
6
+ def setup
7
+ @c = Rant::CSharp::BaseCompilerAdapter.new("testbin")
8
+ end
9
+
10
+ # Tests
11
+ def test_initialize_should_fail_with_blank_bin
12
+ assert_raise(Exception) { Rant::CSharp::BaseCompilerAdapter.new }
13
+ assert_raise(Exception) { Rant::CSharp::BaseCompilerAdapter.new("") }
14
+ end
15
+
16
+ def test_cmd_should_fail_with_blank_target
17
+ assert_raise(Exception) { @c.cmd("", nil, nil) }
18
+ end
19
+
20
+ def test_cmd_should_create_compile_line
21
+ assert_equal "testbin out:outfile target:library ",
22
+ @c.cmd("outfile", {}, mock_context)
23
+ end
24
+
25
+ def test_cmd_should_create_complex_compile_line
26
+ args = {:sources => ["a", "b"],
27
+ :libs => ["c", "d"],
28
+ :target => "exe",
29
+ :checked => false}
30
+
31
+ cmd = @c.cmd("outfile", args, mock_context)
32
+ # Order of arguments is undefined, so use regex to test
33
+ assert_regex "^testbin out:outfile " , cmd
34
+ assert_regex " target:exe " , cmd
35
+ assert_regex " checked- " , cmd
36
+ assert_regex " libs:c libs:d " , cmd
37
+ assert_regex "a b$" , cmd
38
+ end
39
+
40
+ def test_should_provide_default_map_target
41
+ assert_equal "string 1", @c.map_target("string 1")
42
+ assert_equal "string 2", @c.map_target("string 2")
43
+ end
44
+
45
+ def test_should_guess_module_target
46
+ assert_equal "module", @c.guess_target("outfile.netmodule")
47
+ end
48
+
49
+ def test_should_guess_exe_target_as_winexe
50
+ assert_equal "winexe", @c.guess_target("outfile.exe")
51
+ end
52
+
53
+ def test_should_default_to_library_target
54
+ assert_equal "library", @c.guess_target("outfile.dll")
55
+ assert_equal "library", @c.guess_target("outfile")
56
+ end
57
+
58
+ # Helpers
59
+ def mock_context
60
+ Struct.new(:sys).new(MockSys.new)
61
+ end
62
+
63
+ def assert_regex regex, actual
64
+ assert actual =~ Regexp.new(regex), "<\"#{actual}\"> did not match /#{regex}/"
65
+ end
66
+
67
+ # Mocks
68
+ class MockSys
69
+ def sp(file)
70
+ file
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,66 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../csharp_test_helper')
2
+ require File.expand_path(File.dirname(__FILE__) +
3
+ '/../../../lib/rant/csharp/compiler_adapter_factory')
4
+
5
+ class TestCompilerAdapterFactory < Test::Unit::TestCase
6
+ # Tests
7
+ def test_should_create_compiler_from_bin_in_path
8
+ c = Rant::CSharp::CompilerAdapterFactory.new(mock_context(MockEnv.new))
9
+ c.compiler_map = {"testbin" => MockCompiler }
10
+
11
+ assert c.compiler.kind_of?(MockCompiler),
12
+ "Compiler was not an instance of MockCompiler"
13
+ end
14
+
15
+ def test_should_raise_exception_if_no_compiler_found
16
+ mock_context = Struct.new(:env).new(MockEnvNoBin.new)
17
+ c = Rant::CSharp::CompilerAdapterFactory.new(mock_context(MockEnvNoBin.new))
18
+ assert_raise(Exception) { c.compiler }
19
+ end
20
+
21
+ def test_should_cache_compiler
22
+ mock_context = Struct.new(:env).new(MockEnv.new)
23
+ c = ::Rant::CSharp::CompilerAdapterFactory.new(mock_context)
24
+ c.compiler_map = {"testbin" => MockCompiler }
25
+
26
+ c.compiler # First call to populate cache
27
+ c.compiler_map = nil
28
+
29
+ assert c.compiler.kind_of?(MockCompiler),
30
+ "Complier was not cached"
31
+ end
32
+
33
+ def test_should_have_valid_default_compiler_map
34
+ c = Rant::CSharp::CompilerAdapterFactory.new(nil)
35
+
36
+ assert c.compiler_map.respond_to?("[]"), "Default compiler map is invalid"
37
+ c.compiler_map.each_pair do |key, value|
38
+ assert value.respond_to?(:new),
39
+ "Default compiler map contains an invalid pair: #{key} => #{value}"
40
+ end
41
+ end
42
+
43
+ # Helpers
44
+ def mock_context(env)
45
+ Struct.new(:env).new(env)
46
+ end
47
+
48
+ # Mocks
49
+ class MockEnv
50
+ def find_bin(bin)
51
+ bin == "testbin"
52
+ end
53
+ end
54
+
55
+ class MockEnvNoBin
56
+ def find_bin(bin)
57
+ false
58
+ end
59
+ end
60
+
61
+ class MockCompiler
62
+ def initialize context
63
+ end
64
+ end
65
+ end
66
+
@@ -0,0 +1,66 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/csharp_test_helper')
2
+ require File.expand_path(File.dirname(__FILE__) +
3
+ '/../../../lib/rant/csharp/compiler_adapter_factory')
4
+
5
+ class TestCompilerAdapterFactory < Test::Unit::TestCase
6
+ # Tests
7
+ def test_should_create_compiler_from_bin_in_path
8
+ c = Rant::CSharp::CompilerAdapterFactory.new(mock_context(MockEnv.new))
9
+ c.compiler_map = {"testbin" => MockCompiler }
10
+
11
+ assert c.compiler.kind_of?(MockCompiler),
12
+ "Compiler was not an instance of MockCompiler"
13
+ end
14
+
15
+ def test_should_raise_exception_if_no_compiler_found
16
+ mock_context = Struct.new(:env).new(MockEnvNoBin.new)
17
+ c = Rant::CSharp::CompilerAdapterFactory.new(mock_context(MockEnvNoBin.new))
18
+ assert_raise(Exception) { c.compiler }
19
+ end
20
+
21
+ def test_should_cache_compiler
22
+ mock_context = Struct.new(:env).new(MockEnv.new)
23
+ c = ::Rant::CSharp::CompilerAdapterFactory.new(mock_context)
24
+ c.compiler_map = {"testbin" => MockCompiler }
25
+
26
+ c.compiler # First call to populate cache
27
+ c.compiler_map = nil
28
+
29
+ assert c.compiler.kind_of?(MockCompiler),
30
+ "Complier was not cached"
31
+ end
32
+
33
+ def test_should_have_valid_default_compiler_map
34
+ c = Rant::CSharp::CompilerAdapterFactory.new(nil)
35
+
36
+ assert c.compiler_map.respond_to?("[]"), "Default compiler map is invalid"
37
+ c.compiler_map.each_pair do |key, value|
38
+ assert value.respond_to?(:new),
39
+ "Default compiler map contains an invalid pair: #{key} => #{value}"
40
+ end
41
+ end
42
+
43
+ # Helpers
44
+ def mock_context(env)
45
+ Struct.new(:env).new(env)
46
+ end
47
+
48
+ # Mocks
49
+ class MockEnv
50
+ def find_bin(bin)
51
+ bin == "testbin"
52
+ end
53
+ end
54
+
55
+ class MockEnvNoBin
56
+ def find_bin(bin)
57
+ false
58
+ end
59
+ end
60
+
61
+ class MockCompiler
62
+ def initialize context
63
+ end
64
+ end
65
+ end
66
+