Permalink
Browse files

Implement 'type' without -t.

Addresses issue #61 (abuild uses this.)
  • Loading branch information...
Andy Chu
Andy Chu committed Jan 9, 2018
1 parent 5a09f28 commit 4d332f7a22730a9e53aa3156f71d55d32e4f4c73
Showing with 26 additions and 11 deletions.
  1. +12 −7 core/builtin.py
  2. +0 −4 core/cmd_exec.py
  3. +9 −0 gold/abuild.sh
  4. +5 −0 test/gold.sh
View
@@ -931,16 +931,21 @@ def Type(argv, funcs, path_val):
arg, i = TYPE_SPEC.Parse(argv)
status = 0
if not arg.t:
util.warn("*** 'type' builtin called without -t ***")
status = 1
# Keep going anyway
for kind, arg in _ResolveNames(argv[i:], funcs, path_val):
for kind, name in _ResolveNames(argv[i:], funcs, path_val):
if kind is None:
status = 1 # nothing printed, but we fail
else:
print(kind)
if arg.t:
print(kind)
else:
# Alpine's abuild relies on this text because busybox ash doesn't have
# -t!
# ash prints "is a shell function" instead of "is a function", but the
# regex accouts for that.
print('%s is a %s' % (name, kind))
if kind == 'function':
# bash prints the function body, busybox ash doesn't.
pass
return status
View
@@ -668,10 +668,6 @@ def _Dispatch(self, node, fork_external):
if node.more_env:
self.mem.PopTemp()
if self.exec_opts.xtrace:
#log('+ %s -> %d', argv, status)
pass
elif node.tag == command_e.Sentence:
# Don't check_errexit since this isn't a real node!
if node.terminator.id == Id.Op_Semi:
View
@@ -0,0 +1,9 @@
#!/bin/bash
#
# Snippets from abuild that we need to run correctly.
is_function() {
type "$1" 2>&1 | head -n 1 | egrep -q "is a (shell )?function"
}
"$@"
View
@@ -96,6 +96,10 @@ strip-op-char-class() { _compare gold/strip-op-char-class.sh; }
echo-e() { _compare gold/echo-e.sh; }
dollar-sq() { _compare gold/dollar-sq.sh; }
abuild() {
_compare gold/abuild.sh is_function is_function
}
# Needs declare -p
declare() { _compare gold/declare.sh demo; }
@@ -118,6 +122,7 @@ readonly -a PASSING=(
no-op
complex-here-docs
strip-op-char-class
abuild
count
one-spec-test

0 comments on commit 4d332f7

Please sign in to comment.