rcodetools 0.7.0.0 → 0.8.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.
Files changed (83) hide show
  1. data/CHANGES +12 -0
  2. data/README +1 -1
  3. data/README.emacs +21 -4
  4. data/README.ja +1 -1
  5. data/README.xmpfilter +159 -74
  6. data/Rakefile +3 -37
  7. data/anything-rcodetools.el +142 -0
  8. data/bin/rct-complete +1 -1
  9. data/bin/rct-doc +1 -1
  10. data/bin/rct-meth-args +33 -2
  11. data/bin/xmpfilter +5 -1
  12. data/lib/rcodetools/compat.rb +14 -0
  13. data/lib/rcodetools/completion.rb +8 -6
  14. data/lib/rcodetools/fork.rb +15 -8
  15. data/lib/rcodetools/options.rb +8 -0
  16. data/lib/rcodetools/xmpfilter.rb +80 -33
  17. data/lib/rcodetools/xmptestunitfilter.rb +76 -21
  18. data/lib/ruby_toggle_file.rb +1 -1
  19. data/rcodetools.el +213 -20
  20. data/test/test_functional.rb +36 -68
  21. data/test/test_method_analyzer.rb +28 -20
  22. data/test/test_ruby_toggle_file.rb +118 -69
  23. data/test/test_xmpfilter.rb +75 -47
  24. data/test/test_xmptestunitfilter.rb +12 -11
  25. metadata +83 -133
  26. data/test/data/add_markers-input.rb +0 -2
  27. data/test/data/add_markers-output.rb +0 -2
  28. data/test/data/bindings-input.rb +0 -26
  29. data/test/data/bindings-output.rb +0 -31
  30. data/test/data/completion-input.rb +0 -1
  31. data/test/data/completion-output.rb +0 -2
  32. data/test/data/completion_class_info-input.rb +0 -1
  33. data/test/data/completion_class_info-output.rb +0 -10
  34. data/test/data/completion_class_info_no_candidates-input.rb +0 -1
  35. data/test/data/completion_class_info_no_candidates-output.rb +0 -1
  36. data/test/data/completion_detect_rbtest-input.rb +0 -7
  37. data/test/data/completion_detect_rbtest-output.rb +0 -2
  38. data/test/data/completion_detect_rbtest2-input.rb +0 -1
  39. data/test/data/completion_detect_rbtest2-output.rb +0 -2
  40. data/test/data/completion_emacs-input.rb +0 -1
  41. data/test/data/completion_emacs-output.rb +0 -6
  42. data/test/data/completion_emacs_icicles-input.rb +0 -1
  43. data/test/data/completion_emacs_icicles-output.rb +0 -6
  44. data/test/data/completion_in_method-input.rb +0 -3
  45. data/test/data/completion_in_method-output.rb +0 -1
  46. data/test/data/completion_in_method-test.rb +0 -6
  47. data/test/data/completion_rbtest-input.rb +0 -7
  48. data/test/data/completion_rbtest-output.rb +0 -2
  49. data/test/data/doc-input.rb +0 -1
  50. data/test/data/doc-output.rb +0 -1
  51. data/test/data/doc_detect_rbtest-input.rb +0 -1
  52. data/test/data/doc_detect_rbtest-output.rb +0 -1
  53. data/test/data/doc_detect_rbtest2-input.rb +0 -7
  54. data/test/data/doc_detect_rbtest2-output.rb +0 -1
  55. data/test/data/doc_rbtest-input.rb +0 -7
  56. data/test/data/doc_rbtest-output.rb +0 -1
  57. data/test/data/no_warnings-input.rb +0 -3
  58. data/test/data/no_warnings-output.rb +0 -4
  59. data/test/data/refe-input.rb +0 -1
  60. data/test/data/refe-output.rb +0 -1
  61. data/test/data/ri-input.rb +0 -1
  62. data/test/data/ri-output.rb +0 -1
  63. data/test/data/ri_emacs-input.rb +0 -1
  64. data/test/data/ri_emacs-output.rb +0 -1
  65. data/test/data/ri_vim-input.rb +0 -1
  66. data/test/data/ri_vim-output.rb +0 -1
  67. data/test/data/rspec-input.rb +0 -48
  68. data/test/data/rspec-output.rb +0 -52
  69. data/test/data/rspec_poetry-input.rb +0 -48
  70. data/test/data/rspec_poetry-output.rb +0 -52
  71. data/test/data/simple_annotation-input.rb +0 -8
  72. data/test/data/simple_annotation-output.rb +0 -8
  73. data/test/data/unit_test-input.rb +0 -50
  74. data/test/data/unit_test-output.rb +0 -52
  75. data/test/data/unit_test_detect_rbtest-input.rb +0 -50
  76. data/test/data/unit_test_detect_rbtest-output.rb +0 -52
  77. data/test/data/unit_test_detect_rbtest2-input.rb +0 -6
  78. data/test/data/unit_test_detect_rbtest2-output.rb +0 -6
  79. data/test/data/unit_test_poetry-input.rb +0 -50
  80. data/test/data/unit_test_poetry-output.rb +0 -52
  81. data/test/data/unit_test_rbtest-input.rb +0 -6
  82. data/test/data/unit_test_rbtest-output.rb +0 -6
  83. data/test/test_run.rb +0 -45
@@ -1,79 +1,47 @@
1
1
  require 'test/unit'
2
-
3
- module TestFunctional
4
- DIR = File.expand_path(File.dirname(__FILE__))
5
- LIBDIR = File.expand_path(DIR + '/../lib')
6
-
7
- module DefineFunctionalTests
8
- def define_functional_tests(exec, tests)
9
- tests.each_pair do |test, opts|
10
- define_method("test_#{test}") do
11
-
12
- output = `ruby -I#{LIBDIR} #{exec} #{opts.join(" ")} #{DIR}/data/#{test}-input.rb`
13
- outputfile = "#{DIR}/data/#{test}-output.rb"
14
- assert_equal(File.read(outputfile), output)
15
- end
16
- end
2
+ require 'tempfile'
3
+ class TestFunctional < Test::Unit::TestCase
4
+ def self.parse_taf(filename)
5
+ open(filename) do |io|
6
+ delimiter=Regexp.union(io.gets)
7
+ io.read.split(delimiter)
17
8
  end
18
9
  end
19
10
 
20
- class TestXmpfilter < Test::Unit::TestCase
21
- extend DefineFunctionalTests
22
- tests = {
23
- :simple_annotation => [], :unit_test => ["-u"], :rspec => ["-s"],
24
- :no_warnings => ["--no-warnings"], :bindings => ["--poetry", "-u"],
25
- :add_markers => ["-m"], :unit_test_rbtest => ["-u", "--rbtest"],
26
- :unit_test_detect_rbtest => ["-u", "--detect-rbtest"],
27
- :unit_test_detect_rbtest2 => ["--detect-rbtest"],
28
- }
29
- define_functional_tests File.expand_path(DIR + '/../bin/xmpfilter'), tests
30
- end
31
-
32
- class TestRctComplete < Test::Unit::TestCase
33
- extend DefineFunctionalTests
34
- tests = {
35
- :completion_rbtest => [ "--rbtest", "--line=6" ],
36
- :completion_detect_rbtest => [ "--detect-rbtest", "--line=6" ],
37
- :completion_detect_rbtest2 => [ "--detect-rbtest", "--line=1" ],
38
- }
39
- define_functional_tests File.expand_path(DIR + '/../bin/rct-complete'), tests
40
- end
41
-
42
- class TestRctDoc < Test::Unit::TestCase
43
- extend DefineFunctionalTests
44
- tests = {
45
- :doc_rbtest => [ "--rbtest", "--line=6" ],
46
- :doc_detect_rbtest => [ "--detect-rbtest", "--line=1" ],
47
- :doc_detect_rbtest2 => [ "--detect-rbtest", "--line=6" ],
48
- }
49
- define_functional_tests File.expand_path(DIR + '/../bin/rct-doc'), tests
11
+ def tempfile_with_contents(contents)
12
+ input = Tempfile.new("rct-test")
13
+ input.write(contents)
14
+ input.close
15
+ input.path
50
16
  end
51
17
 
18
+ DIR = File.expand_path(File.dirname(__FILE__))
19
+ LIBDIR = File.expand_path(DIR + '/../lib')
20
+ BINDIR = File.expand_path(DIR + '/../bin')
52
21
 
53
- # Other tests are in test_run.rb
54
- class TestRctCompleteTDC < Test::Unit::TestCase
55
- test = :completion_in_method
56
- inputfile = "#{DIR}/data/#{test}-input.rb"
57
- outputfile = "#{DIR}/data/#{test}-output.rb"
58
- test_script = "#{DIR}/data/#{test}-test.rb"
59
- common_opts = ["--filename #{inputfile}", "--line 2"]
60
- right_output = File.read(outputfile)
61
- wrong_output = "\n"
62
-
63
- tests = {
64
- :completion_in_method__testscript =>
65
- [ common_opts + ["-t #{test_script}"], right_output ],
66
- :completion_in_method__testmethod =>
67
- [ common_opts + ["-t #{test_script}@test_fooz"], right_output ],
68
- :completion_in_method__wrong_testmethod =>
69
- [ common_opts + ["-t #{test_script}@test_NOT_FOUND"], wrong_output ],
70
- }
71
- exec = File.expand_path(DIR + '/../bin/rct-complete')
72
- tests.each_pair do |test, (opts, expected)|
73
- define_method("test_#{test}") do
74
- output = `ruby -I#{LIBDIR} #{exec} #{opts.join(" ")} #{inputfile}`
75
- assert_equal(expected, output)
22
+ # rct-complete-TDC
23
+ %w[xmpfilter rct-complete rct-doc].each do |subdir|
24
+ Dir["#{DIR}/data/#{subdir}/*.taf"].each do |taf|
25
+ desc, cmdline, input, output = parse_taf(taf)
26
+ [desc, cmdline].each{|x| x.chomp! }
27
+ define_method("test_#{desc}") do
28
+ inputfile = tempfile_with_contents(input)
29
+ actual_output = `ruby -I#{LIBDIR} #{BINDIR}/#{cmdline} #{inputfile}`
30
+ assert_equal output, actual_output
76
31
  end
77
32
  end
78
33
  end
34
+
35
+ # TODO
36
+ Dir["#{DIR}/data/rct-complete-TDC/*.taf"].each do |taf|
37
+ desc, cmdline, input, output, test = parse_taf(taf)
38
+ [desc, cmdline].each{|x| x.chomp! }
39
+ define_method("test_#{desc}") do
40
+ inputfile = tempfile_with_contents(input)
41
+ testfile = tempfile_with_contents(test)
42
+ actual_output = `ruby -I#{LIBDIR} #{BINDIR}/#{cmdline % [inputfile, testfile]} #{inputfile}`
43
+ assert_equal output, actual_output
44
+ end
45
+ end
46
+
79
47
  end
@@ -9,7 +9,7 @@ end
9
9
  class MethodAnalyzerTextOutput < Test::Unit::TestCase
10
10
  include ScriptConfig
11
11
 
12
- # test (find-sh "ruby -r../method_analyzer data/method_analyzer-data.rb")
12
+ # test (find-sh "ruby -r../method_analyzer data/method_analyzer-data.rb")
13
13
 
14
14
  # attr_accessor is actually Module#attr_accessor.
15
15
  # But `f?ri Module.attr_accessor' answers correctly.
@@ -68,17 +68,6 @@ class MethodAnalyzerMarshalOutput < Test::Unit::TestCase
68
68
  METHOD_ANALYSIS = File.join(DIR, "method_analysis")
69
69
  at_exit { File.unlink METHOD_ANALYSIS rescue nil}
70
70
 
71
- def setup
72
- ENV['METHOD_ANALYZER_FORMAT'] = 'marshal'
73
- @pwd = Dir.pwd
74
- Dir.chdir DIR
75
- end
76
-
77
- def teardown
78
- ENV['METHOD_ANALYZER_FORMAT'] = nil
79
- Dir.chdir @pwd
80
- end
81
-
82
71
  def write_temp_file(str, file)
83
72
  file.replace File.expand_path(file)
84
73
  at_exit { File.unlink file }
@@ -86,14 +75,33 @@ class MethodAnalyzerMarshalOutput < Test::Unit::TestCase
86
75
  end
87
76
 
88
77
  def test_marshal_merged
89
- a = write_temp_file "z=1+2", "mergeA.rb"
90
- b = write_temp_file "[].empty?", "mergeB.rb"
91
-
92
- system "ruby -r#{SCRIPT} mergeA.rb"
93
- system "ruby -r#{SCRIPT} mergeB.rb"
78
+ begin
79
+ ENV['METHOD_ANALYZER_FORMAT'] = 'marshal'
80
+ @pwd = Dir.pwd
81
+ Dir.chdir DIR
82
+ a = write_temp_file "z=1+2", "mergeA.rb"
83
+ system "ruby -r#{SCRIPT} mergeA.rb"
84
+ method_analysis = Marshal.load(File.read(METHOD_ANALYSIS))
85
+ assert_equal ["Fixnum#+"], method_analysis[File.join(DIR, "mergeA.rb")][1]
86
+ ensure
87
+ ENV.delete 'METHOD_ANALYZER_FORMAT'
88
+ Dir.chdir @pwd
89
+ end
90
+ end
94
91
 
95
- method_analysis = Marshal.load(File.read(METHOD_ANALYSIS))
96
- assert_equal ["Fixnum#+"], method_analysis[File.join(DIR, "mergeA.rb")][1]
97
- assert_equal ["Array#empty?"], method_analysis[File.join(DIR, "mergeB.rb")][1]
92
+ def test_marshal_merged
93
+ begin
94
+ ENV['METHOD_ANALYZER_FORMAT'] = 'marshal'
95
+ @pwd = Dir.pwd
96
+ Dir.chdir DIR
97
+
98
+ b = write_temp_file "[].empty?", "mergeB.rb"
99
+ system "ruby -r#{SCRIPT} mergeB.rb"
100
+ method_analysis = Marshal.load(File.read(METHOD_ANALYSIS))
101
+ assert_equal ["Array#empty?"], method_analysis[File.join(DIR, "mergeB.rb")][1]
102
+ ensure
103
+ ENV.delete 'METHOD_ANALYZER_FORMAT'
104
+ Dir.chdir @pwd
105
+ end
98
106
  end
99
107
  end
@@ -7,105 +7,148 @@ class TestRubyToggleFile < Test::Unit::TestCase
7
7
  WORK_DIR = "#{Dir.tmpdir}/zdsfwfwejiotest".freeze
8
8
  FileUtils.rm_rf WORK_DIR
9
9
 
10
- FILE_MAP = {
11
- :zero => %w[lib/zero.rb test/test_zero.rb],
12
- :one => %w[lib/one/one.rb test/one/test_one.rb],
13
- :two => %w[lib/two/two.rb test/test_two.rb],
14
- :three => %w[three.rb test_three.rb],
15
- :four => %w[four.rb],
16
- :five => %w[lib/five.rb],
17
- :six => %w[lib/six/six/six.rb],
18
- :seven => %w[ test_seven.rb],
19
- :eight => %w[ test/test_eight.rb],
20
- :nine => %w[ test/nine/nine/nine.rb],
21
-
22
- # Rails
23
- :rcontrollers => %w[app/controllers/c.rb test/functional/c_test.rb],
24
- :rmodels => %w[app/models/m.rb test/unit/m_test.rb],
25
- :rlib => %w[lib/l.rb test/unit/test_l.rb app/models/m.rb],
26
- }
27
-
28
- def use_file_map(key, &block)
29
- Dir.mkdir(WORK_DIR)
30
- Dir.chdir(WORK_DIR) do
31
- FILE_MAP[key].each do |file|
32
- FileUtils.mkpath(File.dirname(file))
33
- open(file, "w"){}
34
- end
35
- end
10
+ def teardown
11
+ FileUtils.rm_rf WORK_DIR
12
+ end
36
13
 
37
- begin
38
- yield
39
- ensure
40
- FileUtils.rm_rf WORK_DIR
14
+ def create(*files)
15
+ for file in files.map{|f| _(f) }
16
+ FileUtils.mkpath(File.dirname(file))
17
+ open(file,"w"){}
41
18
  end
42
19
  end
43
20
 
44
- def setup
45
- @x = RubyToggleFile.new
21
+ def _(path) # make full path
22
+ WORK_DIR + "/" + path
46
23
  end
47
24
 
48
- def _(path)
49
- WORK_DIR + "/" + path
25
+ ###########################################################################
26
+ # naming convention #
27
+ # test_METHOD__EXISTP__IMPLEMENTDIR_TESTDIR #
28
+ ###########################################################################
29
+ def test_test_file__exist__lib_test
30
+ create "lib/zero.rb", "test/test_zero.rb"
31
+ rtf = RubyToggleFile.new
32
+ assert_equal _("test/test_zero.rb"), rtf.ruby_toggle_file(_("lib/zero.rb"))
50
33
  end
51
34
 
52
- def check(after, before)
53
- assert_equal _(after), @x.ruby_toggle_file(_(before))
35
+ def test_test_file__exist__libone_testone
36
+ create "lib/one/one.rb", "test/one/test_one.rb"
37
+ rtf = RubyToggleFile.new
38
+ assert_equal _("test/one/test_one.rb"), rtf.ruby_toggle_file(_("lib/one/one.rb"))
54
39
  end
55
40
 
56
- def test_test_file_file_exist
57
- use_file_map(:zero) { check "test/test_zero.rb", "lib/zero.rb" }
58
- use_file_map(:one) { check "test/one/test_one.rb", "lib/one/one.rb" }
59
- use_file_map(:two) { check "test/test_two.rb", "lib/two/two.rb" }
60
- use_file_map(:three) { check "test_three.rb", "three.rb" }
61
- end
41
+ def test_test_file__exist__libtwo_test
42
+ create "lib/two/two.rb", "test/test_two.rb"
43
+ rtf = RubyToggleFile.new
44
+ assert_equal _("test/test_two.rb"), rtf.ruby_toggle_file(_("lib/two/two.rb"))
45
+ end
46
+
47
+ def test_test_file__exist__top_test
48
+ create "three.rb", "test_three.rb"
49
+ rtf = RubyToggleFile.new
50
+ assert_equal _("test_three.rb"), rtf.ruby_toggle_file(_("three.rb"))
51
+ end
52
+
53
+ def test_test_file__not_exist__top
54
+ create "four.rb"
55
+ rtf = RubyToggleFile.new
56
+ assert_equal _("test_four.rb"), rtf.ruby_toggle_file(_("four.rb"))
57
+ end
58
+
59
+ def test_test_file__not_exist__lib
60
+ create "lib/five.rb"
61
+ rtf = RubyToggleFile.new
62
+ assert_equal _("test/test_five.rb"), rtf.ruby_toggle_file(_("lib/five.rb"))
63
+ end
62
64
 
63
- def test_test_file_file_not_exist
64
- use_file_map(:four) { check "test_four.rb", "four.rb" }
65
- use_file_map(:five) { check "test/test_five.rb", "lib/five.rb" }
66
- use_file_map(:six) { check "test/six/six/test_six.rb", "lib/six/six/six.rb" }
65
+ def test_test_file__not_exist__libsixsix
66
+ create "lib/six/six/six.rb"
67
+ rtf = RubyToggleFile.new
68
+ assert_equal _("test/six/six/test_six.rb"), rtf.ruby_toggle_file(_("lib/six/six/six.rb"))
67
69
  end
68
70
 
69
- def test_implementation_file_file_exist
70
- use_file_map(:zero) { check "lib/zero.rb", "test/test_zero.rb" }
71
- use_file_map(:one) { check "lib/one/one.rb", "test/one/test_one.rb" }
72
- use_file_map(:two) { check "lib/two/two.rb", "test/test_two.rb" }
73
- use_file_map(:three) { check "three.rb", "test_three.rb" }
71
+ def test_implementation_file__exist__lib_test
72
+ create "lib/zero.rb", "test/test_zero.rb"
73
+ rtf = RubyToggleFile.new
74
+ assert_equal _("lib/zero.rb"), rtf.ruby_toggle_file(_("test/test_zero.rb"))
74
75
  end
75
76
 
76
- def test_implementation_file_file_not_exist
77
- use_file_map(:seven) { check "seven.rb", "test_seven.rb" }
78
- use_file_map(:eight) { check "lib/eight.rb", "test/test_eight.rb" }
79
- use_file_map(:nine) { check "lib/nine/nine/nine.rb", "test/nine/nine/test_nine.rb" }
77
+ def test_implementation_file__exist__libone_testone
78
+ create "lib/one/one.rb", "test/one/test_one.rb"
79
+ rtf = RubyToggleFile.new
80
+ assert_equal _("lib/one/one.rb"), rtf.ruby_toggle_file(_("test/one/test_one.rb"))
80
81
  end
81
82
 
82
- # Rails test
83
- def test_test_file_rails_controllers
84
- use_file_map(:rcontrollers) { check "test/functional/c_test.rb", "app/controllers/c.rb" }
83
+ def test_implementation_file__exist__libtwo_test
84
+ create "lib/two/two.rb", "test/test_two.rb"
85
+ rtf = RubyToggleFile.new
86
+ assert_equal _("lib/two/two.rb"), rtf.ruby_toggle_file(_("test/test_two.rb"))
85
87
  end
86
88
 
87
- def test_test_file_rails_models
88
- use_file_map(:rmodels) { check "test/unit/m_test.rb", "app/models/m.rb" }
89
+ def test_implementation_file__exist__top_test
90
+ create "three.rb", "test_three.rb"
91
+ rtf = RubyToggleFile.new
92
+ assert_equal _("three.rb"), rtf.ruby_toggle_file(_("test_three.rb"))
89
93
  end
90
94
 
91
- def test_test_file_rails_lib
92
- use_file_map(:rlib) { check "test/unit/test_l.rb", "lib/l.rb" }
95
+ def test_implementation_file__not_exist__none_top
96
+ create "test_seven.rb"
97
+ rtf = RubyToggleFile.new
98
+ assert_equal _("seven.rb"), rtf.ruby_toggle_file(_("test_seven.rb"))
93
99
  end
94
100
 
101
+ def test_implementation_file__not_exist__none_test
102
+ create "test/test_eight.rb"
103
+ rtf = RubyToggleFile.new
104
+ assert_equal _("lib/eight.rb"), rtf.ruby_toggle_file(_("test/test_eight.rb"))
105
+ end
106
+
107
+ def test_implementation_file__not_exist__none_testninenine
108
+ create "test/nine/nine/nine.rb"
109
+ rtf = RubyToggleFile.new
110
+ assert_equal _("lib/nine/nine/nine.rb"), rtf.ruby_toggle_file(_("test/nine/nine/test_nine.rb"))
111
+ end
95
112
 
96
- def test_implementation_file_rails_controllers
97
- use_file_map(:rcontrollers) { check "app/controllers/c.rb", "test/functional/c_test.rb" }
113
+ ###########################################################################
114
+ # Rails test #
115
+ ###########################################################################
116
+ def test_test_file__rails_controllers
117
+ create "app/controllers/c.rb", "test/functional/c_test.rb"
118
+ rtf = RubyToggleFile.new
119
+ assert_equal _("test/functional/c_test.rb"), rtf.ruby_toggle_file(_("app/controllers/c.rb"))
98
120
  end
99
121
 
100
- def test_implementation_file_rails_models
101
- use_file_map(:rmodels) { check "app/models/m.rb", "test/unit/m_test.rb" }
122
+ def test_test_file__rails_models
123
+ create "app/models/m.rb", "test/unit/m_test.rb"
124
+ rtf = RubyToggleFile.new
125
+ assert_equal _("test/unit/m_test.rb"), rtf.ruby_toggle_file(_("app/models/m.rb"))
102
126
  end
103
127
 
104
- def test_implementation_file_rails_lib
105
- use_file_map(:rlib) { check "lib/l.rb", "test/unit/test_l.rb" }
128
+ def test_test_file__rails_lib
129
+ create "lib/l.rb", "test/unit/test_l.rb", "app/models/m.rb"
130
+ rtf = RubyToggleFile.new
131
+ assert_equal _("test/unit/test_l.rb"), rtf.ruby_toggle_file(_("lib/l.rb"))
132
+ end
133
+
134
+
135
+ def test_implementation_file__rails_controllers
136
+ create "app/controllers/c.rb", "test/functional/c_test.rb"
137
+ rtf = RubyToggleFile.new
138
+ assert_equal _("app/controllers/c.rb"), rtf.ruby_toggle_file(_("test/functional/c_test.rb"))
106
139
  end
107
140
 
141
+ def test_implementation_file__rails_models
142
+ create "app/models/m.rb", "test/unit/m_test.rb"
143
+ rtf = RubyToggleFile.new
144
+ assert_equal _("app/models/m.rb"), rtf.ruby_toggle_file(_("test/unit/m_test.rb"))
145
+ end
108
146
 
147
+ def test_implementation_file__rails_lib
148
+ create "lib/l.rb", "test/unit/test_l.rb", "app/models/m.rb"
149
+ rtf = RubyToggleFile.new
150
+ assert_equal _("lib/l.rb"), rtf.ruby_toggle_file(_("test/unit/test_l.rb"))
151
+ end
109
152
  end
110
153
 
111
154
 
@@ -117,9 +160,15 @@ class TestRunHooksWithArgsUntilSuccess < Test::Unit::TestCase
117
160
  def m004(x) 200 end
118
161
 
119
162
  public
120
- def test_run_hooks_with_args_until_success
163
+ def test_run_hooks_with_args_until_success__m003
121
164
  assert_equal 1000, run_hooks_with_args_until_success(/^m\d+$/, 10)
165
+ end
166
+
167
+ def test_run_hooks_with_args_until_success__m001
122
168
  assert_nil run_hooks_with_args_until_success(/^m001$/, 10)
169
+ end
170
+
171
+ def test_run_hooks_with_args_until_success__m004
123
172
  assert_equal 200, run_hooks_with_args_until_success(/^m004$/, 10)
124
173
  end
125
174
  end
@@ -2,29 +2,56 @@
2
2
  require 'test/unit'
3
3
  $: << ".." << "../lib"
4
4
  require "rcodetools/xmpfilter"
5
+ require 'rubygems'
6
+ require 'mocha'
5
7
 
6
8
  class TestXMPFilter < Test::Unit::TestCase
7
9
  include Rcodetools
8
- def setup
9
- @xmp = XMPFilter.new
10
- @marker = XMPFilter::MARKER
11
- @testdir = File.dirname(__FILE__)
10
+ def test_extract_data__results
11
+ marker = XMPFilter::MARKER
12
+ str = <<-EOF
13
+ #{marker}[1] => Fixnum 42
14
+ #{marker}[1] => Fixnum 0
15
+ #{marker}[1] ==> var
16
+ #{marker}[1] ==> var2
17
+ #{marker}[4] ==> var3
18
+ #{marker}[2] ~> some exception
19
+ #{marker}[10] => Fixnum 42
20
+ EOF
21
+ xmp = XMPFilter.new
22
+ data = xmp.extract_data(str)
23
+ assert_equal([[1, [["Fixnum", "42"], ["Fixnum", "0"]]], [10, [["Fixnum", "42"]]]], data.results.sort)
12
24
  end
13
25
 
14
- def test_extract_data
26
+ def test_extract_data__exceptions
27
+ marker = XMPFilter::MARKER
15
28
  str = <<-EOF
16
- #{@marker}[1] => Fixnum 42
17
- #{@marker}[1] => Fixnum 0
18
- #{@marker}[1] ==> var
19
- #{@marker}[1] ==> var2
20
- #{@marker}[4] ==> var3
21
- #{@marker}[2] ~> some exception
22
- #{@marker}[10] => Fixnum 42
29
+ #{marker}[1] => Fixnum 42
30
+ #{marker}[1] => Fixnum 0
31
+ #{marker}[1] ==> var
32
+ #{marker}[1] ==> var2
33
+ #{marker}[4] ==> var3
34
+ #{marker}[2] ~> some exception
35
+ #{marker}[10] => Fixnum 42
23
36
  EOF
24
- data = @xmp.extract_data(str)
25
- assert_kind_of(XMPFilter::RuntimeData, data)
26
- assert_equal([[1, [["Fixnum", "42"], ["Fixnum", "0"]]], [10, [["Fixnum", "42"]]]], data.results.sort)
37
+ xmp = XMPFilter.new
38
+ data = xmp.extract_data(str)
27
39
  assert_equal([[2, ["some exception"]]], data.exceptions.sort)
40
+ end
41
+
42
+ def test_extract_data__bindings
43
+ marker = XMPFilter::MARKER
44
+ str = <<-EOF
45
+ #{marker}[1] => Fixnum 42
46
+ #{marker}[1] => Fixnum 0
47
+ #{marker}[1] ==> var
48
+ #{marker}[1] ==> var2
49
+ #{marker}[4] ==> var3
50
+ #{marker}[2] ~> some exception
51
+ #{marker}[10] => Fixnum 42
52
+ EOF
53
+ xmp = XMPFilter.new
54
+ data = xmp.extract_data(str)
28
55
  assert_equal([[1, ["var", "var2"]], [4, ["var3"]]], data.bindings.sort)
29
56
  end
30
57
 
@@ -34,13 +61,9 @@ class TestXMPFilter < Test::Unit::TestCase
34
61
  end
35
62
 
36
63
  def test_interpreter_command_detect_rct_fork
37
- begin
38
- def Fork::run?() true end
39
- xmp = XMPFilter.new(:interpreter=>"ruby", :detect_rct_fork => true)
40
- assert_equal(%w[ruby -S rct-fork-client], xmp.interpreter_command)
41
- ensure
42
- def Fork::run?() false end
43
- end
64
+ Fork.stubs(:run?).returns true
65
+ xmp = XMPFilter.new(:interpreter=>"ruby", :detect_rct_fork => true)
66
+ assert_equal(%w[ruby -S rct-fork-client], xmp.interpreter_command)
44
67
  end
45
68
 
46
69
  def test_interpreter_command_use_rbtest
@@ -49,7 +72,8 @@ class TestXMPFilter < Test::Unit::TestCase
49
72
  end
50
73
 
51
74
  def test_initialize__test_script_1
52
- @xmp = XMPFilter.new(:test_script=>"/path/to/test/test_ruby_toggle_file.rb",
75
+ XMPFilter.any_instance.stubs(:safe_require_code).returns("require 'test/unit'")
76
+ xmp = XMPFilter.new(:test_script=>"/path/to/test/test_ruby_toggle_file.rb",
53
77
  :test_method=>"test_implementation_file_file_exist",
54
78
  :filename=>"/path/to/lib/ruby_toggle_file.rb")
55
79
 
@@ -59,11 +83,12 @@ class TestXMPFilter < Test::Unit::TestCase
59
83
  %q!load "/path/to/test/test_ruby_toggle_file.rb"!,
60
84
  %q!Test::Unit::AutoRunner.run(false, nil, ["-n", "test_implementation_file_file_exist"])!
61
85
  ]
62
- assert_equal evals_expected, @xmp.instance_variable_get(:@evals)
86
+ assert_equal evals_expected, xmp.instance_variable_get(:@evals)
63
87
  end
64
88
 
65
89
  def test_initialize__test_script_2
66
- @xmp = XMPFilter.new(:test_script=>"/path/to/test_ruby_toggle_file.rb",
90
+ XMPFilter.any_instance.stubs(:safe_require_code).returns("require 'test/unit'")
91
+ xmp = XMPFilter.new(:test_script=>"/path/to/test_ruby_toggle_file.rb",
67
92
  :test_method=>"test_implementation_file_file_exist",
68
93
  :filename=>"/path/to/ruby_toggle_file.rb")
69
94
 
@@ -73,13 +98,14 @@ class TestXMPFilter < Test::Unit::TestCase
73
98
  %q!load "/path/to/test_ruby_toggle_file.rb"!,
74
99
  %q!Test::Unit::AutoRunner.run(false, nil, ["-n", "test_implementation_file_file_exist"])!
75
100
  ]
76
- assert_equal evals_expected, @xmp.instance_variable_get(:@evals)
101
+ assert_equal evals_expected, xmp.instance_variable_get(:@evals)
77
102
  end
78
103
 
79
104
  def test_initialize__test_script_3
80
- test_script = File.join(@testdir, "data/sample_test_script.rb")
81
- filename = File.join(@testdir, "data/sample.rb")
82
- @xmp = XMPFilter.new(:test_script=>test_script, :test_method=>"4", :filename=>filename)
105
+ test_script = File.join(File.dirname(__FILE__), "data/sample_test_script.rb")
106
+ filename = File.join(File.dirname(__FILE__), "data/sample.rb")
107
+ XMPFilter.any_instance.stubs(:safe_require_code).returns("require 'test/unit'")
108
+ xmp = XMPFilter.new(:test_script=>test_script, :test_method=>"4", :filename=>filename)
83
109
 
84
110
  evals_expected = [
85
111
  %q!$LOADED_FEATURES << "sample.rb"!,
@@ -87,33 +113,34 @@ class TestXMPFilter < Test::Unit::TestCase
87
113
  %Q!load #{test_script.dump}!,
88
114
  %q!Test::Unit::AutoRunner.run(false, nil, ["-n", "test_sample0"])!
89
115
  ]
90
- assert_equal evals_expected, @xmp.instance_variable_get(:@evals)
116
+ assert_equal evals_expected, xmp.instance_variable_get(:@evals)
91
117
  end
92
118
 
93
119
  def test_initialize__test_script__filename_eq_test_script
94
- test_script = File.join(@testdir, "data/sample_test_script.rb")
120
+ test_script = File.join(File.dirname(__FILE__), "data/sample_test_script.rb")
95
121
  filename = test_script
96
- @xmp = XMPFilter.new(:test_script=>test_script, :test_method=>"4", :filename=>filename)
122
+ xmp = XMPFilter.new(:test_script=>test_script, :test_method=>"4", :filename=>filename)
97
123
 
98
124
  evals_expected = [
99
125
  %q!Test::Unit::AutoRunner.run(false, nil, ["-n", "test_sample0"])!
100
126
  ]
101
- assert_equal evals_expected, @xmp.instance_variable_get(:@evals)
127
+ assert_equal evals_expected, xmp.instance_variable_get(:@evals)
102
128
  end
103
129
 
104
130
  def test_get_test_method_from_lineno
105
- file = File.join(@testdir, "data/sample_test_script.rb")
106
- assert_equal("test_sample0", @xmp.get_test_method_from_lineno(file, 4))
107
- assert_equal("test_sample1", @xmp.get_test_method_from_lineno(file, 7))
108
- assert_equal("test_sample1", @xmp.get_test_method_from_lineno(file, 8))
109
- assert_equal(nil, @xmp.get_test_method_from_lineno(file, 1))
131
+ file = File.join(File.dirname(__FILE__), "data/sample_test_script.rb")
132
+ xmp = XMPFilter.new
133
+ assert_equal("test_sample0", xmp.get_test_method_from_lineno(file, 4))
134
+ assert_equal("test_sample1", xmp.get_test_method_from_lineno(file, 7))
135
+ assert_equal("test_sample1", xmp.get_test_method_from_lineno(file, 8))
136
+ assert_equal(nil, xmp.get_test_method_from_lineno(file, 1))
110
137
  end
111
138
 
112
- def test_s_detect_rbtest
113
- # Use variable to avoid confusing syntax highlighting
114
- beg = "=begin"
115
- ed = "=end"
116
-
139
+ # Use methods to avoid confusing syntax highlighting
140
+ def beg() "=begin" end
141
+ def ed() "=end" end
142
+
143
+ def test_s_detect_rbtest_1
117
144
  rbtest_script_1 = <<XXX
118
145
  #{beg} test_0
119
146
  assert f(10)
@@ -130,9 +157,9 @@ XXX
130
157
  opts = {:detect_rbtest => false, :use_rbtest => true}
131
158
  assert_equal true, XMPFilter.detect_rbtest(rbtest_script_1, opts)
132
159
  assert_equal true, opts[:use_rbtest]
160
+ end
133
161
 
134
-
135
-
162
+ def test_s_detect_rbtest_2
136
163
  rbtest_script_2 = <<XXX
137
164
  def f(x) x*100 end
138
165
  #{beg} test_0
@@ -145,8 +172,9 @@ XXX
145
172
  opts = {:detect_rbtest => false}
146
173
  assert_equal false, XMPFilter.detect_rbtest(rbtest_script_2, opts)
147
174
  assert_equal false, opts[:use_rbtest]
148
-
149
-
175
+ end
176
+
177
+ def test_s_detect_rbtest_3
150
178
  no_rbtest_script = <<XXX
151
179
  def f(x) x*100 end
152
180
  XXX