Skip to content
This repository
Browse code

debugger: test repeating last command

* debugger: Add NODE_FORCE_READLINE environment variable, handle
 `SIGINT`'s sent to process while in this mode.
  • Loading branch information...
commit d68c02e3fe50405279a138e908701558939ce926 1 parent 8ac1a73
Fedor Indutny indutny authored

Showing 2 changed files with 33 additions and 5 deletions. Show diff stats Hide diff stats

  1. +9 1 lib/_debugger.js
  2. +24 4 test/simple/test-debugger-repl.js
10 lib/_debugger.js
@@ -759,6 +759,15 @@ function Interface(stdin, stdout, args) {
759 759 };
760 760 if (parseInt(process.env['NODE_NO_READLINE'], 10)) {
761 761 opts.terminal = false;
  762 + } else if (parseInt(process.env['NODE_FORCE_READLINE'], 10)) {
  763 + opts.terminal = true;
  764 +
  765 + // Emulate Ctrl+C if we're emulating terminal
  766 + if (!this.stdout.isTTY) {
  767 + process.on('SIGINT', function() {
  768 + self.repl.rli.emit('SIGINT');
  769 + });
  770 + }
762 771 }
763 772 if (parseInt(process.env['NODE_DISABLE_COLORS'], 10)) {
764 773 opts.useColors = false;
@@ -777,7 +786,6 @@ function Interface(stdin, stdout, args) {
777 786 self.killChild();
778 787 });
779 788
780   -
781 789 var proto = Interface.prototype,
782 790 ignored = ['pause', 'resume', 'exitRepl', 'handleBreak',
783 791 'requireConnection', 'killChild', 'trySpawn',
28 test/simple/test-debugger-repl.js
@@ -29,7 +29,9 @@ var port = common.PORT + 1337;
29 29
30 30 var script = common.fixturesDir + '/breakpoints.js';
31 31
32   -var child = spawn(process.execPath, ['debug', '--port=' + port, script]);
  32 +var child = spawn(process.execPath, ['debug', '--port=' + port, script], {
  33 + env: { NODE_FORCE_READLINE: 1 }
  34 +});
33 35
34 36 console.error('./node', 'debug', '--port=' + port, script);
35 37
@@ -48,6 +50,7 @@ var expected = [];
48 50
49 51 child.on('line', function(line) {
50 52 line = line.replace(/^(debug> )+/, 'debug> ');
  53 + line = line.replace(/\u001b\[\d+\w/g, '');
51 54 console.error('line> ' + line);
52 55 assert.ok(expected.length > 0, 'Got unexpected line: ' + line);
53 56
@@ -96,15 +99,17 @@ addTest(null, [
96 99
97 100 // Next
98 101 addTest('n', [
  102 + /debug> n/,
99 103 /break in .*:11/,
100 104 /9/, /10/, /11/, /12/, /13/
101 105 ]);
102 106
103 107 // Watch
104   -addTest('watch("\'x\'"), true', [/true/]);
  108 +addTest('watch("\'x\'"), true', [/debug>/, /true/]);
105 109
106 110 // Continue
107 111 addTest('c', [
  112 + /debug>/,
108 113 /break in .*:5/,
109 114 /Watchers/,
110 115 /0:\s+'x' = "x"/,
@@ -114,49 +119,64 @@ addTest('c', [
114 119
115 120 // Show watchers
116 121 addTest('watchers', [
  122 + /debug>/,
117 123 /0:\s+'x' = "x"/
118 124 ]);
119 125
120 126 // Unwatch
121   -addTest('unwatch("\'x\'"), true', [/true/]);
  127 +addTest('unwatch("\'x\'"), true', [/debug>/, /true/]);
122 128
123 129 // Step out
124 130 addTest('o', [
  131 + /debug>/,
125 132 /break in .*:12/,
126 133 /10/, /11/, /12/, /13/, /14/
127 134 ]);
128 135
129 136 // Continue
130 137 addTest('c', [
  138 + /debug>/,
131 139 /break in .*:5/,
132 140 /3/, /4/, /5/, /6/, /7/
133 141 ]);
134 142
135 143 // Set breakpoint by function name
136 144 addTest('sb("setInterval()", "!(setInterval.flag++)")', [
  145 + /debug>/,
137 146 /1/, /2/, /3/, /4/, /5/, /6/, /7/, /8/, /9/, /10/
138 147 ]);
139 148
140 149 // Continue
141 150 addTest('c', [
  151 + /debug>/,
142 152 /break in node.js:\d+/,
143 153 /\d/, /\d/, /\d/, /\d/, /\d/
144 154 ]);
145 155
146   -addTest('c', [
  156 +// Repeat last command
  157 +addTest('', [
  158 + /debug>/,
147 159 /break in .*breakpoints.js:\d+/,
148 160 /\d/, /\d/, /\d/, /\d/, /\d/
149 161 ]);
150 162
151 163 addTest('repl', [
  164 + /debug>/,
152 165 /Press Ctrl \+ C to leave debug repl/
153 166 ]);
154 167
155 168 addTest('now', [
  169 + /> now/,
156 170 /\w* \w* \d* \d* \d*:\d*:\d* GMT[+-]\d* (\w*)/
157 171 ]);
158 172
159 173 function finish() {
  174 + // Exit debugger repl
  175 + child.kill('SIGINT');
  176 + child.kill('SIGINT');
  177 +
  178 + // Exit debugger
  179 + child.kill('SIGINT');
160 180 process.exit(0);
161 181 }
162 182

0 comments on commit d68c02e

Please sign in to comment.
Something went wrong with that request. Please try again.