File: test_rake_test_task.rb

package info (click to toggle)
rake 12.3.1-3%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 928 kB
  • sloc: ruby: 9,386; sh: 19; ansic: 19; makefile: 10
file content (173 lines) | stat: -rw-r--r-- 4,455 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# frozen_string_literal: true
require File.expand_path("../helper", __FILE__)
require "rake/testtask"

class TestRakeTestTask < Rake::TestCase
  include Rake

  def test_initialize
    tt = Rake::TestTask.new do |t| end
    refute_nil tt
    assert_equal :test, tt.name
    assert_equal ["lib"], tt.libs
    assert_equal "test/test*.rb", tt.pattern
    assert_equal false, tt.verbose
    assert_equal true, tt.warning
    assert_equal [], tt.deps
    assert Task.task_defined?(:test)
  end

  def test_initialize_deps
    tt = Rake::TestTask.new(example: :bar)
    refute_nil tt
    assert_equal :bar, tt.deps
    assert Task.task_defined?(:example)
  end

  def test_initialize_multi_deps
    tt = Rake::TestTask.new(example: [:foo, :bar])
    refute_nil tt
    assert_equal [:foo, :bar], tt.deps
    assert Task.task_defined?(:example)
  end

  def test_initialize_override
    tt = Rake::TestTask.new(example: :bar) do |t|
      t.description = "Run example tests"
      t.libs = ["src", "ext"]
      t.pattern = "test/tc_*.rb"
      t.warning = true
      t.verbose = true
      t.deps = [:env]
    end
    refute_nil tt
    assert_equal "Run example tests", tt.description
    assert_equal :example, tt.name
    assert_equal ["src", "ext"], tt.libs
    assert_equal "test/tc_*.rb", tt.pattern
    assert_equal true, tt.warning
    assert_equal true, tt.verbose
    assert_equal [:env], tt.deps
    assert_match(/-w/, tt.ruby_opts_string)
    assert Task.task_defined?(:example)
  end

  def test_file_list_env_test
    ENV["TEST"] = "testfile.rb"
    tt = Rake::TestTask.new do |t|
      t.pattern = "*"
    end

    assert_equal ["testfile.rb"], tt.file_list.to_a
  ensure
    ENV.delete "TEST"
  end

  def test_libs_equals
    test_task = Rake::TestTask.new do |t|
      t.libs << ["A", "B"]
    end

    path = %w[lib A B].join File::PATH_SEPARATOR

    assert_equal "-w -I\"#{path}\"", test_task.ruby_opts_string
  end

  def test_libs_equals_empty
    test_task = Rake::TestTask.new do |t|
      t.libs    = []
      t.warning = false
    end

    assert_equal "", test_task.ruby_opts_string
  end

  def test_pattern_equals
    ["gl.rb", "ob.rb"].each do |f|
      create_file(f)
    end
    tt = Rake::TestTask.new do |t|
      t.pattern = "*.rb"
    end
    assert_equal ["gl.rb", "ob.rb"], tt.file_list.to_a
  end

  def test_pattern_equals_test_files_equals
    ["gl.rb", "ob.rb"].each do |f|
      create_file(f)
    end
    tt = Rake::TestTask.new do |t|
      t.test_files = FileList["a.rb", "b.rb"]
      t.pattern = "*.rb"
    end
    assert_equal ["a.rb", "b.rb", "gl.rb", "ob.rb"], tt.file_list.to_a
  end

  def test_run_code_direct
    globbed = ["test_gl.rb", "test_ob.rb"].map { |f| File.join("test", f) }
    others = ["a.rb", "b.rb"].map { |f| File.join("test", f) }
    (globbed + others).each do |f|
      create_file(f)
    end
    test_task = Rake::TestTask.new do |t|
      t.loader = :direct
      # if t.pettern and t.test_files are nil,
      # t.pettern is "test/test*.rb"
    end

    assert_equal '-e "ARGV.each{|f| require f}"', test_task.run_code
    assert_equal globbed, test_task.file_list.to_a
  end

  def test_run_code_rake
    skip # disabled in Debian
    spec = Gem::Specification.new "rake", 0
    spec.loaded_from = File.join Gem::Specification.dirs.last, "rake-0.gemspec"
    rake, Gem.loaded_specs["rake"] = Gem.loaded_specs["rake"], spec

    test_task = Rake::TestTask.new do |t|
      t.loader = :rake
    end

    assert_match(/\A-I".*?" ".*?"\Z/, test_task.run_code)
  ensure
    Gem.loaded_specs["rake"] = rake
  end

  def test_test_files_equals
    tt = Rake::TestTask.new do |t|
      t.test_files = FileList["a.rb", "b.rb"]
    end

    assert_equal ["a.rb", "b.rb"], tt.file_list.to_a
  end

  def test_task_prerequisites
    Rake::TestTask.new :parent
    Rake::TestTask.new child: :parent

    task = Rake::Task[:child]
    assert_includes task.prerequisites, "parent"
  end

  def test_task_prerequisites_multi
    Rake::TestTask.new :parent
    Rake::TestTask.new :parent2
    Rake::TestTask.new child: [:parent, :parent2]

    task = Rake::Task[:child]
    assert_includes task.prerequisites, "parent"
    assert_includes task.prerequisites, "parent2"
  end

  def test_task_prerequisites_deps
    Rake::TestTask.new :parent

    Rake::TestTask.new :child do |t|
      t.deps = :parent
    end

    task = Rake::Task[:child]
    assert_includes task.prerequisites, "parent"
  end
end