tenseleyflow/bensch / ba8e9bc

Browse files

extract fortsh-specific builtin tests

test_abbr, test_defun, test_config, test_memory, test_perf, test_help
These test builtins unique to fortsh (abbreviations, function syntax,
memory pool stats, performance counters).

Source: fortsh/tests/builtins/
Authored by espadonne
SHA
ba8e9bc31845038d752f2e1d898ba7b4e67fa4bc
Parents
4936ef0
Tree
8dd135c

6 changed files

StatusFile+-
A suites/builtins/extended/fortsh/test_abbr.sh 32 0
A suites/builtins/extended/fortsh/test_config.sh 12 0
A suites/builtins/extended/fortsh/test_defun.sh 27 0
A suites/builtins/extended/fortsh/test_help.sh 9 0
A suites/builtins/extended/fortsh/test_memory.sh 10 0
A suites/builtins/extended/fortsh/test_perf.sh 12 0
suites/builtins/extended/fortsh/test_abbr.shadded
@@ -0,0 +1,32 @@
1
+#!/bin/sh
2
+TEST_PREFIX="[abbr]"
3
+. "$(cd "$(dirname "$0")" && pwd)/test_harness.sh"
4
+
5
+section "1. abbr define"
6
+check_exit "abbr with no args succeeds" 'abbr' "0"
7
+check_exit "abbr define abbreviation" 'abbr gs="git status"' "0"
8
+check_exit "abbr define with spaces in value" 'abbr ll="ls -la --color"' "0"
9
+check_exit "abbr define single char" 'abbr g="git"' "0"
10
+check_exit "abbr define with path" 'abbr vi="/usr/bin/vim"' "0"
11
+
12
+section "2. abbr show"
13
+check_output "abbr shows defined abbr" 'abbr gs="git status"; abbr gs' "gs = git status"
14
+check_exit "abbr -s shows all" 'abbr gs="git status"; abbr -s' "0"
15
+check_exit "abbr --show shows all" 'abbr gs="git status"; abbr --show' "0"
16
+check_exit "abbr show nonexistent" 'abbr nonexistent_xyz 2>/dev/null; true' "0"
17
+check_output "abbr shows multiple" 'abbr a1="echo 1"; abbr a2="echo 2"; abbr -s | wc -l | tr -d " "' "2"
18
+
19
+section "3. abbr erase"
20
+check_exit "abbr -e removes abbreviation" 'abbr gs="git status"; abbr -e gs' "0"
21
+check_exit "abbr --erase removes abbreviation" 'abbr gs="git status"; abbr --erase gs' "0"
22
+check_exit "abbr -e nonexistent" 'abbr -e nonexistent_xyz 2>/dev/null; true' "0"
23
+check_output "abbr -e then show is gone" 'abbr gs="git status"; abbr -e gs; abbr gs 2>/dev/null; echo $?' "1"
24
+
25
+section "4. abbr overwrite and edge cases"
26
+check_exit "abbr overwrite existing" 'abbr gs="git status"; abbr gs="git stash"' "0"
27
+check_output "abbr overwrite changes value" 'abbr gs="git status"; abbr gs="git stash"; abbr gs' "gs = git stash"
28
+check_exit "abbr with quoted value double" 'abbr ll="ls -la"' "0"
29
+check_exit "abbr with quoted value single" "abbr ll='ls -la'" "0"
30
+check_exit "abbr with equals in value" 'abbr myvar="export FOO=bar"' "0"
31
+
32
+print_summary
suites/builtins/extended/fortsh/test_config.shadded
@@ -0,0 +1,12 @@
1
+#!/bin/sh
2
+TEST_PREFIX="[config]"
3
+. "$(cd "$(dirname "$0")" && pwd)/test_harness.sh"
4
+
5
+section "1. config display"
6
+check_exit "config show exits successfully" 'config show' "0"
7
+check_exit "config with no args shows config" 'config' "0"
8
+
9
+section "2. config operations"
10
+check_exit "config reload" 'config reload 2>/dev/null; true' "0"
11
+
12
+print_summary
suites/builtins/extended/fortsh/test_defun.shadded
@@ -0,0 +1,27 @@
1
+#!/bin/sh
2
+TEST_PREFIX="[defun]"
3
+. "$(cd "$(dirname "$0")" && pwd)/test_harness.sh"
4
+
5
+# defun is a fortsh-specific alternate syntax for function definitions
6
+
7
+section "1. defun basic"
8
+check_exit "defun defines a function" 'defun greet echo hello; greet' "0"
9
+check_output "defun function produces output" 'defun greet echo hello; greet' "hello"
10
+check_exit "defun with no args shows usage" 'defun 2>/dev/null; true' "0"
11
+
12
+section "2. defun with arguments"
13
+check_output "defun function receives args" 'defun say echo; say hello world' "hello world"
14
+check_output "defun function uses dollar-1" 'defun greet echo "hi $1"; greet alice' "hi alice"
15
+
16
+section "3. defun overwrite and unset"
17
+check_output "defun overwrites existing function" 'defun f echo old; defun f echo new; f' "new"
18
+check_output "unset -f removes defun function" 'defun f echo test; unset -f f; f 2>/dev/null; echo $?' "127"
19
+check_output "type shows defun as function" 'defun myfunc echo hi; type myfunc 2>/dev/null | head -1' "myfunc is a function"
20
+
21
+section "4. defun edge cases"
22
+check_output "defun with special chars in body" 'defun f echo "hello world"; f' "hello world"
23
+check_output "defun called multiple times" 'defun f echo ok; f; f; f' "ok
24
+ok
25
+ok"
26
+
27
+print_summary
suites/builtins/extended/fortsh/test_help.shadded
@@ -0,0 +1,9 @@
1
+#!/bin/sh
2
+TEST_PREFIX="[help]"
3
+. "$(cd "$(dirname "$0")" && pwd)/test_harness.sh"
4
+
5
+section "1. help output"
6
+check_exit "help exits successfully" 'help' "0"
7
+check_output "help produces output" 'help | head -1 | grep -q . && echo yes' "yes"
8
+
9
+print_summary
suites/builtins/extended/fortsh/test_memory.shadded
@@ -0,0 +1,10 @@
1
+#!/bin/sh
2
+TEST_PREFIX="[memory]"
3
+. "$(cd "$(dirname "$0")" && pwd)/test_harness.sh"
4
+
5
+section "1. memory commands"
6
+check_exit "memory with no args" 'memory' "0"
7
+check_exit "memory stats" 'memory stats' "0"
8
+check_exit "memory optimize" 'memory optimize' "0"
9
+
10
+print_summary
suites/builtins/extended/fortsh/test_perf.shadded
@@ -0,0 +1,12 @@
1
+#!/bin/sh
2
+TEST_PREFIX="[perf]"
3
+. "$(cd "$(dirname "$0")" && pwd)/test_harness.sh"
4
+
5
+section "1. perf commands"
6
+check_exit "perf with no args" 'perf' "0"
7
+check_exit "perf on enables monitoring" 'perf on' "0"
8
+check_exit "perf off disables monitoring" 'perf off' "0"
9
+check_exit "perf stats shows statistics" 'perf stats' "0"
10
+check_exit "perf reset clears counters" 'perf reset' "0"
11
+
12
+print_summary