~ubuntu-branches/ubuntu/vivid/nodejs/vivid

« back to all changes in this revision

Viewing changes to test/simple/test-debugger-repl-utf8.js

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
 
 
23
22
var common = require('../common');
24
 
var assert = require('assert');
25
 
var spawn = require('child_process').spawn;
26
 
var debug = require('_debugger');
27
 
 
28
23
var script = common.fixturesDir + '/breakpoints_utf8.js';
29
 
 
30
 
var child = spawn(process.execPath, ['debug', script]);
31
 
 
32
 
var buffer = '';
33
 
child.stdout.setEncoding('utf-8');
34
 
child.stdout.on('data', function(data) {
35
 
  data = (buffer + data.toString()).split(/\n/g);
36
 
  buffer = data.pop();
37
 
  data.forEach(function(line) {
38
 
    child.emit('line', line);
39
 
  });
40
 
});
41
 
child.stderr.pipe(process.stdout);
42
 
 
43
 
var expected = [];
44
 
 
45
 
child.on('line', function(line) {
46
 
  assert.ok(expected.length > 0, 'Got unexpected line: ' + line);
47
 
 
48
 
  var expectedLine = expected[0].lines.shift();
49
 
  assert.ok(line.match(expectedLine) !== null, line + ' != ' + expectedLine);
50
 
 
51
 
  if (expected[0].lines.length === 0) {
52
 
    var callback = expected[0].callback;
53
 
    expected.shift();
54
 
    callback && callback();
55
 
  }
56
 
});
57
 
 
58
 
function addTest(input, output) {
59
 
  function next() {
60
 
    if (expected.length > 0) {
61
 
      child.stdin.write(expected[0].input + '\n');
62
 
 
63
 
      if (!expected[0].lines) {
64
 
        setTimeout(function() {
65
 
          var callback = expected[0].callback;
66
 
          expected.shift();
67
 
 
68
 
          callback && callback();
69
 
        }, 50);
70
 
      }
71
 
    } else {
72
 
      finish();
73
 
    }
74
 
  };
75
 
  expected.push({input: input, lines: output, callback: next});
76
 
}
77
 
 
78
 
// Initial lines
79
 
addTest(null, [
80
 
  /listening on port 5858/,
81
 
  /connecting... ok/,
82
 
  /break in .*:1/,
83
 
  /1/, /2/, /3/
84
 
]);
85
 
 
86
 
// Next
87
 
addTest('n', [
88
 
  /break in .*:11/,
89
 
  /9/, /10/, /11/, /12/, /13/
90
 
]);
91
 
 
92
 
// Watch
93
 
addTest('watch("\'x\'")');
94
 
 
95
 
// Continue
96
 
addTest('c', [
97
 
  /break in .*:5/,
98
 
  /Watchers/,
99
 
  /0:\s+'x' = "x"/,
100
 
  /()/,
101
 
  /3/, /4/, /5/, /6/, /7/
102
 
]);
103
 
 
104
 
// Show watchers
105
 
addTest('watchers', [
106
 
  /0:\s+'x' = "x"/
107
 
]);
108
 
 
109
 
// Unwatch
110
 
addTest('unwatch("\'x\'")');
111
 
 
112
 
// Step out
113
 
addTest('o', [
114
 
  /break in .*:12/,
115
 
  /10/, /11/, /12/, /13/, /14/
116
 
]);
117
 
 
118
 
// Continue
119
 
addTest('c', [
120
 
  /break in .*:5/,
121
 
  /3/, /4/, /5/, /6/, /7/
122
 
]);
123
 
 
124
 
// Set breakpoint by function name
125
 
addTest('sb("setInterval()", "!(setInterval.flag++)")', [
126
 
  /1/, /2/, /3/, /4/, /5/, /6/, /7/, /8/, /9/, /10/
127
 
]);
128
 
 
129
 
// Continue
130
 
addTest('c', [
131
 
  /break in node.js:\d+/,
132
 
  /\d/, /\d/, /\d/, /\d/, /\d/
133
 
]);
134
 
 
135
 
// Continue
136
 
addTest('c, bt', [
137
 
  /Can't request backtrace now/
138
 
]);
139
 
 
140
 
 
141
 
function finish() {
142
 
  process.exit(0);
143
 
}
144
 
 
145
 
function quit() {
146
 
  if (quit.called) return;
147
 
  quit.called = true;
148
 
  child.stdin.write('quit');
149
 
}
150
 
 
151
 
setTimeout(function() {
152
 
  var err = 'Timeout';
153
 
  if (expected.length > 0 && expected[0].lines) {
154
 
    err = err + '. Expected: ' + expected[0].lines.shift();
155
 
  }
156
 
 
157
 
  throw new Error(err);
158
 
}, 5000);
159
 
 
160
 
process.once('uncaughtException', function(e) {
161
 
  quit();
162
 
  console.error(e.toString());
163
 
  child.kill('SIGKILL');
164
 
  process.exit(1);
165
 
});
166
 
 
167
 
process.on('exit', function(code) {
168
 
  quit();
169
 
  if (code === 0) {
170
 
    assert.equal(expected.length, 0);
171
 
  }
172
 
});
 
24
process.env.NODE_DEBUGGER_TEST_SCRIPT = script;
 
25
 
 
26
require('./test-debugger-repl.js');
 
27