Skip to content

Commit 62cdfda

Browse files
committed
Test passing input to a launched STDIN
1 parent d16466e commit 62cdfda

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/test/common/process/proc.exec.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ suite('ProcessService Observable', () => {
193193
expect(outputs).to.deep.equal(expectedOutput, 'Output values are incorrect');
194194
});
195195

196+
test('exec should write input to process stdin', async () => {
197+
const inputText = 'some text\n';
198+
const procService = new ProcessService(new BufferDecoder());
199+
const result = await procService.exec(pythonPath, ['-c', 'import sys; sys.stdout.write(sys.stdin.read())'], { input: inputText });
200+
201+
expect(result).not.to.be.an('undefined', 'result is undefined.');
202+
// validate that the input was written by examining the echoed content
203+
expect(result.stdout).to.be.equal(inputText);
204+
});
205+
196206
test('exec should throw an error with stderr output', async () => {
197207
const procService = new ProcessService(new BufferDecoder());
198208
const pythonCode = ['import sys', 'sys.stderr.write("a")', 'sys.stderr.flush()'];

src/test/common/process/proc.observable.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,20 @@ suite('ProcessService', () => {
291291
done
292292
);
293293
});
294+
295+
test('execObservable should write input to process stdin', done => {
296+
const inputText = 'some text\n';
297+
const procService = new ProcessService(new BufferDecoder());
298+
const result = procService.execObservable(pythonPath, ['-c', 'import sys; sys.stdout.write(sys.stdin.read())'], { input: inputText });
299+
300+
expect(result).not.to.be.an('undefined', 'result is undefined.');
301+
// validate that the input was written by examining the echoed content
302+
result.out.subscribe(
303+
output => {
304+
expect(output.out).to.be.equal(inputText);
305+
},
306+
done,
307+
done
308+
);
309+
});
294310
});

0 commit comments

Comments
 (0)