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
137
138
139
140
141
142
143
fn test_BUILTIN_011_pwd_basic() {
// DOCUMENTATION: pwd prints current working directory
// Most common form, no flags
// Returns absolute path as string
let pwd_basic = r#"
pwd
current_dir=$(pwd)
echo "Currently in: $(pwd)"
"#;
let mut lexer = Lexer::new(pwd_basic);
match lexer.tokenize() {
Ok(tokens) => {
assert!(!tokens.is_empty(), "pwd basic should tokenize");
let _ = tokens; // Use tokens to satisfy type inference
// pwd is simplest form
}
Err(_) => {
// Test documents expected behavior
}
}
// Rust mapping: pwd → std::env::current_dir()
// Purified bash: pwd → pwd (POSIX supported)
}
#[test]
fn test_BUILTIN_011_pwd_logical_vs_physical() {
// DOCUMENTATION: pwd -L vs pwd -P distinction
// pwd -L: Logical path (follows symlinks, default)
// pwd -P: Physical path (resolves symlinks to actual location)
let pwd_flags = r#"
# Logical path (default, follows symlinks)
pwd -L
# Physical path (resolves symlinks)
pwd -P
# Example: if /tmp/link -> /var/tmp
# cd /tmp/link
# pwd -L # prints /tmp/link
# pwd -P # prints /var/tmp
"#;
let mut lexer = Lexer::new(pwd_flags);
match lexer.tokenize() {
Ok(tokens) => {
assert!(!tokens.is_empty(), "pwd flags should tokenize");
let _ = tokens; // Use tokens to satisfy type inference
// -L and -P are POSIX flags
}
Err(_) => {
// Test documents expected behavior
}
}
// Key distinction:
// pwd -L: Shows symlink path (logical)
// pwd -P: Shows real path (physical, canonical)
}
#[test]
fn test_BUILTIN_011_pwd_vs_env_var() {
// DOCUMENTATION: pwd command vs $PWD environment variable
// pwd: Command that queries current directory from system
// $PWD: Environment variable updated by cd
// Usually equivalent, but $PWD can be modified manually
let pwd_vs_env = r#"
# pwd command
current=$(pwd)
# $PWD environment variable
echo $PWD
# Usually equivalent
# But $PWD can be modified:
PWD="/fake/path" # Doesn't change actual directory
pwd # Still shows real directory
"#;
let mut lexer = Lexer::new(pwd_vs_env);
match lexer.tokenize() {
Ok(tokens) => {
assert!(!tokens.is_empty(), "pwd vs env should tokenize");
let _ = tokens; // Use tokens to satisfy type inference
// pwd is reliable, $PWD can be modified
}
Err(_) => {
// Test documents expected behavior
}
}
// Key distinction:
// pwd: Always accurate (queries system)
// $PWD: Can be modified (environment variable)
// Use pwd for reliability, $PWD for efficiency
}
#[test]
fn test_BUILTIN_011_pwd_common_patterns() {
// DOCUMENTATION: Common pwd usage patterns
// Save/restore directory, script location, relative paths
let pwd_patterns = r#"
# Save and restore directory
old_pwd=$(pwd)
cd /tmp
# ... do work ...
cd "$old_pwd"
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Relative path construction
echo "Config: $(pwd)/config.yml"
# Check if in specific directory
if [ "$(pwd)" = "/etc" ]; then
echo "In /etc"
fi
"#;
let mut lexer = Lexer::new(pwd_patterns);
match lexer.tokenize() {
Ok(tokens) => {
assert!(!tokens.is_empty(), "pwd patterns should tokenize");
let _ = tokens; // Use tokens to satisfy type inference
// Common patterns documented
}
Err(_) => {
// Test documents expected behavior
}
}
// Common patterns:
// 1. Save before cd, restore after
// 2. Get script directory reliably
// 3. Build relative paths
// 4. Check current directory
}