Do a dry run, or write a file.

@param {bool} dryRun Do a dry run?
@param {string} filePath Path to write file to.
@param {Object} result PostCSS root object.
@return {Promise} Resolves with writeCriticalFile or doDryRun function call.
975177
function dryRunOrWriteFile(dryRun, filePath, result) {
  var css = result.css;

  return new Promise(function (resolve) {
    return resolve(dryRun ? doDryRun(css) : writeCriticalFile(filePath, css));
  });
}
1347286
function (stream, destPath) {
    let data = '';
    return new Promise(function (resolve, reject) {
        stream.on('error', reject);
        stream.on('data', function (d) {
            data += d.toString();
        });
        stream.on('end', function () {
            fs.outputFile(destPath, data, function (err) {
                if (!err) {
                    resolve();
                } else {
                    reject(err);
                }
            });
        });
    });
}
989028
function EvergreenReporter(runner) {
  mocha.reporters.Base.call(this, runner);

  var logDir = 'test_logs';
  var self = this;
  var indents = 0;
  var stats = (this.stats = {
    tests: 0,
    passes: 0,
    failures: 0,
    pending: 0
  });

  var tests = [];

  this.runner = runner;
  runner.stats = stats;

  debug('setting up handlers...');

  function indent() {
    return Array(indents).join('  ');
  }

  /*
   * Runs on the start of all of the tests
   */
  runner.on('start', function() {
    stats.start = Date.now();
    debug('starting!');
  });

  runner.on('suite', function(suite) {
    debug('suite start %s', suite.title, suite.file);
    console.log(suite.title);
    if (suite.file) {
      console.log(suite.file);
    }
    indents++;
  });

  runner.on('suite end', function(suite) {
    debug('suite end %s', suite.title, suite.file);
    console.log();
    indents--;
  });

  /**
   * Runs before every test begins
   */
  runner.on('test', function(test) {
    debug('test', test.title);
    test.start = Date.now() / 1000;
  });

  /**
   * Runs after every test ends
   */
  runner.on('test end', function(test) {
    stats.tests++;
    tests.push(test);
  });

  runner.on('pass', function(test) {
    console.log(indent() + test.title + ': Passed!');
    console.log();
    stats.passes++;
    test.exit_code = 0;
    test.state = 'pass';
    test.end = Date.now() / 1000;
  });

  runner.on('fail', function(test, err) {
    test.err = err;
    test.exit_code = 1;
    test.state = 'fail';
    test.end = Date.now() / 1000;
    console.log(indent() + test.title + ': Failed :(');
    console.log(test.err.message);
    console.log(test.err.stack);
    console.log();
    stats.failures++;
  });

  runner.on('pending', function(test) {
    console.log(indent() + test.title + ': Skip');
    console.log();
    stats.pending++;
    test.state = 'skip';
    test.duration = 0;
    test.exit_code = 0;
    test.start = Date.now() / 1000;
    test.end = test.start;
  });

  /**
   * Runs after all tests have completed
   */
  runner.on('end', function() {
    debug('end!', arguments);
    stats.end = Date.now() / 1000;
    stats.duration = stats.end - stats.start;

    var obj = {
      end: stats.end,
      start: stats.start,
      elapsed: stats.duration,
      failures: stats.failures,
      results: tests.map(report)
    };

    runner.testResults = obj;
    debug('test results', runner.testResults);

    var output = JSON.stringify(obj, null, 2);

    var reportPath = path.join(process.cwd(), 'report.json');
    fs.writeFileSync(reportPath, output);
    debug('report json written to', reportPath);

    console.log('-----------------------------------');
    console.log('# mocha-evergreen-reporter: Results');
    console.log('Passed: %s', stats.passes);
    console.log('Failed: %s', stats.failures);
    console.log('Skipped: %s', stats.pending);
    console.log('Report Path: %s', reportPath);
    console.log('-----------------------------------');

    process.exit(stats.failures);
  });
}
637163
function(runner) {
      this.reportFailures_();

      var results = runner.results();
      var resultColor = (results.failedCount > 0) ? this.color_.fail() : this.color_.pass();

      var specs = runner.specs();
      var specCount = specs.length;

      var message = "\n\nFinished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + " seconds";
      this.printLine_(message);

      // This is what jasmine-html.js has
      //message = "" + specCount + " spec" + ( specCount === 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount === 1) ? "" : "s");

      this.printLine_(this.stringWithColor_(this.printRunnerResults_(runner), resultColor));

      this.finished_ = true;
      if(this.callback_) { this.callback_(runner); }
    }
1292566
function fsRead(filePath) {
    return new Promise((resolve, reject) => {
        fs.readFile(filePath, (err, data) => {
            if (err) {
                if (err.syscall === 'open') {
                    console.log('Open "' + err.path +'" fail!')
                }
                reject(err);
            }
            resolve(data.toString())
        })
    })
}
240079
function(testPath) {
    var testStartTime = +new Date();

    var waitForTest = function(resolve, reject) {
      // executeScript runs the passed method in the "window" context of
      // the current test. JSUnit exposes hooks into the test's status through
      // the "G_testRunner" global object.
      browser
          .executeScript(function() {
            if (window['G_testRunner'] &&
                window['G_testRunner']['isFinished']()) {
              var status = {};
              status['isFinished'] = true;
              status['isSuccess'] = window['G_testRunner']['isSuccess']();
              status['report'] = window['G_testRunner']['getReport']();
              return status;
            } else {
              return {'isFinished': false};
            }
          })
          .then(
              function(status) {
                if (status && status.isFinished) {
                  resolve(status);
                } else {
                  var currTime = +new Date();
                  if (currTime - testStartTime > TEST_TIMEOUT) {
                    status.isSuccess = false;
                    status.report = testPath + ' timed out after ' +
                        (TEST_TIMEOUT / 1000) + 's!';
                    // resolve so tests continue running.
                    resolve(status);
                  } else {
                    // Check every 300ms for completion.
                    setTimeout(
                        waitForTest.bind(undefined, resolve, reject), 300);
                  }
                }
              },
              function(err) {
                reject(err);
              });
    };

    return new Promise(function(resolve, reject) {
      waitForTest(resolve, reject);
    });
  }
908297
function writeToFile(fileContent, filePath) {
  return new Promise((resolve, reject) => {
    fs.writeFile(filePath, fileContent, 'utf8', (err) => {
      if (err) {
        reject(err);
        return;
      }
      resolve(filePath);
    });
  });
}
627680
def write(self, dry_run=True):
    
    start_lines = self._build_file_source_lines[:]
    end_lines = self.build_file_lines()
    diff_generator = unified_diff(start_lines,
                                  end_lines,
                                  fromfile=self.build_file.relpath,
                                  tofile=self.build_file.relpath,
                                  lineterm='')
    if dry_run:
      msg = 'DRY RUN, would have written this diff:'
    else:
      msg = 'REAL RUN, about to write the following diff:'
    sys.stderr.write(msg + '\n')
    sys.stderr.write('*' * 40 + '\n')
    sys.stderr.write('target at: ')
    sys.stderr.write(str(self.target_address) + '\n')

    for line in diff_generator:
      sys.stderr.write(line + '\n')

    sys.stderr.write('*' * 40 + '\n')
    if not dry_run:
      with open(self.build_file.full_path, 'w') as bf:
        bf.write('\n'.join(end_lines))
      sys.stderr.write('WROTE to {full_path}\n'.format(full_path=self.build_file.full_path))
17539
public boolean isDryRun() {
	String run = getSingle("dryrun");
	if (run == null) return false;
	if (run.equalsIgnoreCase("yes")) return true;
	return false;
    }
418070
function saveFile(filename, data, overwrite) {
  if (overwrite) {
    return fs.outputFile(filename, data)
      .then(() => filename);
  } else {
    return new Promise((resolve, reject) => {
      fsu.writeFileUnique(
        filename.replace(fileExtRegex, '{_###}$&'),
        data,
        { force: true },
        (err, savedFile) => err === null ? resolve(savedFile) : reject(err)
      );
    });
  }
}
855705
def _postrun(self, result):
        
        logger.debug(
            "{}.PostRun: {}[{}]".format(
                self.__class__.__name__, self.__class__.path, self.uuid
            ),
            extra=dict(
                kmsg=Message(
                    self.uuid, entrypoint=self.__class__.path,
                    params=self.params, metadata=self.metadata
                ).dump()
            )
        )
        return self.postrun(result)
318010
function writeResolved(info, res, statusCode){
    statusCode = statusCode || 200;
    if (info.type === 'json'){

      res.setHeader('Content-Type', 'application/json');
      res.writeHead(statusCode);
      res.end(JSON.stringify(info.data));

      return true;
    } else if (info.type === 'file') {
      // content || assets
      sendFile(res, info.filename);

      return true;
    } else if (info.type === 'files') {
      // content with mutiple files
      if (info.files.length === 1){
        //res.setHeader('Content-Type', mime.lookup( info.files[0].filename) );
        sendFile(res, info.files[0].filename);
        return true;
      } else {
        var bpath = extractBasepath(info.files.map(function(f){ return f.filename; }));

        var relfiles = info.files.map(function(f){
          var fname = f.filename.replace(/\\/ig, '/');
          return fname.replace(bpath, '');
        });

        var htmls = relfiles.filter(function(rf){
          return (/\.html$/i).test(rf);
        });

        // the index HTML
        var ihtml = htmls.filter(function(h){ 
          return /index.htm(l)?/ig.test(h);
        });

        var idxhtml = ihtml.length > 0 ? ihtml[0] : undefined;

        if ( idxhtml === undefined){
          // index.html doesn't exists 
          // any html
          idxhtml = (htmls.length > 0 ? htmls[0] : undefined);
        }

        var route = '/content/' + info.uid;
        if (app.cacheContent[route] === undefined){
          app.cacheContent[route] = {
            path: bpath,
            index: idxhtml
          };
        }
        var r = route;
        var item = app.cacheContent[route];
        if (item.index !== undefined){
          r += '/' + item.index;
        }
        
        res.redirect(r);
        //res.sendFile(idxhtml, {root: bpath });
      }

      return true;
    }

    function sendFile(res, filename){
      var fname = path.basename(filename);
      fname = encodeURIComponent(fname);
      res.setHeader('Content-disposition', 'inline; filename="' + fname + '"');
      res.setHeader('Content-Type', mime.lookup(filename));

      res.sendFile(filename);
    }

    return false;

    function extractBasepath(entries) {

      var dirs = entries.map(function(e){ 
        return path.dirname(e); 
      });

      var sdirs = dirs.map(function(d){ 
        return d.split('\\');
      });

      var idx = 0;
      var curr;
      var root = '';
      var eq;

      var haveFunc = function(sd){ 
        return sd.length > idx; 
      };

      var eqFunc = function(i){
        return curr === i;
      };

      var eqmapFunc = function(a){ 
        return a[idx]; 
      };

      do {

        curr = sdirs[0][idx];

        var have = _.all(sdirs, haveFunc);

        eq = have;
        if (have === true){
          eq = _.all(sdirs.map(eqmapFunc), eqFunc);
        }

        if(eq) {
          root += curr + '/';
        }

        idx++;

      } while(eq === true);

      return root;
    }
  }
583888
def run_on_change(paths)
      if @options[:dry_run]
        paths.each { |path| UI.info "Dry run: #{path}" }
        return
      end

      total    = 0
      failures = 0
      duration = 0
      run_command("mix test #{paths.join(' ')}") do |line|
        puts line
        if /Finished in ([0-9.]+) seconds/.match(line)
          duration = Regexp::last_match[1]
        elsif /([0-9]+) tests, ([0-9]+) failures/.match(line)
          total = Regexp::last_match[1].to_i
          failures = Regexp::last_match[2].to_i
        end
      end

      Notifier.notify(
        guard_message(total, failures, duration),
        :title => "Elixir results",
        :image => guard_image(failures),
        :priority => guard_priority(failures)
      )
    end
757944
function final(err,result){
			if (err){return res.status(404).send(err)};
			var mts = process.rapidcfg.mdb.esqls[req.body.queryname];
			mts.inuse = true;
			process.rapidcfg.mdb.sqls[req.body.queryname] = mts;
			delete process.rapidcfg.mdb.esqls[req.body.queryname] //delete ;
			//console.log(process.rapidcfg.mdb.sqls);
			return res.send({message:"OK",result:result});
		}
1032807
synchronized void result(@Nullable T res) {
        if (isFinished) {
            throw new RuntimeException("Promise " + this + " already completed!");
        }
        isFinished = true;
        result = res;
        deliverResult();
    }
391130
def process_file(self, path, dryrun):
        
        # special case - skip output file so we won't include it in result
        if path == self._output_path:
            return None

        # if dryrun skip and return file
        if dryrun:
            return path

        # concat file with output file
        with open(path, "rb") as infile:
            data = infile.read()
            self._output_file.write(data)

        # return processed file path
        return path
422875
function createDirectory(dir) {
    if (!fs.existsSync(dir)) {
        dryRun ? console.log(`...CREATE the '${dir}' folder.`) : fs.mkdirSync(dir);
    }
}