Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/alias.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# Alias tests
# Inspired by Oils spec/alias.test.sh
# https://github.com/oilshell/oil/blob/master/spec/alias.test.sh

### alias_basic
# Basic alias definition and use
### skip: TODO alias expansion not implemented
shopt -s expand_aliases
alias hi='echo hello world'
hi
### expect
hello world
### end

### alias_override_builtin
# alias can override builtin
### skip: TODO alias expansion not implemented
shopt -s expand_aliases
alias echo='echo foo'
echo bar
### expect
foo bar
### end

### alias_define_multiple
# defining multiple aliases
### skip: TODO alias expansion not implemented
shopt -s expand_aliases
alias echo_x='echo X' echo_y='echo Y'
echo_x
echo_y
### expect
X
Y
### end

### alias_unalias
# unalias removes alias
### skip: TODO alias expansion not implemented
shopt -s expand_aliases
alias hi='echo hello'
hi
unalias hi
hi 2>/dev/null
echo status=$?
### expect
hello
status=127
### end

### alias_unalias_all
# unalias -a removes all
### skip: TODO alias expansion not implemented
alias foo=bar
alias spam=eggs
unalias -a
alias 2>/dev/null | wc -l
### expect
0
### end

### alias_not_defined_error
# alias for non-existent returns error
### skip: TODO alias expansion not implemented
alias nonexistentZZZ 2>/dev/null
echo status=$?
### expect
status=1
### end

### alias_unalias_not_defined_error
# unalias for non-existent returns error
### skip: TODO alias expansion not implemented
unalias nonexistentZZZ 2>/dev/null
echo status=$?
### expect
status=1
### end

### alias_with_variable
# Alias with variable expansion at use-time
### skip: TODO alias expansion not implemented
shopt -s expand_aliases
x=early
alias echo_x='echo $x'
x=late
echo_x
### expect
late
### end

### alias_trailing_space
# alias with trailing space triggers expansion of next word
### skip: TODO alias expansion not implemented
shopt -s expand_aliases
alias hi='echo hello world '
alias punct='!!!'
hi punct
### expect
hello world !!!
### end

### alias_recursive_first_word
# Recursive alias expansion of first word
### skip: TODO alias expansion not implemented
shopt -s expand_aliases
alias hi='e_ hello world'
alias e_='echo __'
hi
### expect
__ hello world
### end

### alias_must_be_unquoted
# Alias must be an unquoted word
### skip: TODO alias expansion not implemented
shopt -s expand_aliases
alias echo_alias_='echo'
cmd=echo_alias_
echo_alias_ X
$cmd X 2>/dev/null
echo status=$?
### expect
X
status=127
### end

### alias_in_pipeline
# Two aliases in pipeline
### skip: TODO alias expansion not implemented
shopt -s expand_aliases
alias myseq='seq '
alias mywc='wc '
myseq 3 | mywc -l
### expect
3
### end

### alias_used_in_subshell
# alias used in subshell
### skip: TODO alias expansion not implemented
shopt -s expand_aliases
alias echo_='echo [ '
( echo_ subshell; )
echo $(echo_ commandsub)
### expect
[ subshell
[ commandsub
### end

### alias_with_semicolon_pipeline
# Alias that is && || ;
### skip: TODO alias expansion not implemented
shopt -s expand_aliases
alias t1='echo one && echo two'
t1
### expect
one
two
### end

### alias_list_all
# alias without args lists all
### skip: TODO alias expansion not implemented
alias ex=exit ll='ls -l'
alias | grep -c 'ex\|ll'
### expect
2
### end
138 changes: 138 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/arith-dynamic.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Dynamic arithmetic tests
# Inspired by Oils spec/arith-dynamic.test.sh
# https://github.com/oilshell/oil/blob/master/spec/arith-dynamic.test.sh

### arith_dyn_var_reference
# Variable references in arithmetic
x='1'
echo $(( x + 2 * 3 ))
### expect
7
### end

### arith_dyn_var_expression
# Variable containing expression is re-evaluated
### skip: TODO arithmetic variable re-evaluation of expressions not implemented
x='1 + 2'
echo $(( x * 3 ))
### expect
9
### end

### arith_dyn_substitution
# $x in arithmetic
x='1 + 2'
echo $(( $x * 3 ))
### expect
7
### end

### arith_dyn_quoted_substitution
# "$x" in arithmetic
### skip: TODO double-quoted substitution in arithmetic not implemented
x='1 + 2'
echo $(( "$x" * 3 ))
### expect
7
### end

### arith_dyn_nested_var
# Nested variable reference in arithmetic
### skip: TODO recursive variable dereferencing in arithmetic not implemented
a=3
b=a
echo $(( b + 1 ))
### expect
4
### end

### arith_dyn_array_index
# Dynamic array index
### skip: TODO array access in arithmetic expressions not implemented
arr=(10 20 30 40)
i=2
echo $(( arr[i] ))
### expect
30
### end

### arith_dyn_array_index_expr
# Expression as array index
### skip: TODO array access in arithmetic expressions not implemented
arr=(10 20 30 40)
echo $(( arr[1+1] ))
### expect
30
### end

### arith_dyn_conditional
# Ternary operator
x=5
echo $(( x > 3 ? 1 : 0 ))
echo $(( x < 3 ? 1 : 0 ))
### expect
1
0
### end

### arith_dyn_comma
# Comma operator
echo $(( 1, 2, 3 ))
### expect
3
### end

### arith_dyn_assign_in_expr
# Assignment within arithmetic expression
echo $(( x = 5 + 3 ))
echo $x
### expect
8
8
### end

### arith_dyn_pre_post_increment
# Pre/post increment in dynamic context
x=5
echo $(( x++ ))
echo $x
echo $(( ++x ))
echo $x
### expect
5
6
7
7
### end

### arith_dyn_compound_assign
# Compound assignment operators
x=10
echo $(( x += 5 ))
echo $(( x -= 3 ))
echo $(( x *= 2 ))
echo $(( x /= 4 ))
echo $(( x %= 2 ))
### expect
15
12
24
6
0
### end

### arith_dyn_unset_var_is_zero
# Unset variable in arithmetic treated as 0
unset arith_undef_xyz
echo $(( arith_undef_xyz + 5 ))
### expect
5
### end

### arith_dyn_string_var_is_zero
# Non-numeric string in arithmetic treated as 0
x=hello
echo $(( x + 5 ))
### expect
5
### end
90 changes: 90 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/empty-bodies.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Empty body tests
# Inspired by Oils spec/empty-bodies.test.sh
# https://github.com/oilshell/oil/blob/master/spec/empty-bodies.test.sh

### empty_case_esac
# Empty case/esac is valid
case foo in
esac
echo empty
### expect
empty
### end

### empty_while_do_done
# Empty while body - bash treats as parse error, bashkit allows it
### skip: TODO empty while body not rejected as parse error
bash -c 'while false; do
done
echo empty' 2>/dev/null
echo status=$?
### expect
status=2
### end

### empty_if_then_fi
# Empty then body - bash treats as parse error, bashkit allows it
### skip: TODO empty if body not rejected as parse error
bash -c 'if true; then
fi
echo empty' 2>/dev/null
echo status=$?
### expect
status=2
### end

### empty_else_clause
# Empty else clause - bash treats as parse error, bashkit allows it
### skip: TODO empty else body not rejected as parse error
bash -c 'if false; then echo yes; else
fi' 2>/dev/null
echo status=$?
### expect
status=2
### end

### empty_for_body
# Empty for body - bash treats as parse error, bashkit allows it
### skip: TODO empty for body not rejected as parse error
bash -c 'for i in 1 2 3; do
done' 2>/dev/null
echo status=$?
### expect
status=2
### end

### empty_function_body
# Empty function body - bash treats as parse error, bashkit allows it
### skip: TODO empty function body not rejected as parse error
bash -c 'f() { }' 2>/dev/null
echo status=$?
### expect
status=2
### end

### case_with_empty_clause
# case with empty clauses is valid
case foo in
bar)
;;
foo)
echo matched
;;
esac
### expect
matched
### end

### case_empty_fallthrough
# case with empty clause and fallthrough
case x in
x)
;;
*)
echo no
;;
esac
echo done
### expect
done
### end
Loading
Loading