ritsu 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/README.md +95 -95
  2. data/bin/define_cpp_string +54 -54
  3. data/bin/ritsu +31 -31
  4. data/lib/ritsu.rb +16 -16
  5. data/lib/ritsu/block.rb +258 -258
  6. data/lib/ritsu/ext/cuda.rb +5 -5
  7. data/lib/ritsu/ext/cuda/external_library.rb +15 -15
  8. data/lib/ritsu/ext/cuda/project.rb +31 -31
  9. data/lib/ritsu/ext/cuda/src_files/cu_file.rb +46 -46
  10. data/lib/ritsu/ext/cuda/src_files/target_cmake_lists.rb +110 -110
  11. data/lib/ritsu/ext/cuda/target.rb +16 -16
  12. data/lib/ritsu/ext/cuda/targets/library.rb +16 -16
  13. data/lib/ritsu/ext/fake_install.rb +2 -2
  14. data/lib/ritsu/ext/fake_install/project.rb +16 -16
  15. data/lib/ritsu/ext/fake_install/src_files/project_cmake_lists.rb +45 -45
  16. data/lib/ritsu/ext/glsl.rb +1 -1
  17. data/lib/ritsu/ext/glsl/src_files/frag_file.rb +70 -70
  18. data/lib/ritsu/ext/glsl/src_files/vert_file.rb +70 -70
  19. data/lib/ritsu/ext/qt.rb +4 -4
  20. data/lib/ritsu/ext/qt/project.rb +47 -47
  21. data/lib/ritsu/ext/qt/src_files/header_file.rb +60 -60
  22. data/lib/ritsu/ext/qt/src_files/target_cmake_lists.rb +106 -106
  23. data/lib/ritsu/ext/qt/src_files/ui_file.rb +46 -46
  24. data/lib/ritsu/ext/test_case.rb +19 -19
  25. data/lib/ritsu/external_library.rb +46 -46
  26. data/lib/ritsu/project.rb +93 -93
  27. data/lib/ritsu/project_generator.rb +33 -33
  28. data/lib/ritsu/project_generators/default_generator.rb +72 -72
  29. data/lib/ritsu/project_generators/default_generator_files/Thorfile.erb +8 -8
  30. data/lib/ritsu/project_generators/default_generator_files/meta/project.rb.erb +10 -10
  31. data/lib/ritsu/src_file.rb +79 -79
  32. data/lib/ritsu/src_files.rb +12 -12
  33. data/lib/ritsu/src_files/cpp_file.rb +43 -43
  34. data/lib/ritsu/src_files/executable_cmake_lists.rb +39 -39
  35. data/lib/ritsu/src_files/header_file.rb +60 -60
  36. data/lib/ritsu/src_files/project_cmake_lists.rb +133 -133
  37. data/lib/ritsu/src_files/project_config_header_file.rb +14 -14
  38. data/lib/ritsu/src_files/project_config_header_template_file.rb +44 -44
  39. data/lib/ritsu/src_files/shared_library_cmake_lists.rb +39 -39
  40. data/lib/ritsu/src_files/static_library_cmake_lists.rb +39 -39
  41. data/lib/ritsu/src_files/target_cmake_lists.rb +189 -189
  42. data/lib/ritsu/src_files/templated_src_file.rb +47 -47
  43. data/lib/ritsu/src_files/unit.rb +32 -32
  44. data/lib/ritsu/target.rb +154 -154
  45. data/lib/ritsu/targets.rb +3 -3
  46. data/lib/ritsu/targets/executable.rb +44 -44
  47. data/lib/ritsu/targets/library.rb +29 -29
  48. data/lib/ritsu/targets/shared_library.rb +38 -38
  49. data/lib/ritsu/targets/static_library.rb +32 -32
  50. data/lib/ritsu/template.rb +68 -68
  51. data/lib/ritsu/template_policies.rb +132 -132
  52. data/lib/ritsu/test_helpers.rb +123 -123
  53. data/lib/ritsu/thors/default_thor.rb +1 -1
  54. data/lib/ritsu/utility.rb +7 -7
  55. data/lib/ritsu/utility/accessors.rb +29 -29
  56. data/lib/ritsu/utility/check_upon_add_set.rb +34 -34
  57. data/lib/ritsu/utility/file_robot.rb +128 -128
  58. data/lib/ritsu/utility/files.rb +12 -12
  59. data/lib/ritsu/utility/instance_dependencies.rb +112 -112
  60. data/lib/ritsu/utility/instance_set.rb +28 -28
  61. data/lib/ritsu/utility/platform.rb +20 -20
  62. data/lib/ritsu/utility/simple_io.rb +64 -64
  63. data/lib/ritsu/utility/single_instance.rb +33 -33
  64. data/lib/ritsu/utility/strings.rb +40 -40
  65. data/test/ritsu/block_test.rb +196 -196
  66. data/test/ritsu/ext/cuda/src_files/cuda_static_library_cmake_lists_test.rb +63 -63
  67. data/test/ritsu/external_library_test.rb +41 -41
  68. data/test/ritsu/project_generators/default_generator_test.rb +34 -34
  69. data/test/ritsu/project_test.rb +127 -127
  70. data/test/ritsu/src_file_test.rb +69 -69
  71. data/test/ritsu/src_files/cpp_file_test.rb +42 -42
  72. data/test/ritsu/src_files/executable_cmake_lists_test.rb +92 -92
  73. data/test/ritsu/src_files/header_file_test.rb +57 -57
  74. data/test/ritsu/src_files/project_cmake_lists_test.rb +159 -159
  75. data/test/ritsu/src_files/shared_library_cmake_lists_test.rb +54 -54
  76. data/test/ritsu/src_files/static_library_cmake_lists_test.rb +54 -54
  77. data/test/ritsu/src_files/target_cmake_lists_test.rb +15 -15
  78. data/test/ritsu/target_test.rb +105 -105
  79. data/test/ritsu/targets/executable_test.rb +10 -10
  80. data/test/ritsu/targets/shared_library_test.rb +10 -10
  81. data/test/ritsu/targets/static_library_test.rb +10 -10
  82. data/test/ritsu/utility/accessors_test.rb +14 -14
  83. data/test/ritsu/utility/check_upon_add_set_test.rb +31 -31
  84. data/test/ritsu/utility/file_robot_test.rb +175 -175
  85. data/test/ritsu/utility/strings_test.rb +28 -28
  86. data/test/test_helpers.rb +3 -3
  87. metadata +72 -124
  88. data/Thorfile +0 -104
  89. data/VERSION +0 -1
@@ -1,16 +1,16 @@
1
- require File.dirname(__FILE__) + "/../../test_helpers"
2
-
3
- class TargetCMakeListsTest < Test::Unit::TestCase
4
- include Ritsu::SetupProjectAndClearEverythingElse
5
-
6
- must "src_path must be target_name/CMakeLists.txt" do
7
- target = Ritsu::Targets::Executable.new("abc", :project=>@project)
8
- assert_equal "abc/CMakeLists.txt", target.cmake_lists.src_path
9
- end
10
-
11
- must "src_path must be project_dir/target_name/CMakeLists.txt" do
12
- target = Ritsu::Targets::Executable.new("abc", :project=>@project)
13
- assert_equal "#{@project.project_dir}/src/abc/CMakeLists.txt",
14
- target.cmake_lists.abs_path
15
- end
1
+ require File.dirname(__FILE__) + "/../../test_helpers"
2
+
3
+ class TargetCMakeListsTest < Test::Unit::TestCase
4
+ include Ritsu::SetupProjectAndClearEverythingElse
5
+
6
+ must "src_path must be target_name/CMakeLists.txt" do
7
+ target = Ritsu::Targets::Executable.new("abc", :project=>@project)
8
+ assert_equal "abc/CMakeLists.txt", target.cmake_lists.src_path
9
+ end
10
+
11
+ must "src_path must be project_dir/target_name/CMakeLists.txt" do
12
+ target = Ritsu::Targets::Executable.new("abc", :project=>@project)
13
+ assert_equal "#{@project.project_dir}/src/abc/CMakeLists.txt",
14
+ target.cmake_lists.abs_path
15
+ end
16
16
  end
@@ -1,106 +1,106 @@
1
- require File.dirname(__FILE__) + "/../test_helpers"
2
-
3
- class TargetTest < Test::Unit::TestCase
4
- include Ritsu
5
- include Ritsu::Targets
6
- include Ritsu::SetupProjectAndClearEverythingElse
7
-
8
- must "contruct instances and keep track of them correctly" do
9
- Executable.new("abc")
10
- SharedLibrary.new("def")
11
- StaticLibrary.new("ghi")
12
-
13
- assert_equal 3, Target.instances.length
14
-
15
- assert Target.instances.any? {|x| x.name =='abc'}
16
- assert Target.instances.any? {|x| x.name == 'def'}
17
- assert Target.instances.any? {|x| x.name == 'ghi'}
18
-
19
- assert Target.instances.any? {|x| x.kind_of?(Executable)}
20
- assert Target.instances.any? {|x| x.kind_of?(SharedLibrary)}
21
- assert Target.instances.any? {|x| x.kind_of?(StaticLibrary)}
22
- end
23
-
24
- must "set the project to the default project if none is explicitly specified" do
25
- abc = Executable.new('abc')
26
- assert_equal @project, abc.project
27
- end
28
-
29
- must "upon creation, add the target to the given project" do
30
- abc = Executable.new('abc', :project => @project)
31
- assert_equal 1, @project.targets.length
32
- assert @project.targets.any? {|x| x.name == 'abc'}
33
- end
34
-
35
- def setup_abcd_dependency_tree
36
- @a = SharedLibrary.new('a')
37
- @b = SharedLibrary.new('b')
38
- @c = SharedLibrary.new('c')
39
- @d = StaticLibrary.new('d')
40
-
41
- @b.dependency_targets << @a
42
- @c.dependency_targets << @b
43
- @d.dependency_targets << @a
44
-
45
- @nodes = {:a => @a, :b => @b, :c => @c, :d => @d}
46
- end
47
-
48
- must "be able to determine which target it depends directly on" do
49
- setup_abcd_dependency_tree
50
-
51
- [[:b,:a], [:c,:b], [:d,:a]].each do |u,v|
52
- assert @nodes[u].depends_directly_on_target?(@nodes[v]),
53
- "#{u} must depend directly on #{v}"
54
- end
55
-
56
- [[:c,:a], [:a,:b], [:b,:b], [:b,:d]].each do |u,v|
57
- assert !(@nodes[u].depends_directly_on_target?(@nodes[v])),
58
- "#{u} must not depend directly on #{v}"
59
- end
60
- end
61
-
62
- must "be able to determine which target it depends on, even not directly, on" do
63
- setup_abcd_dependency_tree
64
-
65
- [[:b,:a], [:c,:b], [:c,:b], [:d,:a]].each do |u,v|
66
- assert @nodes[u].depends_on_target?(@nodes[v]),
67
- "#{u} must depend on #{v}"
68
- end
69
-
70
- [[:a,:a], [:a,:b], [:a,:c], [:a,:d], [:b,:d], [:b,:c], [:c,:d], [:d,:c]].each do |u,v|
71
- assert !(@nodes[u].depends_on_target?(@nodes[v])),
72
- "#{u} must not depend on #{v}"
73
- end
74
- end
75
-
76
- must "compute topological orders correctly" do
77
- setup_abcd_dependency_tree
78
-
79
- Target.compute_topological_orders
80
-
81
- [[:b,:a], [:c,:b], [:d,:a]].each do |u,v|
82
- assert @nodes[u].topological_order > @nodes[v].topological_order,
83
- "#{u} should come after #{v} in topological ordering"
84
- end
85
- end
86
-
87
- must "src_dir" do
88
- abc = Executable.new('abc')
89
- assert_equal "abc", abc.src_dir
90
- end
91
-
92
- must "compute src_path correctly" do
93
- abc = Executable.new('abc')
94
- assert_equal "abc/temp.cpp", abc.compute_src_path("temp.cpp")
95
- end
96
-
97
- must "compute src_path correctly relative to src" do
98
- abc = Executable.new('abc')
99
- assert_equal "xyz/temp.cpp", abc.compute_src_path("xyz/temp.cpp", :relative_to => :src)
100
- end
101
-
102
- must "compute src_path correct when the input is absolute" do
103
- abc = Executable.new('abc')
104
- assert_equal "../temp.cpp", abc.compute_src_path(@project.project_dir + "/temp.cpp", :relative_to => :absolute)
105
- end
1
+ require File.dirname(__FILE__) + "/../test_helpers"
2
+
3
+ class TargetTest < Test::Unit::TestCase
4
+ include Ritsu
5
+ include Ritsu::Targets
6
+ include Ritsu::SetupProjectAndClearEverythingElse
7
+
8
+ must "contruct instances and keep track of them correctly" do
9
+ Executable.new("abc")
10
+ SharedLibrary.new("def")
11
+ StaticLibrary.new("ghi")
12
+
13
+ assert_equal 3, Target.instances.length
14
+
15
+ assert Target.instances.any? {|x| x.name =='abc'}
16
+ assert Target.instances.any? {|x| x.name == 'def'}
17
+ assert Target.instances.any? {|x| x.name == 'ghi'}
18
+
19
+ assert Target.instances.any? {|x| x.kind_of?(Executable)}
20
+ assert Target.instances.any? {|x| x.kind_of?(SharedLibrary)}
21
+ assert Target.instances.any? {|x| x.kind_of?(StaticLibrary)}
22
+ end
23
+
24
+ must "set the project to the default project if none is explicitly specified" do
25
+ abc = Executable.new('abc')
26
+ assert_equal @project, abc.project
27
+ end
28
+
29
+ must "upon creation, add the target to the given project" do
30
+ abc = Executable.new('abc', :project => @project)
31
+ assert_equal 1, @project.targets.length
32
+ assert @project.targets.any? {|x| x.name == 'abc'}
33
+ end
34
+
35
+ def setup_abcd_dependency_tree
36
+ @a = SharedLibrary.new('a')
37
+ @b = SharedLibrary.new('b')
38
+ @c = SharedLibrary.new('c')
39
+ @d = StaticLibrary.new('d')
40
+
41
+ @b.dependency_targets << @a
42
+ @c.dependency_targets << @b
43
+ @d.dependency_targets << @a
44
+
45
+ @nodes = {:a => @a, :b => @b, :c => @c, :d => @d}
46
+ end
47
+
48
+ must "be able to determine which target it depends directly on" do
49
+ setup_abcd_dependency_tree
50
+
51
+ [[:b,:a], [:c,:b], [:d,:a]].each do |u,v|
52
+ assert @nodes[u].depends_directly_on_target?(@nodes[v]),
53
+ "#{u} must depend directly on #{v}"
54
+ end
55
+
56
+ [[:c,:a], [:a,:b], [:b,:b], [:b,:d]].each do |u,v|
57
+ assert !(@nodes[u].depends_directly_on_target?(@nodes[v])),
58
+ "#{u} must not depend directly on #{v}"
59
+ end
60
+ end
61
+
62
+ must "be able to determine which target it depends on, even not directly, on" do
63
+ setup_abcd_dependency_tree
64
+
65
+ [[:b,:a], [:c,:b], [:c,:b], [:d,:a]].each do |u,v|
66
+ assert @nodes[u].depends_on_target?(@nodes[v]),
67
+ "#{u} must depend on #{v}"
68
+ end
69
+
70
+ [[:a,:a], [:a,:b], [:a,:c], [:a,:d], [:b,:d], [:b,:c], [:c,:d], [:d,:c]].each do |u,v|
71
+ assert !(@nodes[u].depends_on_target?(@nodes[v])),
72
+ "#{u} must not depend on #{v}"
73
+ end
74
+ end
75
+
76
+ must "compute topological orders correctly" do
77
+ setup_abcd_dependency_tree
78
+
79
+ Target.compute_topological_orders
80
+
81
+ [[:b,:a], [:c,:b], [:d,:a]].each do |u,v|
82
+ assert @nodes[u].topological_order > @nodes[v].topological_order,
83
+ "#{u} should come after #{v} in topological ordering"
84
+ end
85
+ end
86
+
87
+ must "src_dir" do
88
+ abc = Executable.new('abc')
89
+ assert_equal "abc", abc.src_dir
90
+ end
91
+
92
+ must "compute src_path correctly" do
93
+ abc = Executable.new('abc')
94
+ assert_equal "abc/temp.cpp", abc.compute_src_path("temp.cpp")
95
+ end
96
+
97
+ must "compute src_path correctly relative to src" do
98
+ abc = Executable.new('abc')
99
+ assert_equal "xyz/temp.cpp", abc.compute_src_path("xyz/temp.cpp", :relative_to => :src)
100
+ end
101
+
102
+ must "compute src_path correct when the input is absolute" do
103
+ abc = Executable.new('abc')
104
+ assert_equal "../temp.cpp", abc.compute_src_path(@project.project_dir + "/temp.cpp", :relative_to => :absolute)
105
+ end
106
106
  end
@@ -1,11 +1,11 @@
1
- require File.dirname(__FILE__) + "/../../test_helpers"
2
-
3
- class ExecutableTest < Test::Unit::TestCase
4
- include Ritsu::Targets
5
- include Ritsu::SetupProjectAndClearEverythingElse
6
-
7
- must "not be able to be depended on" do
8
- exe = Executable.new('exe')
9
- assert !exe.can_be_depended_on?
10
- end
1
+ require File.dirname(__FILE__) + "/../../test_helpers"
2
+
3
+ class ExecutableTest < Test::Unit::TestCase
4
+ include Ritsu::Targets
5
+ include Ritsu::SetupProjectAndClearEverythingElse
6
+
7
+ must "not be able to be depended on" do
8
+ exe = Executable.new('exe')
9
+ assert !exe.can_be_depended_on?
10
+ end
11
11
  end
@@ -1,11 +1,11 @@
1
- require File.dirname(__FILE__) + "/../../test_helpers"
2
-
3
- class SharedLibraryTest < Test::Unit::TestCase
4
- include Ritsu::Targets
5
- include Ritsu::SetupProjectAndClearEverythingElse
6
-
7
- must "be able to be depended on" do
8
- so = SharedLibrary.new('so')
9
- assert so.can_be_depended_on?
10
- end
1
+ require File.dirname(__FILE__) + "/../../test_helpers"
2
+
3
+ class SharedLibraryTest < Test::Unit::TestCase
4
+ include Ritsu::Targets
5
+ include Ritsu::SetupProjectAndClearEverythingElse
6
+
7
+ must "be able to be depended on" do
8
+ so = SharedLibrary.new('so')
9
+ assert so.can_be_depended_on?
10
+ end
11
11
  end
@@ -1,11 +1,11 @@
1
- require File.dirname(__FILE__) + "/../../test_helpers"
2
-
3
- class StaticLibraryTest < Test::Unit::TestCase
4
- include Ritsu::Targets
5
- include Ritsu::SetupProjectAndClearEverythingElse
6
-
7
- must "be able to be depended on" do
8
- a = StaticLibrary.new('a')
9
- assert a.can_be_depended_on?
10
- end
1
+ require File.dirname(__FILE__) + "/../../test_helpers"
2
+
3
+ class StaticLibraryTest < Test::Unit::TestCase
4
+ include Ritsu::Targets
5
+ include Ritsu::SetupProjectAndClearEverythingElse
6
+
7
+ must "be able to be depended on" do
8
+ a = StaticLibrary.new('a')
9
+ assert a.can_be_depended_on?
10
+ end
11
11
  end
@@ -1,15 +1,15 @@
1
- require File.dirname(__FILE__) + "/../../test_helpers"
2
-
3
-
4
- class AccessorsTest < Test::Unit::TestCase
5
- class A
6
- include Ritsu::Utility::Accessors
7
- attr_method :x
8
- end
9
-
10
- must "attr_equal works correctly" do
11
- a = A.new
12
- a.x 10
13
- assert_equal 10, a.x
14
- end
1
+ require File.dirname(__FILE__) + "/../../test_helpers"
2
+
3
+
4
+ class AccessorsTest < Test::Unit::TestCase
5
+ class A
6
+ include Ritsu::Utility::Accessors
7
+ attr_method :x
8
+ end
9
+
10
+ must "attr_equal works correctly" do
11
+ a = A.new
12
+ a.x 10
13
+ assert_equal 10, a.x
14
+ end
15
15
  end
@@ -1,32 +1,32 @@
1
- require File.dirname(__FILE__) + "/../../test_helpers"
2
-
3
- class CheckUponAddSetTest < Test::Unit::TestCase
4
- include Ritsu::Utility
5
-
6
- must "behave like normal set when given no block" do
7
- s = CheckUponAddSet.new
8
- s << 1 << 2 << "abc"
9
- assert s.include?(1)
10
- assert s.include?(2)
11
- assert s.include?("abc")
12
- s.delete(1)
13
- assert !s.include?(1)
14
- end
15
-
16
- must "preform check when block is given" do
17
- s = CheckUponAddSet.new do |s,x|
18
- if x > 10
19
- raise ArgumentError.new("inserted value more than 10!")
20
- end
21
- end
22
- assert_nothing_raised do
23
- s << 1
24
- s << 2
25
- s << 10
26
- s << -1
27
- end
28
- assert_raises ArgumentError do
29
- s << 11
30
- end
31
- end
1
+ require File.dirname(__FILE__) + "/../../test_helpers"
2
+
3
+ class CheckUponAddSetTest < Test::Unit::TestCase
4
+ include Ritsu::Utility
5
+
6
+ must "behave like normal set when given no block" do
7
+ s = CheckUponAddSet.new
8
+ s << 1 << 2 << "abc"
9
+ assert s.include?(1)
10
+ assert s.include?(2)
11
+ assert s.include?("abc")
12
+ s.delete(1)
13
+ assert !s.include?(1)
14
+ end
15
+
16
+ must "preform check when block is given" do
17
+ s = CheckUponAddSet.new do |s,x|
18
+ if x > 10
19
+ raise ArgumentError.new("inserted value more than 10!")
20
+ end
21
+ end
22
+ assert_nothing_raised do
23
+ s << 1
24
+ s << 2
25
+ s << 10
26
+ s << -1
27
+ end
28
+ assert_raises ArgumentError do
29
+ s << 11
30
+ end
31
+ end
32
32
  end
@@ -1,176 +1,176 @@
1
- require File.dirname(__FILE__) + "/../../test_helpers"
2
-
3
- class FileRobotTest < Test::Unit::TestCase
4
- include Ritsu::Utility
5
- include Ritsu::TestCaseWithFileTestData
6
-
7
- def data_dir; File.dirname(__FILE__) + "/" + File.basename(__FILE__, ".rb") end
8
-
9
- def setup
10
- init_data_dir
11
- @input = StringIO.new
12
- @output = StringIO.new
13
- FileRobot.input = @input
14
- FileRobot.output = @output
15
- end
16
-
17
- def provide_input(string)
18
- @input << string
19
- @input.rewind
20
- end
21
-
22
- def expect_output(string)
23
- assert_equal string, @output.string
24
- end
25
-
26
- must "force must be initially false" do
27
- assert !FileRobot.force
28
- end
29
-
30
- must "quiet must be initially false" do
31
- assert !FileRobot.quiet
32
- end
33
-
34
- file_test "create empty file" do
35
- FileRobot.create_file(output_path("abc.txt"))
36
- assert_output_file_exists "abc.txt"
37
- assert_output_file_content "", "abc.txt"
38
- expect_output(" create #{output_dir}/abc.txt\n")
39
- end
40
-
41
- file_test "create file with content" do
42
- FileRobot.create_file(output_path("abc.txt"), "def")
43
- assert_output_file_content "def", "abc.txt"
44
- expect_output(" create #{output_dir}/abc.txt\n")
45
- end
46
-
47
- file_test "create parent directories when creating a file" do
48
- FileRobot.create_file(output_path("a/b/c/def.txt"), "def")
49
- assert_output_file_exists "a/b/c/def.txt"
50
- expect_output(
51
- " create #{output_dir}/a/b/c\n" +
52
- " create #{output_dir}/a/b/c/def.txt\n"
53
- )
54
- end
55
-
56
- file_test "create directory" do
57
- FileRobot.create_dir(output_path("abc/def/ghi"))
58
- assert_file_exists(output_path("abc/def/ghi"))
59
- expect_output(" create #{output_dir}/abc/def/ghi\n")
60
- end
61
-
62
- file_test "display exist message when dir already exist" do
63
- FileRobot.create_dir(output_path("abc"))
64
- FileRobot.create_dir(output_path("abc"))
65
- expect_output(
66
- " create #{output_dir}/abc\n" +
67
- " exist #{output_dir}/abc\n"
68
- )
69
- end
70
-
71
- ['no', 'n', 'N', 'NO'].each do |answer|
72
- file_test "ask user when file exist and do nothing when user says #{answer}" do
73
- provide_input(answer)
74
- FileRobot.create_file(output_path("abc.txt"), "abc")
75
- FileRobot.create_file(output_path("abc.txt"), "def")
76
- expect_output(
77
- " create #{output_dir}/abc.txt\n" +
78
- "overwrite #{output_dir}/abc.txt? (yes/no/all): " +
79
- " exist #{output_dir}/abc.txt\n"
80
- )
81
- assert_output_file_content "abc", "abc.txt"
82
- end
83
- end
84
-
85
- ['yes', 'y', 'YES', 'Yes', 'Y'].each do |answer|
86
- file_test "ask user when file exist and overwrite when user says #{answer}" do
87
- provide_input(answer)
88
- FileRobot.create_file(output_path("abc.txt"), "abc")
89
- FileRobot.create_file(output_path("abc.txt"), "def")
90
- expect_output(
91
- " create #{output_dir}/abc.txt\n" +
92
- "overwrite #{output_dir}/abc.txt? (yes/no/all): " +
93
- " overwrite #{output_dir}/abc.txt\n"
94
- )
95
- assert_output_file_content "def", "abc.txt"
96
- end
97
- end
98
-
99
- ['ye', 'non', 'Nevar', 'programming'].each do |answer|
100
- file_test "ask user when file exist and ask again when user says #{answer}" do
101
- provide_input(answer + "\nno")
102
- FileRobot.create_file(output_path("abc.txt"), "abc")
103
- FileRobot.create_file(output_path("abc.txt"), "def")
104
- expect_output(
105
- " create #{output_dir}/abc.txt\n" +
106
- "overwrite #{output_dir}/abc.txt? (yes/no/all): " +
107
- "overwrite #{output_dir}/abc.txt? (yes/no/all): " +
108
- " exist #{output_dir}/abc.txt\n"
109
- )
110
- assert_output_file_content "abc", "abc.txt"
111
- end
112
- end
113
-
114
- file_test "remove file" do
115
- FileRobot.create_file(output_path("abc.txt"), "abc")
116
- assert_output_file_exists("abc.txt")
117
- FileRobot.remove_file(output_path("abc.txt"))
118
- assert_output_file_not_exist("abc.txt")
119
- end
120
-
121
- file_test "write a message if file to remove does not exist" do
122
- FileRobot.remove_file(output_path("abc.txt"))
123
- expect_output(
124
- " not exist #{output_dir}/abc.txt\n"
125
- )
126
- end
127
-
128
- file_test "write a message if file to remove is not a file" do
129
- FileRobot.create_dir(output_path("abc.txt"))
130
- assert_output_file_exists("abc.txt")
131
- FileRobot.remove_file(output_path("abc.txt"))
132
- expect_output(
133
- " create #{output_dir}/abc.txt\n" +
134
- " not file #{output_dir}/abc.txt\n"
135
- )
136
- assert_output_file_exists("abc.txt")
137
- end
138
-
139
- file_test "remove dir" do
140
- FileRobot.create_dir(output_path("abc"))
141
- assert_output_file_exists("abc")
142
- FileRobot.remove_dir(output_path("abc"))
143
- assert_output_file_not_exist("abc")
144
- end
145
-
146
- file_test "write a message if dir to remove does not exist" do
147
- FileRobot.remove_file(output_path("abc"))
148
- expect_output(
149
- " not exist #{output_dir}/abc\n"
150
- )
151
- end
152
-
153
- file_test "write a message if dir to remove is not a dir" do
154
- FileRobot.create_file(output_path("abc"), "")
155
- assert_output_file_exists("abc")
156
- FileRobot.remove_dir(output_path("abc"))
157
- expect_output(
158
- " create #{output_dir}/abc\n" +
159
- " not dir #{output_dir}/abc\n"
160
- )
161
- assert_output_file_exists("abc")
162
- end
163
-
164
- file_test "write a message if dir to remove is not empty" do
165
- FileRobot.create_dir(output_path("abc"))
166
- FileRobot.create_file(output_path("abc/def.txt"), "")
167
- assert_output_file_exists('abc/def.txt')
168
- FileRobot.remove_dir(output_path("abc"))
169
- expect_output(
170
- " create #{output_dir}/abc\n" +
171
- " create #{output_dir}/abc/def.txt\n" +
172
- " not empty #{output_dir}/abc\n"
173
- )
174
- assert_output_file_exists("abc/def.txt")
175
- end
1
+ require File.dirname(__FILE__) + "/../../test_helpers"
2
+
3
+ class FileRobotTest < Test::Unit::TestCase
4
+ include Ritsu::Utility
5
+ include Ritsu::TestCaseWithFileTestData
6
+
7
+ def data_dir; File.dirname(__FILE__) + "/" + File.basename(__FILE__, ".rb") end
8
+
9
+ def setup
10
+ init_data_dir
11
+ @input = StringIO.new
12
+ @output = StringIO.new
13
+ FileRobot.input = @input
14
+ FileRobot.output = @output
15
+ end
16
+
17
+ def provide_input(string)
18
+ @input << string
19
+ @input.rewind
20
+ end
21
+
22
+ def expect_output(string)
23
+ assert_equal string, @output.string
24
+ end
25
+
26
+ must "force must be initially false" do
27
+ assert !FileRobot.force
28
+ end
29
+
30
+ must "quiet must be initially false" do
31
+ assert !FileRobot.quiet
32
+ end
33
+
34
+ file_test "create empty file" do
35
+ FileRobot.create_file(output_path("abc.txt"))
36
+ assert_output_file_exists "abc.txt"
37
+ assert_output_file_content "", "abc.txt"
38
+ expect_output(" create #{output_dir}/abc.txt\n")
39
+ end
40
+
41
+ file_test "create file with content" do
42
+ FileRobot.create_file(output_path("abc.txt"), "def")
43
+ assert_output_file_content "def", "abc.txt"
44
+ expect_output(" create #{output_dir}/abc.txt\n")
45
+ end
46
+
47
+ file_test "create parent directories when creating a file" do
48
+ FileRobot.create_file(output_path("a/b/c/def.txt"), "def")
49
+ assert_output_file_exists "a/b/c/def.txt"
50
+ expect_output(
51
+ " create #{output_dir}/a/b/c\n" +
52
+ " create #{output_dir}/a/b/c/def.txt\n"
53
+ )
54
+ end
55
+
56
+ file_test "create directory" do
57
+ FileRobot.create_dir(output_path("abc/def/ghi"))
58
+ assert_file_exists(output_path("abc/def/ghi"))
59
+ expect_output(" create #{output_dir}/abc/def/ghi\n")
60
+ end
61
+
62
+ file_test "display exist message when dir already exist" do
63
+ FileRobot.create_dir(output_path("abc"))
64
+ FileRobot.create_dir(output_path("abc"))
65
+ expect_output(
66
+ " create #{output_dir}/abc\n" +
67
+ " exist #{output_dir}/abc\n"
68
+ )
69
+ end
70
+
71
+ ['no', 'n', 'N', 'NO'].each do |answer|
72
+ file_test "ask user when file exist and do nothing when user says #{answer}" do
73
+ provide_input(answer)
74
+ FileRobot.create_file(output_path("abc.txt"), "abc")
75
+ FileRobot.create_file(output_path("abc.txt"), "def")
76
+ expect_output(
77
+ " create #{output_dir}/abc.txt\n" +
78
+ "overwrite #{output_dir}/abc.txt? (yes/no/all): " +
79
+ " exist #{output_dir}/abc.txt\n"
80
+ )
81
+ assert_output_file_content "abc", "abc.txt"
82
+ end
83
+ end
84
+
85
+ ['yes', 'y', 'YES', 'Yes', 'Y'].each do |answer|
86
+ file_test "ask user when file exist and overwrite when user says #{answer}" do
87
+ provide_input(answer)
88
+ FileRobot.create_file(output_path("abc.txt"), "abc")
89
+ FileRobot.create_file(output_path("abc.txt"), "def")
90
+ expect_output(
91
+ " create #{output_dir}/abc.txt\n" +
92
+ "overwrite #{output_dir}/abc.txt? (yes/no/all): " +
93
+ " overwrite #{output_dir}/abc.txt\n"
94
+ )
95
+ assert_output_file_content "def", "abc.txt"
96
+ end
97
+ end
98
+
99
+ ['ye', 'non', 'Nevar', 'programming'].each do |answer|
100
+ file_test "ask user when file exist and ask again when user says #{answer}" do
101
+ provide_input(answer + "\nno")
102
+ FileRobot.create_file(output_path("abc.txt"), "abc")
103
+ FileRobot.create_file(output_path("abc.txt"), "def")
104
+ expect_output(
105
+ " create #{output_dir}/abc.txt\n" +
106
+ "overwrite #{output_dir}/abc.txt? (yes/no/all): " +
107
+ "overwrite #{output_dir}/abc.txt? (yes/no/all): " +
108
+ " exist #{output_dir}/abc.txt\n"
109
+ )
110
+ assert_output_file_content "abc", "abc.txt"
111
+ end
112
+ end
113
+
114
+ file_test "remove file" do
115
+ FileRobot.create_file(output_path("abc.txt"), "abc")
116
+ assert_output_file_exists("abc.txt")
117
+ FileRobot.remove_file(output_path("abc.txt"))
118
+ assert_output_file_not_exist("abc.txt")
119
+ end
120
+
121
+ file_test "write a message if file to remove does not exist" do
122
+ FileRobot.remove_file(output_path("abc.txt"))
123
+ expect_output(
124
+ " not exist #{output_dir}/abc.txt\n"
125
+ )
126
+ end
127
+
128
+ file_test "write a message if file to remove is not a file" do
129
+ FileRobot.create_dir(output_path("abc.txt"))
130
+ assert_output_file_exists("abc.txt")
131
+ FileRobot.remove_file(output_path("abc.txt"))
132
+ expect_output(
133
+ " create #{output_dir}/abc.txt\n" +
134
+ " not file #{output_dir}/abc.txt\n"
135
+ )
136
+ assert_output_file_exists("abc.txt")
137
+ end
138
+
139
+ file_test "remove dir" do
140
+ FileRobot.create_dir(output_path("abc"))
141
+ assert_output_file_exists("abc")
142
+ FileRobot.remove_dir(output_path("abc"))
143
+ assert_output_file_not_exist("abc")
144
+ end
145
+
146
+ file_test "write a message if dir to remove does not exist" do
147
+ FileRobot.remove_file(output_path("abc"))
148
+ expect_output(
149
+ " not exist #{output_dir}/abc\n"
150
+ )
151
+ end
152
+
153
+ file_test "write a message if dir to remove is not a dir" do
154
+ FileRobot.create_file(output_path("abc"), "")
155
+ assert_output_file_exists("abc")
156
+ FileRobot.remove_dir(output_path("abc"))
157
+ expect_output(
158
+ " create #{output_dir}/abc\n" +
159
+ " not dir #{output_dir}/abc\n"
160
+ )
161
+ assert_output_file_exists("abc")
162
+ end
163
+
164
+ file_test "write a message if dir to remove is not empty" do
165
+ FileRobot.create_dir(output_path("abc"))
166
+ FileRobot.create_file(output_path("abc/def.txt"), "")
167
+ assert_output_file_exists('abc/def.txt')
168
+ FileRobot.remove_dir(output_path("abc"))
169
+ expect_output(
170
+ " create #{output_dir}/abc\n" +
171
+ " create #{output_dir}/abc/def.txt\n" +
172
+ " not empty #{output_dir}/abc\n"
173
+ )
174
+ assert_output_file_exists("abc/def.txt")
175
+ end
176
176
  end