def Run(self, cmd_val):
    'The test/[ builtin.\n\n    The only difference between test and [ is that [ needs a matching ].\n    '
    if self.need_right_bracket:
        if self.exec_opts.simple_test_builtin():
            e_usage("should be invoked as 'test' (simple_test_builtin)")
        strs = cmd_val.argv
        if ((not strs) or (strs[(- 1)] != ']')):
            self.errfmt.Print_('missing closing ]', span_id=cmd_val.arg_spids[0])
            return 2
        cmd_val.argv.pop()
        cmd_val.arg_spids.pop()
    w_parser = _StringWordEmitter(cmd_val)
    w_parser.Read()
    b_parser = bool_parse.BoolParser(w_parser)
    bool_node = None
    n = (len(cmd_val.argv) - 1)
    if (self.exec_opts.simple_test_builtin() and (n > 3)):
        e_usage('should only have 3 arguments or fewer (simple_test_builtin)')
    try:
        if (n == 0):
            return 1
        elif (n == 1):
            w = w_parser.Read()
            bool_node = bool_expr.WordTest(w)
        elif (n == 2):
            bool_node = _TwoArgs(w_parser)
        elif (n == 3):
            bool_node = _ThreeArgs(w_parser)
        if (n == 4):
            a0 = w_parser.Peek(0)
            if (a0 == '!'):
                w_parser.Read()
                child = _ThreeArgs(w_parser)
                bool_node = bool_expr.LogicalNot(child)
            elif ((a0 == '(') and (w_parser.Peek(3) == ')')):
                w_parser.Read()
                bool_node = _TwoArgs(w_parser)
            else:
                pass
        if (bool_node is None):
            bool_node = b_parser.ParseForBuiltin()
    except error.Parse as e:
        self.errfmt.PrettyPrintError(e, prefix='(test) ')
        return 2
    word_ev = _WordEvaluator()
    bool_ev = sh_expr_eval.BoolEvaluator(self.mem, self.exec_opts, None, self.errfmt)
    bool_ev.Init_AlwaysStrict()
    bool_ev.word_ev = word_ev
    bool_ev.CheckCircularDeps()
    try:
        b = bool_ev.EvalB(bool_node)
    except error._ErrorWithLocation as e:
        self.errfmt.PrettyPrintError(e, prefix='(test) ')
        return 2
    status = (0 if b else 1)
    return status
The test/[ builtin.

The only difference between test and [ is that [ needs a matching ].
def Run(self, cmd_val):
    'The test/[ builtin.\n\n    The only difference between test and [ is that [ needs a matching ].\n    '
    if self.need_right_bracket:
        if self.exec_opts.simple_test_builtin():
            e_usage("should be invoked as 'test' (simple_test_builtin)")
        strs = cmd_val.argv
        if ((not strs) or (strs[(- 1)] != ']')):
            self.errfmt.Print_('missing closing ]', span_id=cmd_val.arg_spids[0])
            return 2
        cmd_val.argv.pop()
        cmd_val.arg_spids.pop()
    w_parser = _StringWordEmitter(cmd_val)
    w_parser.Read()
    b_parser = bool_parse.BoolParser(w_parser)
    bool_node = None
    n = (len(cmd_val.argv) - 1)
    if (self.exec_opts.simple_test_builtin() and (n > 3)):
        e_usage('should only have 3 arguments or fewer (simple_test_builtin)')
    try:
        if (n == 0):
            return 1
        elif (n == 1):
            w = w_parser.Read()
            bool_node = bool_expr.WordTest(w)
        elif (n == 2):
            bool_node = _TwoArgs(w_parser)
        elif (n == 3):
            bool_node = _ThreeArgs(w_parser)
        if (n == 4):
            a0 = w_parser.Peek(0)
            if (a0 == '!'):
                w_parser.Read()
                child = _ThreeArgs(w_parser)
                bool_node = bool_expr.LogicalNot(child)
            elif ((a0 == '(') and (w_parser.Peek(3) == ')')):
                w_parser.Read()
                bool_node = _TwoArgs(w_parser)
            else:
                pass
        if (bool_node is None):
            bool_node = b_parser.ParseForBuiltin()
    except error.Parse as e:
        self.errfmt.PrettyPrintError(e, prefix='(test) ')
        return 2
    word_ev = _WordEvaluator()
    bool_ev = sh_expr_eval.BoolEvaluator(self.mem, self.exec_opts, None, self.errfmt)
    bool_ev.Init_AlwaysStrict()
    bool_ev.word_ev = word_ev
    bool_ev.CheckCircularDeps()
    try:
        b = bool_ev.EvalB(bool_node)
    except error._ErrorWithLocation as e:
        self.errfmt.PrettyPrintError(e, prefix='(test) ')
        return 2
    status = (0 if b else 1)
    return status