File: test_rake_task_argument_parsing.rb

package info (click to toggle)
rake 13.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 916 kB
  • sloc: ruby: 9,661; ansic: 19; sh: 19; makefile: 11
file content (124 lines) | stat: -rw-r--r-- 3,098 bytes parent folder | download | duplicates (3)
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
# frozen_string_literal: true
require File.expand_path("../helper", __FILE__)

class TestRakeTaskArgumentParsing < Rake::TestCase # :nodoc:
  def setup
    super

    @app = Rake::Application.new
  end

  def test_name_only
    name, args = @app.parse_task_string("name")
    assert_equal "name", name
    assert_equal [], args
  end

  def test_empty_args
    name, args = @app.parse_task_string("name[]")
    assert_equal "name", name
    assert_equal [], args
  end

  def test_one_argument
    name, args = @app.parse_task_string("name[one]")
    assert_equal "name", name
    assert_equal ["one"], args
  end

  def test_two_arguments
    name, args = @app.parse_task_string("name[one,two]")
    assert_equal "name", name
    assert_equal ["one", "two"], args
  end

  def test_can_handle_spaces_between_args
    name, args = @app.parse_task_string("name[one, two,\tthree , \tfour]")
    assert_equal "name", name
    assert_equal ["one", "two", "three", "four"], args
  end

  def test_can_handle_spaces_between_all_args
    name, args = @app.parse_task_string("name[ one , two ,\tthree , \tfour ]")
    assert_equal "name", name
    assert_equal ["one", "two", "three", "four"], args
  end

  def test_keeps_embedded_spaces
    name, args = @app.parse_task_string("name[a one ana, two]")
    assert_equal "name", name
    assert_equal ["a one ana", "two"], args
  end

  def test_can_handle_commas_in_args
    name, args = @app.parse_task_string("name[one, two, three_a\\, three_b, four]")
    assert_equal "name", name
    assert_equal ["one", "two", "three_a, three_b", "four"], args
  end

  def test_treat_blank_arg_as_empty_string
    name, args = @app.parse_task_string("name[one,]")
    assert_equal "name", name
    assert_equal ["one", ""], args

    name, args = @app.parse_task_string("name[one,,two]")
    assert_equal "name", name
    assert_equal ["one", "", "two"], args
  end

  def test_terminal_width_using_env
    app = Rake::Application.new
    app.terminal_columns = 1234

    assert_equal 1234, app.terminal_width
  end

  def test_terminal_width_using_stty
    def @app.unix?() true end
    def @app.dynamic_width_stty() 1235 end
    def @app.dynamic_width_tput() 0 end

    assert_equal 1235, @app.terminal_width
  end

  def test_terminal_width_using_tput
    def @app.unix?() true end
    def @app.dynamic_width_stty() 0 end
    def @app.dynamic_width_tput() 1236 end

    assert_equal 1236, @app.terminal_width
  end

  def test_terminal_width_using_hardcoded_80
    def @app.unix?() false end

    assert_equal 80, @app.terminal_width
  end

  def test_terminal_width_with_failure
    def @app.unix?() raise end

    assert_equal 80, @app.terminal_width
  end

  def test_no_rakeopt
    app = Rake::Application.new
    app.init %w[--trace]
    assert !app.options.silent
  end

  def test_rakeopt_with_blank_options
    app = Rake::Application.new
    app.init %w[--trace]
    assert !app.options.silent
  end

  def test_rakeopt_with_silent_options
    ENV["RAKEOPT"] = "-s"
    app = Rake::Application.new

    app.init

    assert app.options.silent
  end
end