From 8ea6844d265dbcd24e18fd98dc5f598f682d0edc Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 27 May 2015 19:20:28 -0700 Subject: [PATCH] test: add test for failed save in REPL PR-URL: https://github.com/nodejs/io.js/pull/1818 Reviewed-By: Chris Dickinson --- test/parallel/test-repl-.save.load.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-repl-.save.load.js b/test/parallel/test-repl-.save.load.js index cf3224e..dd92c76 100644 --- a/test/parallel/test-repl-.save.load.js +++ b/test/parallel/test-repl-.save.load.js @@ -74,5 +74,20 @@ putIn.write = function(data) { }; putIn.run(['.load ' + loadFile]); +// clear the REPL +putIn.run(['.clear']); + +// NUL (\0) is disallowed in filenames in UNIX-like operating systems and +// Windows so we can use that to test failed saves +const invalidFileName = join(common.tmpDir, '\0\0\0\0\0'); -//TODO how do I do a failed .save test? +// should not break +putIn.write = function(data) { + // make sure I get a failed to save message and not some other error + assert.equal(data, 'Failed to save:' + invalidFileName + '\n'); + // reset to no-op + putIn.write = function() {}; +}; + +// save it to a file +putIn.run(['.save ' + invalidFileName]); -- 2.7.4