5
5
6
6
use super :: common:: * ;
7
7
use std:: { fs, thread:: sleep, time:: Duration } ;
8
- use tempfile:: TempDir ;
9
8
10
9
// ANSI escape sequences for function keys
11
10
const F8_KEY : & str = "\x1b [19~" ;
12
11
const F9_KEY : & str = "\x1b [20~" ;
13
12
13
+ /// Helper to create a custom cable directory with external actions.
14
+ fn write_toml_config (
15
+ cable_dir : & std:: path:: Path ,
16
+ filename : & str ,
17
+ content : & str ,
18
+ ) {
19
+ let toml_path = cable_dir. join ( filename) ;
20
+ fs:: write ( & toml_path, content) . unwrap ( ) ;
21
+ }
22
+
14
23
/// Tests that external actions execute properly when triggered by keybindings.
15
24
#[ test]
16
25
fn test_external_action_lsman_with_f9 ( ) {
17
26
let mut tester = PtyTester :: new ( ) ;
18
27
19
- // Create a temporary directory for the custom cable
20
- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
21
- let cable_dir = temp_dir . path ( ) ;
28
+ // Use TARGET_DIR for consistency with other tests
29
+ let cable_dir = std :: path :: Path :: new ( TARGET_DIR ) . join ( "custom_cable" ) ;
30
+ fs :: create_dir_all ( & cable_dir) . unwrap ( ) ;
22
31
23
32
// Create a custom files.toml with external actions
24
33
let files_toml_content = r#"
@@ -49,8 +58,7 @@ description = "show stats"
49
58
command = "ls '{}'"
50
59
"# ;
51
60
52
- let files_toml_path = cable_dir. join ( "files.toml" ) ;
53
- fs:: write ( & files_toml_path, files_toml_content) . unwrap ( ) ;
61
+ write_toml_config ( & cable_dir, "files.toml" , files_toml_content) ;
54
62
55
63
// Use the LICENSE file as input since it exists in the repo
56
64
let mut cmd = tv ( ) ;
@@ -82,9 +90,8 @@ command = "ls '{}'"
82
90
fn test_external_action_thebatman_with_f8 ( ) {
83
91
let mut tester = PtyTester :: new ( ) ;
84
92
85
- // Create a temporary directory for the custom cable
86
- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
87
- let cable_dir = temp_dir. path ( ) ;
93
+ let cable_dir = std:: path:: Path :: new ( TARGET_DIR ) . join ( "custom_cable_f8" ) ;
94
+ fs:: create_dir_all ( & cable_dir) . unwrap ( ) ;
88
95
89
96
// Create a custom files.toml with external actions
90
97
let files_toml_content = r#"
@@ -115,8 +122,7 @@ description = "show stats"
115
122
command = "ls '{}'"
116
123
"# ;
117
124
118
- let files_toml_path = cable_dir. join ( "files.toml" ) ;
119
- fs:: write ( & files_toml_path, files_toml_content) . unwrap ( ) ;
125
+ write_toml_config ( & cable_dir, "files.toml" , files_toml_content) ;
120
126
121
127
// Use the LICENSE file as input since it exists in the repo
122
128
let mut cmd = tv ( ) ;
@@ -141,3 +147,4 @@ command = "ls '{}'"
141
147
// Check that the process has finished
142
148
PtyTester :: assert_exit_ok ( & mut child, DEFAULT_DELAY ) ;
143
149
}
150
+
0 commit comments