ritsu 0.1.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.
Files changed (73) hide show
  1. data/README.md +96 -0
  2. data/Thorfile +95 -0
  3. data/VERSION +1 -0
  4. data/bin/ritsu +32 -0
  5. data/lib/ritsu/block.rb +259 -0
  6. data/lib/ritsu/ext/test_case.rb +20 -0
  7. data/lib/ritsu/external_library.rb +47 -0
  8. data/lib/ritsu/project.rb +89 -0
  9. data/lib/ritsu/project_generator.rb +34 -0
  10. data/lib/ritsu/project_generators/default_generator.rb +73 -0
  11. data/lib/ritsu/project_generators/default_generator_files/Thorfile.erb +9 -0
  12. data/lib/ritsu/project_generators/default_generator_files/meta/project.rb.erb +9 -0
  13. data/lib/ritsu/project_generators.rb +1 -0
  14. data/lib/ritsu/src_file.rb +76 -0
  15. data/lib/ritsu/src_files/cpp_file.rb +33 -0
  16. data/lib/ritsu/src_files/cpp_file_mixin.rb +13 -0
  17. data/lib/ritsu/src_files/executable_cmake_lists.rb +40 -0
  18. data/lib/ritsu/src_files/header_file.rb +46 -0
  19. data/lib/ritsu/src_files/header_file_mixin.rb +20 -0
  20. data/lib/ritsu/src_files/project_cmake_lists.rb +110 -0
  21. data/lib/ritsu/src_files/project_config_header_file.rb +15 -0
  22. data/lib/ritsu/src_files/project_config_header_template_file.rb +46 -0
  23. data/lib/ritsu/src_files/shared_library_cmake_lists.rb +40 -0
  24. data/lib/ritsu/src_files/static_library_cmake_lists.rb +40 -0
  25. data/lib/ritsu/src_files/target_cmake_lists.rb +159 -0
  26. data/lib/ritsu/src_files/templated_src_file.rb +44 -0
  27. data/lib/ritsu/src_files.rb +14 -0
  28. data/lib/ritsu/target.rb +134 -0
  29. data/lib/ritsu/targets/executable.rb +45 -0
  30. data/lib/ritsu/targets/library.rb +29 -0
  31. data/lib/ritsu/targets/shared_library.rb +39 -0
  32. data/lib/ritsu/targets/static_library.rb +33 -0
  33. data/lib/ritsu/targets.rb +4 -0
  34. data/lib/ritsu/template.rb +69 -0
  35. data/lib/ritsu/template_policies.rb +133 -0
  36. data/lib/ritsu/test_helpers.rb +124 -0
  37. data/lib/ritsu/thors/default_thor.rb +57 -0
  38. data/lib/ritsu/thors.rb +1 -0
  39. data/lib/ritsu/utility/accessors.rb +30 -0
  40. data/lib/ritsu/utility/check_upon_add_set.rb +35 -0
  41. data/lib/ritsu/utility/file_robot.rb +129 -0
  42. data/lib/ritsu/utility/files.rb +13 -0
  43. data/lib/ritsu/utility/instance_dependencies.rb +113 -0
  44. data/lib/ritsu/utility/instance_set.rb +29 -0
  45. data/lib/ritsu/utility/platform.rb +21 -0
  46. data/lib/ritsu/utility/simple_io.rb +65 -0
  47. data/lib/ritsu/utility/single_instance.rb +34 -0
  48. data/lib/ritsu/utility/strings.rb +41 -0
  49. data/lib/ritsu/utility.rb +8 -0
  50. data/lib/ritsu.rb +17 -0
  51. data/test/ritsu/block_test.rb +197 -0
  52. data/test/ritsu/external_library_test.rb +42 -0
  53. data/test/ritsu/project_generators/default_generator_test.rb +34 -0
  54. data/test/ritsu/project_test.rb +128 -0
  55. data/test/ritsu/src_file_test.rb +70 -0
  56. data/test/ritsu/src_files/cpp_file_test.rb +43 -0
  57. data/test/ritsu/src_files/executable_cmake_lists_test.rb +52 -0
  58. data/test/ritsu/src_files/header_file_test.rb +58 -0
  59. data/test/ritsu/src_files/project_cmake_lists_test.rb +152 -0
  60. data/test/ritsu/src_files/shared_library_cmake_lists_test.rb +52 -0
  61. data/test/ritsu/src_files/static_library_cmake_lists_test.rb +52 -0
  62. data/test/ritsu/src_files/target_cmake_lists_test.rb +16 -0
  63. data/test/ritsu/target_test.rb +106 -0
  64. data/test/ritsu/targets/executable_test.rb +11 -0
  65. data/test/ritsu/targets/shared_library_test.rb +11 -0
  66. data/test/ritsu/targets/static_library_test.rb +11 -0
  67. data/test/ritsu/template_policies_test.rb +0 -0
  68. data/test/ritsu/utility/accessors_test.rb +15 -0
  69. data/test/ritsu/utility/check_upon_add_set_test.rb +32 -0
  70. data/test/ritsu/utility/file_robot_test.rb +176 -0
  71. data/test/ritsu/utility/strings_test.rb +29 -0
  72. data/test/test_helpers.rb +4 -0
  73. metadata +209 -0
@@ -0,0 +1,65 @@
1
+ module Ritsu
2
+ module Utility
3
+ ##
4
+ # This class is lifted from rubigen's SimpleLogger
5
+ class SimpleIO
6
+ attr_accessor :input
7
+ attr_accessor :output
8
+ attr_accessor :quiet
9
+
10
+ def initialize(input = $stdin, output = $stdout)
11
+ @input = input
12
+ @output = output
13
+ @quiet = false
14
+ @level = 0
15
+ end
16
+
17
+ def log(status, message, &block)
18
+ @output.print("%12s %s%s\n" % [status, ' ' * @level, message]) unless quiet
19
+ indent(&block) if block_given?
20
+ end
21
+
22
+ def indent(&block)
23
+ @level += 1
24
+ if block_given?
25
+ begin
26
+ block.call
27
+ ensure
28
+ outdent
29
+ end
30
+ end
31
+ end
32
+
33
+ def outdent
34
+ @level -= 1
35
+ if block_given?
36
+ begin
37
+ block.call
38
+ ensure
39
+ indent
40
+ end
41
+ end
42
+ end
43
+
44
+ def ask_yes_no_all(message)
45
+ @output.print("#{message} (yes/no/all): ")
46
+ answer = @input.gets.strip
47
+ case answer
48
+ when /^y(es)?$/i
49
+ return :yes
50
+ when /^no?$/i
51
+ return :no
52
+ when /^a(ll)?$/i
53
+ return :all
54
+ else
55
+ ask_yes_no_all(message)
56
+ end
57
+ end
58
+
59
+ private
60
+ def method_missing(method, *args, &block)
61
+ log(method.to_s, args.first, &block)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,34 @@
1
+ module Ritsu
2
+ module Utility
3
+ module SingleInstance
4
+ module ClassMethods
5
+ def instance
6
+ @instance ||= nil
7
+ end
8
+
9
+ def set_instance(instance)
10
+ validate_instance(instance)
11
+ @instance = instance
12
+ end
13
+
14
+ def validate_instance(instance)
15
+ end
16
+ end
17
+
18
+ def self.included(base)
19
+ base.extend(ClassMethods)
20
+ end
21
+
22
+ def initialize(*args, &block)
23
+ initialize_instance(*args, &block)
24
+ self.class.set_instance(self)
25
+ end
26
+
27
+ def initialize_instance(*args, &block)
28
+ if self.class.superclass.method_defined? :initialize_instance
29
+ super
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,41 @@
1
+ module Ritsu
2
+ module Utility
3
+ module Strings
4
+ def is_underscore_case?(str)
5
+ str =~ /^[a-z_][0-9a-z_]*$/
6
+ end
7
+ module_function :is_underscore_case?
8
+
9
+ def is_c_name?(str)
10
+ str =~ /^[A-Za-z_]\w*$/
11
+ end
12
+ module_function :is_c_name?
13
+
14
+ def first(len, str)
15
+ if str.length > count
16
+ str[0..(len-1)]
17
+ else
18
+ str
19
+ end
20
+ end
21
+ module_function :first
22
+
23
+ def leading_whitespaces(str)
24
+ /^\s*/.match(str)[0]
25
+ end
26
+ module_function :leading_whitespaces
27
+
28
+ def convert_whitespaces_to_spaces(str, options={})
29
+ options = {:soft_tab => 4}.merge(options)
30
+ str.sub("\t", " "*options[:soft_tab]).sub(/\n\r/, "")
31
+ end
32
+ module_function :convert_whitespaces_to_spaces
33
+
34
+ def leading_spaces(str, options={})
35
+ Ritsu::Utility::Strings.convert_whitespaces_to_spaces(
36
+ Ritsu::Utility::Strings.leading_whitespaces(str), options)
37
+ end
38
+ module_function :leading_spaces
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/utility/strings'
2
+ require File.dirname(__FILE__) + '/utility/accessors'
3
+ require File.dirname(__FILE__) + '/utility/instance_set'
4
+ require File.dirname(__FILE__) + '/utility/simple_io'
5
+ require File.dirname(__FILE__) + '/utility/file_robot'
6
+ require File.dirname(__FILE__) + '/utility/check_upon_add_set'
7
+ require File.dirname(__FILE__) + '/utility/files'
8
+ require File.dirname(__FILE__) + '/utility/platform'
data/lib/ritsu.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+
4
+ require File.dirname(__FILE__) + '/ritsu/external_library'
5
+ require File.dirname(__FILE__) + '/ritsu/project'
6
+ require File.dirname(__FILE__) + '/ritsu/target'
7
+ require File.dirname(__FILE__) + '/ritsu/src_file'
8
+ require File.dirname(__FILE__) + '/ritsu/block'
9
+ require File.dirname(__FILE__) + '/ritsu/template'
10
+ require File.dirname(__FILE__) + '/ritsu/project_generator'
11
+
12
+ require File.dirname(__FILE__) + '/ritsu/template_policies'
13
+ require File.dirname(__FILE__) + '/ritsu/targets'
14
+ require File.dirname(__FILE__) + '/ritsu/src_files'
15
+ require File.dirname(__FILE__) + '/ritsu/utility'
16
+ require File.dirname(__FILE__) + '/ritsu/project_generators'
17
+ require File.dirname(__FILE__) + '/ritsu/thors'
@@ -0,0 +1,197 @@
1
+ require File.dirname(__FILE__) + "/../test_helpers"
2
+
3
+ class BlockTest < Test::Unit::TestCase
4
+ include Ritsu::TestCaseWithFileTestData
5
+ include Ritsu::Utility
6
+
7
+ def data_dir; File.dirname(__FILE__) + "/" + File.basename(__FILE__, ".rb") end
8
+
9
+ must "parse lines with no block content correctly" do
10
+ block = Ritsu::Block.new
11
+ block.parse_lines(["abc", "def", "ghi"])
12
+ assert_equal ["abc", "def", "ghi"], block.contents
13
+ end
14
+
15
+ BLOCK_A_ARRAY = [
16
+ "abc",
17
+ "//<< 123",
18
+ "def",
19
+ "//>> 123",
20
+ "ghi",
21
+ "jkl",
22
+ "//<<",
23
+ "mno",
24
+ "pqr",
25
+ "//>>",
26
+ "stu"
27
+ ]
28
+
29
+ def check_block_A(block)
30
+ assert_equal 6, block.contents.length
31
+ assert_equal "abc", block.contents[0]
32
+ assert_equal 1, block.contents[1].contents.length
33
+ assert_equal "def", block.contents[1].contents[0]
34
+ assert_equal "ghi", block.contents[2]
35
+ assert_equal "jkl", block.contents[3]
36
+ assert_equal 2, block.contents[4].contents.length
37
+ assert_equal "mno", block.contents[4].contents[0]
38
+ assert_equal "pqr", block.contents[4].contents[1]
39
+ assert_equal "stu", block.contents[5]
40
+ end
41
+
42
+ must "parse block delimiter correctly" do
43
+ block = Ritsu::Block.new
44
+ block.parse_lines(BLOCK_A_ARRAY)
45
+ check_block_A(block)
46
+ end
47
+
48
+ BLOCK_B_ARRAY = [
49
+ "//<<",
50
+ "//<<",
51
+ "//>>",
52
+
53
+ "//<<",
54
+ "//<<",
55
+ "//>>",
56
+ "//>>",
57
+ "//>>",
58
+
59
+ "//<<",
60
+ "//>>",
61
+ ]
62
+
63
+ def check_block_B(block)
64
+ assert_equal 2, block.contents.length
65
+ assert_equal 2, block.contents[0].contents.length
66
+ assert_equal 0, block.contents[0].contents[0].contents.length
67
+ assert_equal 1, block.contents[0].contents[1].contents.length
68
+ assert_equal 0, block.contents[0].contents[1].contents[0].contents.length
69
+ assert_equal 0, block.contents[1].contents.length
70
+ end
71
+
72
+ must "parse nested block correctly" do
73
+ block = Ritsu::Block.new
74
+ block.parse_lines(BLOCK_B_ARRAY)
75
+ check_block_B(block)
76
+ end
77
+
78
+ must "convert to string correctly" do
79
+ block = Ritsu::Block.new("123",
80
+ :contents => [
81
+ "abc",
82
+ "def",
83
+ Ritsu::Block.new("456",
84
+ :contents => [
85
+ "ghi"
86
+ ]
87
+ ),
88
+ "jkl"
89
+ ]
90
+ )
91
+ expected_string =
92
+ "//<< 123\n" +
93
+ "abc\n" +
94
+ "def\n" +
95
+ "//<< 456\n" +
96
+ "ghi\n" +
97
+ "//>> 456\n" +
98
+ "jkl\n" +
99
+ "//>> 123"
100
+ assert_equal expected_string, block.to_s
101
+ end
102
+
103
+ must "convert to string correct when the no_delimiter option is set" do
104
+ block = Ritsu::Block.new("123",
105
+ :contents => [
106
+ "abc",
107
+ "def",
108
+ Ritsu::Block.new("456",
109
+ :contents => [
110
+ "ghi"
111
+ ]
112
+ ),
113
+ "jkl"
114
+ ]
115
+ )
116
+ expected_string =
117
+ "abc\n" +
118
+ "def\n" +
119
+ "//<< 456\n" +
120
+ "ghi\n" +
121
+ "//>> 456\n" +
122
+ "jkl"
123
+ assert_equal expected_string, block.to_s(:no_delimiter=>true)
124
+ end
125
+
126
+ file_test "write to file" do
127
+ block = Ritsu::Block.new("123",
128
+ :contents => [
129
+ "abc",
130
+ "def",
131
+ Ritsu::Block.new("456",
132
+ :contents => [
133
+ "ghi"
134
+ ]
135
+ ),
136
+ "jkl"
137
+ ]
138
+ )
139
+ expected_content =
140
+ "abc\n" +
141
+ "def\n" +
142
+ "//<< 456\n" +
143
+ "ghi\n" +
144
+ "//>> 456\n" +
145
+ "jkl"
146
+ block.write_to_file(output_path("block.txt"))
147
+ assert_output_file_content expected_content, "block.txt"
148
+ end
149
+
150
+ must "Block.parse must work correctly on array" do
151
+ block = Ritsu::Block.parse(BLOCK_A_ARRAY)
152
+ check_block_A(block)
153
+ end
154
+
155
+ must "Block.parse must work correctly on string" do
156
+ block = Ritsu::Block.parse(BLOCK_A_ARRAY.join("\n"))
157
+ check_block_A(block)
158
+ end
159
+
160
+ file_test "Block_dot_parse must work correct on file" do
161
+ FileRobot.quietly do
162
+ FileRobot.create_file(output_path("block.txt"), BLOCK_A_ARRAY.join("\n"))
163
+ end
164
+ block = Ritsu::Block.parse(:file => output_path("block.txt"))
165
+ check_block_A(block)
166
+ end
167
+
168
+ BLOCK_C_ARRAY = [
169
+ "123",
170
+ " //<< abc",
171
+ " 456",
172
+ " //<< def",
173
+ " 789",
174
+ " //>> def",
175
+ " //>> abc",
176
+ ]
177
+
178
+ must "parse indented blocks correctly" do
179
+ block = Ritsu::Block.parse(BLOCK_C_ARRAY)
180
+ assert_equal " ", block.contents[1].local_indentation
181
+ assert_equal "456", block.contents[1].contents[0]
182
+ assert_equal " ", block.contents[1].contents[1].local_indentation
183
+ assert_equal " 789", block.contents[1].contents[1].contents[0]
184
+
185
+ expected_string = <<-STRING
186
+ 123
187
+ //<< abc
188
+ 456
189
+ //<< def
190
+ 789
191
+ //>> def
192
+ //>> abc
193
+ STRING
194
+ expected_string.strip!
195
+ assert_equal expected_string, block.to_s(:no_delimiter=>true)
196
+ end
197
+ end
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + "/../test_helpers"
2
+
3
+ class ExternalLibraryTest < Test::Unit::TestCase
4
+ include Ritsu
5
+
6
+ def setup
7
+ ExternalLibrary.instances.clear
8
+ end
9
+
10
+ must "initialize correctly" do
11
+ qt = ExternalLibrary.new('qt')
12
+ assert_equal 'qt', qt.name
13
+ assert_equal '', qt.cmake_name
14
+ assert_equal '', qt.cmake_depend_script
15
+ assert_equal '', qt.cmake_find_script
16
+ assert_equal 1, ExternalLibrary.instances.size
17
+ end
18
+
19
+ must "be able to use cmake_name, cmake_depend_script, and cmake_find_script methods in instance_eval" do
20
+ qt = ExternalLibrary.new('qt')
21
+ qt.instance_eval do
22
+ cmake_name 'Qt'
23
+ cmake_depend_script 'abc'
24
+ cmake_find_script 'def'
25
+ end
26
+ assert_equal 'Qt', qt.cmake_name
27
+ assert_equal 'abc', qt.cmake_depend_script
28
+ assert_equal 'def', qt.cmake_find_script
29
+ end
30
+
31
+ must "raise exception if create external library with duplicated names" do
32
+ ExternalLibrary.new('qt')
33
+ assert_raises(ArgumentError) do
34
+ ExternalLibrary.new('qt')
35
+ end
36
+ end
37
+
38
+ must "find_by_name correctly" do
39
+ qt = ExternalLibrary.new('qt')
40
+ assert_equal qt, ExternalLibrary.find_by_name('qt')
41
+ end
42
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + "/../../test_helpers"
2
+
3
+ class DefaultGeneratorTest < Test::Unit::TestCase
4
+ include Ritsu::TestCaseWithFileTestData
5
+ include Ritsu::Utility
6
+
7
+ def data_dir; File.dirname(__FILE__) + "/" + File.basename(__FILE__, ".rb") end
8
+
9
+ file_test "generate" do
10
+ FileRobot.quietly do
11
+ Ritsu::ProjectGenerators::DefaultGenerator.new.generate('mio', output_dir)
12
+ end
13
+
14
+ assert_output_file_exists("mio")
15
+ assert_output_file_exists("mio/build")
16
+ assert_output_file_exists("mio/src")
17
+ assert_output_file_exists("mio/meta")
18
+ assert_output_file_exists("mio/Thorfile")
19
+ assert_output_file_exists("mio/meta/project.rb")
20
+
21
+ expected_project_rb_content = <<-RUBY
22
+ require 'ritsu'
23
+
24
+ Ritsu::Project.create('mio') do |p|
25
+
26
+ ##################
27
+ # YOUR CODE HERE #
28
+ ##################
29
+
30
+ end
31
+ RUBY
32
+ assert_output_file_content(expected_project_rb_content, "mio/meta/project.rb")
33
+ end
34
+ end
@@ -0,0 +1,128 @@
1
+ require File.dirname(__FILE__) + "/../test_helpers"
2
+
3
+ class ProjectTest < Test::Unit::TestCase
4
+ include Ritsu::TestCaseWithFileTestData
5
+ include Ritsu::Utility
6
+
7
+ def data_dir; File.dirname(__FILE__) + "/" + File.basename(__FILE__, ".rb") end
8
+
9
+ def setup
10
+ Ritsu::Target.instances.clear
11
+ Ritsu::SrcFile.instances.clear
12
+ Ritsu::ExternalLibrary.instances.clear
13
+ end
14
+
15
+ must "create correctly" do
16
+ hello = Ritsu::Project.create('hello')
17
+ assert_equal 'hello', hello.name
18
+ assert_equal Set.new, hello.targets
19
+ assert_equal Set.new, hello.external_libraries
20
+ end
21
+
22
+ ['53k', 'abc def', '???'].each do |project_name|
23
+ must "raise exception if project name is #{project_name} (i.e., not a C name)" do
24
+ assert_raises(ArgumentError) do
25
+ Ritsu::Project.create(project_name)
26
+ end
27
+ end
28
+ end
29
+
30
+ ['mio', 'MikuMikuDance', '_Something'].each do |project_name|
31
+ must "not raise exception if project name is #{project_name} (i.e., a valid C name)" do
32
+ assert_nothing_raised do
33
+ Ritsu::Project.create(project_name)
34
+ end
35
+ end
36
+ end
37
+
38
+ must "be able to add external libraries" do
39
+ hello = Ritsu::Project.create('hello') do |p|
40
+ p.add_external_library 'qt_core' do |e|
41
+ e.cmake_name '${QT_LIBRARIES}'
42
+ e.cmake_find_script <<-CMAKE
43
+ FIND_PACKAGE(Qt4 REQUIRED)
44
+ CMAKE
45
+ e.cmake_depend_script <<-CMAKE
46
+ INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR})
47
+ SET(QT_DONT_USE_QTGUI TRUE)
48
+ CMAKE
49
+ end
50
+ p.add_external_library 'qt_core_gui' do |e|
51
+ e.cmake_name '${QT_LIBRARIES}'
52
+ e.cmake_find_script <<-CMAKE
53
+ FIND_PACKAGE(Qt4 REQUIRED)
54
+ CMAKE
55
+ e.cmake_depend_script <<-CMAKE
56
+ INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR})
57
+ CMAKE
58
+ end
59
+ p.add_external_library 'qt_core_gui_opengl' do |e|
60
+ e.cmake_name '${QT_LIBRARIES}'
61
+ e.cmake_find_script <<-CMAKE
62
+ FIND_PACKAGE(Qt4 REQUIRED)
63
+ CMAKE
64
+ e.cmake_depend_script <<-CMAKE
65
+ INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR})
66
+ SET(QT_USE_OPENGL TRUE)
67
+ CMAKE
68
+ end
69
+ end
70
+
71
+ assert_equal 3, hello.external_libraries.length
72
+ assert hello.external_libraries.any? { |x| x.name == 'qt_core' }
73
+ assert hello.external_libraries.any? { |x| x.name == 'qt_core_gui' }
74
+ assert hello.external_libraries.any? { |x| x.name == 'qt_core_gui_opengl' }
75
+ end
76
+
77
+ must "be able to add targets" do
78
+ hello = Ritsu::Project.create('hello') do |p|
79
+ p.add_executable 'abc'
80
+ p.add_shared_library 'def'
81
+ p.add_static_library 'ghi'
82
+ end
83
+
84
+ assert_equal 3, hello.targets.length
85
+ assert hello.targets.any? { |x| x.name == 'abc' }
86
+ assert hello.targets.any? { |x| x.name == 'def' }
87
+ assert hello.targets.any? { |x| x.name == 'ghi' }
88
+ end
89
+
90
+ file_test "create config header file" do
91
+ hello = Ritsu::Project.create('hello')
92
+ hello.project_dir = output_dir
93
+ assert hello.respond_to?(:config_header_file)
94
+ assert hello.src_files.any? {|x| x.src_path != "config.h"}
95
+
96
+ FileRobot.quietly do
97
+ hello.update
98
+ end
99
+
100
+ assert_output_file_exists("src/config.h")
101
+ assert_output_file_content("\n", "src/config.h")
102
+ end
103
+
104
+ file_test "create config header template file" do
105
+ hello = Ritsu::Project.create('hello')
106
+ hello.project_dir = output_dir
107
+ assert hello.respond_to?(:config_header_template_file)
108
+ assert hello.src_files.any? {|x| x.src_path != "config.h.in"}
109
+
110
+ FileRobot.quietly do
111
+ hello.update
112
+ end
113
+
114
+ assert_output_file_exists("src/config.h.in")
115
+
116
+ expected_content = <<-TEXT
117
+ #ifndef __PROJECT_CONFIG_H__
118
+ #define __PROJECT_CONFIG_H__
119
+
120
+ #cmakedefine __WIN_PLATFORM__
121
+ #cmakedefine __MAC_PLATFORM__
122
+ #cmakedefine __UNIX_PLATFORM__
123
+
124
+ #endif
125
+ TEXT
126
+ assert_output_file_content("\n", "src/config.h")
127
+ end
128
+ end
@@ -0,0 +1,70 @@
1
+ require File.dirname(__FILE__) + "/../test_helpers"
2
+
3
+ class SrcFileTest < Test::Unit::TestCase
4
+ include Ritsu::SetupProjectAndClearEverythingElse
5
+
6
+ def self.test_valid_src_path(src_path)
7
+ must "#{src_path} is a valid source path" do
8
+ assert Ritsu::SrcFile.is_valid_src_path?(src_path),
9
+ "#{src_path} must be a valid source path"
10
+ end
11
+ end
12
+
13
+ test_valid_src_path "abc.txt"
14
+ test_valid_src_path "SomeProject/Something_else.cpp"
15
+ test_valid_src_path "mio/koakuma/shadow_gl_renderer.cpp"
16
+ test_valid_src_path ".abc"
17
+ test_valid_src_path "abc-hello.c"
18
+
19
+ def self.test_invalid_src_path(src_path)
20
+ must "#{src_path} is not a valid source path" do
21
+ assert !Ritsu::SrcFile.is_valid_src_path?(src_path),
22
+ "#{src_path} must not be a valid source path"
23
+ end
24
+ end
25
+
26
+ test_invalid_src_path "abc def"
27
+ test_invalid_src_path "/home/one_users/.tmp"
28
+ test_invalid_src_path ""
29
+
30
+ must "throw exception if a source file with invalid source path is given" do
31
+ assert_raises ArgumentError do
32
+ Ritsu::SrcFile.new("abc def", @project)
33
+ end
34
+ end
35
+
36
+ must "throw exception if two source files have duplicated names" do
37
+ assert_raises ArgumentError do
38
+ Ritsu::SrcFile.new("abc/abc.txt", @project)
39
+ Ritsu::SrcFile.new("abc/abc.txt", @project)
40
+ end
41
+ end
42
+
43
+ must "now throw exception if source path is a valid source path" do
44
+ assert_nothing_raised do
45
+ Ritsu::SrcFile.new("abc/abc.txt", @project)
46
+ end
47
+ end
48
+
49
+ must "be added to the owner's src_files array" do
50
+ abc = Ritsu::SrcFile.new("abc/abc.txt", @project)
51
+ assert @project.src_files.include?(abc)
52
+ end
53
+
54
+ must "return its project correctly when owner is the project" do
55
+ abc = Ritsu::SrcFile.new("abc/abc.txt", @project)
56
+ assert_equal @project, abc.project
57
+ end
58
+
59
+ must "return its project correct when owheter is a target" do
60
+ target = Ritsu::Targets::Executable.new("def")
61
+ abc = Ritsu::SrcFile.new('abc/abc.txt', target)
62
+ assert_equal target, abc.owner
63
+ assert_equal @project, abc.project
64
+ end
65
+
66
+ must "compute absolute path correctly" do
67
+ abc = Ritsu::SrcFile.new("abc/abc.txt", @project)
68
+ assert_equal @project.project_dir + "/src/abc/abc.txt", abc.abs_path
69
+ end
70
+ end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + "/../../test_helpers"
2
+
3
+ class CppFileTest < Test::Unit::TestCase
4
+ include Ritsu::SetupProjectAndClearEverythingElse
5
+ include Ritsu::TestCaseWithFileTestData
6
+ include Ritsu::Utility
7
+
8
+ def data_dir; File.dirname(__FILE__) + "/" + File.basename(__FILE__, ".rb") end
9
+
10
+ def setup
11
+ setup_project
12
+ @project.project_dir = output_dir
13
+ @target = Ritsu::Targets::Executable.new("abc", :project=>@project)
14
+ end
15
+
16
+ file_test "create" do
17
+ @cpp_file = Ritsu::SrcFiles::CppFile.new("abc/def.cpp", @target)
18
+ FileRobot.quietly do
19
+ @cpp_file.create
20
+ end
21
+ assert_file_exists(@cpp_file.abs_path)
22
+ assert_file_content("\n", @cpp_file.abs_path)
23
+ end
24
+
25
+ file_test "update_does_nothing" do
26
+ @header_file = Ritsu::SrcFiles::CppFile.new("abc/def.cpp", @target)
27
+ FileRobot.quietly do
28
+ FileRobot.create_file(output_path("src/abc/def.cpp"), "abc")
29
+ @header_file.update
30
+ end
31
+ assert_file_content("abc", @header_file.abs_path)
32
+ end
33
+
34
+ file_test "delete" do
35
+ @header_file = Ritsu::SrcFiles::CppFile.new("abc/def.cpp", @target)
36
+ FileRobot.quietly do
37
+ @header_file.create
38
+ assert_file_exists(@header_file.abs_path)
39
+ @header_file.remove
40
+ assert_file_not_exist(@header_file.abs_path)
41
+ end
42
+ end
43
+ end