11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci// These tests make sure that the `options` object passed to these functions are
51cb0ef41Sopenharmony_ci// never altered.
61cb0ef41Sopenharmony_ci//
71cb0ef41Sopenharmony_ci// Refer: https://github.com/nodejs/node/issues/7655
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst fs = require('fs');
101cb0ef41Sopenharmony_ciconst path = require('path');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst options = common.mustNotMutateObjectDeep({});
131cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
141cb0ef41Sopenharmony_citmpdir.refresh();
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cifs.readFile(__filename, options, common.mustSucceed());
171cb0ef41Sopenharmony_cifs.readFileSync(__filename, options);
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cifs.readdir(__dirname, options, common.mustSucceed());
201cb0ef41Sopenharmony_cifs.readdirSync(__dirname, options);
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciif (common.canCreateSymLink()) {
231cb0ef41Sopenharmony_ci  const sourceFile = path.resolve(tmpdir.path, 'test-readlink');
241cb0ef41Sopenharmony_ci  const linkFile = path.resolve(tmpdir.path, 'test-readlink-link');
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  fs.writeFileSync(sourceFile, '');
271cb0ef41Sopenharmony_ci  fs.symlinkSync(sourceFile, linkFile);
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  fs.readlink(linkFile, options, common.mustSucceed());
301cb0ef41Sopenharmony_ci  fs.readlinkSync(linkFile, options);
311cb0ef41Sopenharmony_ci}
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci{
341cb0ef41Sopenharmony_ci  const fileName = path.resolve(tmpdir.path, 'writeFile');
351cb0ef41Sopenharmony_ci  fs.writeFileSync(fileName, 'ABCD', options);
361cb0ef41Sopenharmony_ci  fs.writeFile(fileName, 'ABCD', options, common.mustSucceed());
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci{
401cb0ef41Sopenharmony_ci  const fileName = path.resolve(tmpdir.path, 'appendFile');
411cb0ef41Sopenharmony_ci  fs.appendFileSync(fileName, 'ABCD', options);
421cb0ef41Sopenharmony_ci  fs.appendFile(fileName, 'ABCD', options, common.mustSucceed());
431cb0ef41Sopenharmony_ci}
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ciif (!common.isIBMi) { // IBMi does not support fs.watch()
461cb0ef41Sopenharmony_ci  const watch = fs.watch(__filename, options, common.mustNotCall());
471cb0ef41Sopenharmony_ci  watch.close();
481cb0ef41Sopenharmony_ci}
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci{
511cb0ef41Sopenharmony_ci  fs.watchFile(__filename, options, common.mustNotCall());
521cb0ef41Sopenharmony_ci  fs.unwatchFile(__filename);
531cb0ef41Sopenharmony_ci}
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci{
561cb0ef41Sopenharmony_ci  fs.realpathSync(__filename, options);
571cb0ef41Sopenharmony_ci  fs.realpath(__filename, options, common.mustSucceed());
581cb0ef41Sopenharmony_ci}
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci{
611cb0ef41Sopenharmony_ci  const tempFileName = path.resolve(tmpdir.path, 'mkdtemp-');
621cb0ef41Sopenharmony_ci  fs.mkdtempSync(tempFileName, options);
631cb0ef41Sopenharmony_ci  fs.mkdtemp(tempFileName, options, common.mustSucceed());
641cb0ef41Sopenharmony_ci}
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci{
671cb0ef41Sopenharmony_ci  const fileName = path.resolve(tmpdir.path, 'streams');
681cb0ef41Sopenharmony_ci  fs.WriteStream(fileName, options).once('open', common.mustCall(() => {
691cb0ef41Sopenharmony_ci    fs.ReadStream(fileName, options).destroy();
701cb0ef41Sopenharmony_ci  })).end();
711cb0ef41Sopenharmony_ci}
72