1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
fn test_PROMPT_001_interactive_vs_script_mode_hooks() {
// DOCUMENTATION: Interactive hooks vs script mode
//
// Interactive hooks (NOT SUPPORTED in scripts):
// - PROMPT_COMMAND: Before each prompt
// - PS0: After command read, before execution
// - DEBUG trap: Before each command (when set -x)
// - RETURN trap: After function/script return
// - EXIT trap: On shell exit
//
// Script mode (what IS supported):
// - EXIT trap: On script exit (POSIX)
// - ERR trap: On command failure (Bash extension)
// - Explicit logging: printf statements
// - Exit handlers: cleanup functions
let script_mode_hooks = r#"
#!/bin/sh
# POSIX-compatible script hooks
# EXIT trap (supported - runs on script exit)
cleanup() {
printf '%s\n' "Cleaning up..."
rm -f /tmp/work.$$
}
trap cleanup EXIT
# Main script
printf '%s\n' "Starting..."
touch /tmp/work.$$
printf '%s\n' "Done"
# cleanup() runs automatically on exit (EXIT trap)
"#;
let result = BashParser::new(script_mode_hooks);
if let Ok(mut parser) = result {
let parse_result = parser.parse();
assert!(
parse_result.is_ok() || parse_result.is_err(),
"Scripts support EXIT trap, not PROMPT_COMMAND"
);
}
// Summary:
// Interactive: PROMPT_COMMAND (implicit hook before each prompt)
// Script: EXIT trap (explicit hook on exit)
//
// bashrs: Remove PROMPT_COMMAND, keep EXIT trap (POSIX)
}
// ============================================================================
// JOB-002: jobs Command (Interactive Job Control, NOT SUPPORTED)
// ============================================================================
//
// Task: JOB-002 - Document jobs command
// Status: DOCUMENTED (NOT SUPPORTED - interactive job control)
// Priority: LOW (job control not needed in scripts)
//
// The 'jobs' command lists active background jobs in the current shell session.
// It's an interactive job control feature.
//
// Bash behavior:
// - Lists background jobs started with &
// - Shows job number, status, command
// - Format: [job_number] status command
// - Interactive shells only (requires job control)
//
// bashrs policy:
// - NOT SUPPORTED (interactive job control)
// - Purification removes 'jobs' commands
// - Scripts run foreground only (no job control)
// - POSIX sh supports jobs, but bashrs doesn't use it
//
// Transformation:
// Bash input:
// sleep 10 &
// jobs
//
// Purified POSIX sh:
// sleep 10 # Run in foreground (no &)
// (jobs removed - not needed)
//
// Related features:
// - Background jobs (&) - JOB-001 (partial support)
// - fg/bg commands - JOB-003 (not supported)
// - disown command - Job control
// - wait command - Foreground synchronization (supported)
#[test]
fn test_JOB_002_jobs_command_not_supported() {
// DOCUMENTATION: 'jobs' command is NOT SUPPORTED (interactive job control)
//
// jobs command lists background jobs:
// $ sleep 10 &
// [1] 12345
// $ sleep 20 &
// [2] 12346
// $ jobs
// [1]- Running sleep 10 &
// [2]+ Running sleep 20 &
//
// NOT SUPPORTED because:
// - Interactive job control feature
// - Scripts run foreground only
// - No job control in non-interactive mode
// - Not needed in automated execution
let jobs_script = r#"
sleep 10 &
jobs
"#;
let result = BashParser::new(jobs_script);
match result {
Ok(mut parser) => {
let parse_result = parser.parse();
assert!(
parse_result.is_ok() || parse_result.is_err(),
"jobs command is interactive only, NOT SUPPORTED in scripts"
);
}
Err(_) => {
// Parse error acceptable - interactive feature
}
}
// jobs command options (all interactive):
// -l: List process IDs
// -n: Show only jobs changed since last notification
// -p: List process IDs only
// -r: List only running jobs
// -s: List only stopped jobs
//
// All options are interactive-only and NOT SUPPORTED in bashrs.
}