Succeed or fail an item based on the return code of a program
490013
def done_item(item, code):
    ''''''
    try:
        if const('FSQ_SUCCESS') == code:
            success(item)
            chirp('{0}: succeeded'.format(item.id))
        elif const('FSQ_FAIL_TMP') == code:
            fail_tmp(item)
            shout('{0}: failed temporarily'.format(item.id))
        else:
            fail_perm(item)
            shout('{0}: failed permanantly'.format(item.id))
    except FSQEnqueueError, e:
        shout(e.strerror.encode(_CHARSET))
        return -1
    except FSQError, e:
        shout(e.strerror.encode(_CHARSET))
    return 0
625931
def failed(self, fail_on_warnings=True):
        """"""

        return bool(self.errors) or (fail_on_warnings and bool(self.warnings))
318292
def _retry(n, f, *args, **kwargs):
    ''''''

    for i in range(n):
        try:
            return f(*args, **kwargs)
        except Exception as exc:
            if i == n - 1:
                log.error(
                    '%s permanently failed with %r', f.__name__, exc)
                raise
            else:
                log.warning(
                    '%s attempt #%d failed with %r', f.__name__, i, exc)
                time.sleep(2 ** i)
    raise RuntimeError('Should never get here!')
520338
function(results, options) {
         failuresOnly = option('failuresOnly')
         print(color("\n Passes: ", 'bold') + color(results.stats.passes, 'green') + 
               color(" Failures: ", 'bold') + color(results.stats.failures, 'red') +
               color(" Duration: ", 'bold') + color(results.duration, 'green') + " ms \n")
              
         function indent(string) {
           return string.replace(/^(.)/gm, '  $1')
         }
         
         each(results.allSuites, function(suite) {
           var displaySuite = failuresOnly ? suite.ran && !suite.passed() : suite.ran
            if (displaySuite && suite.hasSpecs()) {
              print(color(' ' + suite.description, 'bold'))
              each(suite.specs, function(spec){
                var assertionsGraph = inject(spec.assertions, '', function(graph, assertion){
                  return graph + color('.', assertion.passed ? 'green' : 'red')
                })
                if (spec.requiresImplementation())
                  print(color('  ' + spec.description, 'blue') + assertionsGraph)
                else if (spec.passed() && !failuresOnly)
                  print(color('  ' + spec.description, 'green') + assertionsGraph)
                else if (!spec.passed())
                  print(color('  ' + spec.description, 'red') + assertionsGraph + 
                        "\n" + indent(map(spec.failures(), function(a){ return a.message }).join("\n")) + "\n")
              })
              print("")
            }
         })
         
         quit(results.stats.failures)
       }
787781
def _succeed(self, result):
        

        for fn, args, kwargs in self._callbacks:
            fn(result, *args, **kwargs)
        self._resulted_in = result
568851
function check(result, test) {

  const CHECKERS = [ _checkExitCode, _checkOutput, _checkStdout, _checkStderr ];
  var errors = [];

  CHECKERS.forEach(function (checker) {
    var error = checker(result, test);
    if (error) {
      errors.push(error);
    }
  });
  
  return errors;
}
192858
def __assert_false(returned):
        '''
        
        '''
        result = "Pass"
        if isinstance(returned, str):
            try:
                returned = bool(returned)
            except ValueError:
                raise
        try:
            assert (returned is False), "{0} not False".format(returned)
        except AssertionError as err:
            result = "Fail: " + six.text_type(err)
        return result
1285718
def get_code(results):
    
    status = EXIT_SUCCESS

    for file_result in results:
        error = any(object_result.errors for object_result in file_result.object_results)

        fatal = file_result.fatal

        if error:
            status |= EXIT_SCHEMA_INVALID
        if fatal:
            status |= EXIT_VALIDATION_ERROR

    return status
249485
private void checkReturnValue(Decl.FunctionOrMethod d, Environment last) {
		if (d.match(Modifier.Native.class) == null && last != FlowTypeUtils.BOTTOM && d.getReturns().size() != 0) {
			// In this case, code reaches the end of the function or method and,
			// furthermore, that this requires a return value. To get here means
			// that there was no explicit return statement given on at least one
			// execution path.
			syntaxError(d, MISSING_RETURN_STATEMENT);
		}
	}
763889
function({options}, succeed, skip) {
    return each(options.if_exec).call((cmd, next) => {
      this.log({
        message: `Nikita \`if_exec\`: ${cmd}`,
        level: 'DEBUG',
        module: 'nikita/misc/conditions'
      });
      return this.system.execute({
        cmd: cmd,
        relax: true,
        stderr_log: false,
        stdin_log: false,
        stdout_log: false
      }, function(err, {code}) {
        this.log({
          message: `Nikita \`if_exec\`: code is "${code}"`,
          level: 'INFO',
          module: 'nikita/misc/conditions'
        });
        if (code === 0) {
          return next();
        } else {
          return skip();
        }
      });
    }).next(succeed);
  }
999282
function(items, iterator, done) {
    done = done || function() {};
    var results = [];
    var failure = false;
    var expected = items.length;
    var actual = 0;
    var createIntermediary = function(index) {
      return function(err, result) {
        // Return if we found a failure anywhere.
        // We can't stop execution of functions since they've already
        // been fired off; but we can prevent excessive handling of callbacks.
        if (failure != false) {
          return;
        }

        if (err != null) {
          failure = true;
          done(err, result);
          return;
        }

        actual += 1;

        if (actual == expected) {
          done(null, results);
        }
      };
    };

    for (var i = 0; i < items.length; i++) {
      var item = items[i];
      iterator(item, createIntermediary(i));
    }

    if (items.length == 0) {
      done(null, []);
    }
  }
209950
function success(result, ignore) {
    return ((typeof result.error === 'undefined' &&
        typeof result.status === 'undefined' &&
        typeof result.success === 'undefined') ||
        (result.status && result.status === 'success') ||
        (result.success && result.success === true) ||
        (ignore && result.error && !ignore.test(result.error))) ? true : false;
}
1157569
function checkExec (mode, callback) {
  if (!exercise.passed)
    return callback(null, true) // shortcut if we've already had a failure

  execWith(copyTempDir, 'testing', function (err, pass) {
    if (err)
      return callback(err)
    if (!pass) {
      exercise.emit('fail', 'JavaScript code loads addon, invokes `length(str)` method and prints the return value')
      return callback(null, false)
    }

    execWith(copyTempDir, 'this is a longer test string, with spaces in it', function (err, pass) {
      if (err)
        return callback(err)

      exercise.emit(pass ? 'pass' : 'fail', 'Add-on receives string, calculates length and returns value')
      callback(null, pass)
    })
  })
}
750982
function(items, iterator, done) {
    done = done || function() {};
    var results = [];
    var failure = false;
    var expected = items.length;
    var current = -1;

    function callback(err, result) {
      if (err) return done(err);

      results.push(result);

      if (current == expected) {
        return done(null, results);
      } else {
        next();
      }
    }

    function next() {
      current += 1;

      var item = items[current];
      iterator(item, callback);
    }

    next()
  }
442054
def fail(message, code=-1):
    """"""
    print('Error: %s' % message, file=sys.stderr)
    sys.exit(code)
1190667
def raise_on_failure(mainfunc):
    """"""
    try:
        errors = mainfunc()
        if errors:
            exit(errors)
    except CalledProcessError as error:
        exit(error.returncode)
    except SystemExit as error:
        if error.code:
            raise
    except KeyboardInterrupt:  # I don't plan to test-cover this.  :pragma:nocover:
        exit(1)
649479
def check(code):
    """"""
    def safe_lookup(op):
        try:
            return instructions.lookup(op)
        except Exception:
            return op

    for i, a in enumerate(code):
        b = code[i+1] if i+1 < len(code) else None

        # Does instruction exist?
        if not isconstant(a):
            try:
                instructions.lookup(a)
            except KeyError as err:
                # Skip embedded push closures
                if not (len(err.args)==1 and is_embedded_push(err.args[0])):
                    raise CompileError("Instruction at index %d is unknown: %s"
                            % (i, a))

        # Invalid: <str> int
        if isstring(a) and safe_lookup(b) == instructions.cast_int:
            raise CompileError(
                "Cannot convert string to integer (index %d): %s %s" % (i, a,
                    b))

        # Invalid: <int> <binary op>
        boolean_ops = [instructions.boolean_not,
                      instructions.boolean_or,
                      instructions.boolean_and]

        if not isbool(a) and safe_lookup(b) in boolean_ops:
            raise CompileError(
                "Can only use binary operators on booleans (index %d): %s %s" %
                    (i, a, b))
    return code