/
runner_against_valid_program_test.rb
148 lines (114 loc) · 3.55 KB
/
runner_against_valid_program_test.rb
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
# frozen_string_literal: true
require_relative "test_helper"
require "byebug/version"
module Byebug
#
# Tests standalone byebug when debugging a target program
#
class RunnerAgainstValidProgramTest < TestCase
def setup
super
example_file.write("sleep 0")
example_file.close
end
def test_run_with_a_script_to_debug
stdout = run_byebug(
example_path,
input: 'puts "Program: #{$PROGRAM_NAME}"'
)
assert_match(/Program: #{example_path}/, stdout)
end
def test_run_with_a_script_and_params_does_not_consume_script_params
stdout = run_byebug(
"--", example_path, "-opt", "value",
input: 'puts "Args: #{$ARGV.join(\', \')}"'
)
assert_match(/Args: -opt, value/, stdout)
end
def test_run_with_ruby_is_ignored_and_script_passed_instead
stdout = run_byebug(
"--", "ruby", example_path,
input: 'puts "Program: #{$0}"'
)
assert_match(/Program: #{example_path}/, stdout)
end
def test_run_with_fullpath_ruby_is_ignored_and_script_passed_instead
stdout = run_byebug(
"--", RbConfig.ruby, example_path,
input: 'puts "Program: #{$0}"'
)
assert_match(/Program: #{example_path}/, stdout)
end
def test_run_with_post_mortem_mode_flag
stdout = run_byebug(
"-m", example_path,
input: "show post_mortem\nset post_mortem off"
)
assert_match(/post_mortem is on/, stdout)
end
def test_run_with_linetracing_flag
stdout = run_byebug(
"-t", example_path,
input: "show linetrace\nset linetrace off"
)
assert_match(/linetrace is on/, stdout)
end
def test_run_with_no_quit_flag
skip
stdout = run_byebug(
"--no-quit", example_path,
input: "cont\nquit!"
)
assert_match(/\(byebug:ctrl\)/, stdout)
end
def test_run_with_require_flag
stdout = run_byebug(
"-r", example_path, example_path,
input: \
"puts \"Example path loaded? \#{$LOADED_FEATURES.include?('#{example_path}')}\""
)
assert_match(/Example path loaded\? true/, stdout)
end
def test_run_with_a_single_include_flag
stdout = run_byebug(
"-I", "dir1", example_path,
input: 'puts "dir1 in LOAD_PATH? #{$LOAD_PATH.include?(\'dir1\')}"'
)
assert_match(/dir1 in LOAD_PATH\? true/, stdout)
end
def test_run_with_several_include_flags
stdout = run_byebug(
"-I", "d1:d2", example_path,
input: \
'puts "d1 and d2 in LOAD_PATH? #{(%w(d1 d2) - $LOAD_PATH).empty?}"'
)
assert_match(/d1 and d2 in LOAD_PATH\? true/, stdout)
end
def test_run_with_debug_flag
stdout = run_byebug(
"-d", example_path,
input: 'puts "Debug flag is #{$DEBUG}"'
)
assert_match(/Debug flag is true/, stdout)
end
def test_run_and_press_tab_doesnt_make_byebug_crash
stdout = run_byebug(
example_path,
input: "\tputs 'Reached here'"
)
assert_match(/Reached here/, stdout)
end
def test_run_stops_at_the_first_line_by_default
stdout = run_byebug(example_path)
assert_match(/=> 1: sleep 0/, stdout)
end
def test_run_with_no_stop_flag_does_not_stop_at_the_first_line
stdout = run_byebug("--no-stop", example_path)
refute_match(/=> 1: sleep 0/, stdout)
end
def test_run_with_stop_flag_stops_at_the_first_line
stdout = run_byebug("--stop", example_path)
assert_match(/=> 1: sleep 0/, stdout)
end
end
end