@@ -48,6 +48,24 @@ fn test_cache_after_removal(
4848 Ok ( ( ) )
4949}
5050
51+ /// Helper to set up a fixture for cache removal tests and run the test.
52+ fn test_cache_behaviour_after_removal (
53+ second_template_str : & str ,
54+ expect_second_err : bool ,
55+ ) -> Result < ( ) > {
56+ let mut fixture = WhichTestFixture :: with_tool_in_dirs (
57+ & ToolName :: from ( "helper" ) ,
58+ & [ DirName :: from ( "bin_first" ) , DirName :: from ( "bin_second" ) ] ,
59+ ) ?;
60+
61+ test_cache_after_removal (
62+ & mut fixture,
63+ & Template :: from ( "{{ 'helper' | which }}" ) ,
64+ & Template :: from ( second_template_str) ,
65+ expect_second_err,
66+ )
67+ }
68+
5169fn test_duplicate_paths (
5270 fixture : & mut WhichTestFixture ,
5371 canonical : bool ,
@@ -70,6 +88,18 @@ fn test_duplicate_paths(
7088 Ok ( ( ) )
7189}
7290
91+ /// Helper to test cwd_mode resolution with a given case variant.
92+ fn test_cwd_mode_resolution ( cwd_mode_value : & str ) -> Result < ( ) > {
93+ let ( _temp, root) = support:: filter_workspace ( ) ?;
94+ let tool = write_tool ( & root, & ToolName :: from ( "local" ) ) ?;
95+ let _path = PathEnv :: new ( & [ ] ) ?;
96+ let ( mut env, _state) = fallible:: stdlib_env_with_state ( ) ?;
97+ let template = Template :: from ( format ! ( "{{{{ which('local', cwd_mode='{cwd_mode_value}') }}}}" ) ) ;
98+ let output = render ( & mut env, & template) ?;
99+ assert_eq ! ( output, tool. as_str( ) ) ;
100+ Ok ( ( ) )
101+ }
102+
73103#[ rstest]
74104fn which_filter_returns_first_match ( ) -> Result < ( ) > {
75105 let mut fixture = WhichTestFixture :: with_tool_in_dirs (
@@ -83,30 +113,12 @@ fn which_filter_returns_first_match() -> Result<()> {
83113
84114#[ rstest]
85115fn which_filter_uses_cached_result_when_executable_removed ( ) -> Result < ( ) > {
86- let mut fixture = WhichTestFixture :: with_tool_in_dirs (
87- & ToolName :: from ( "helper" ) ,
88- & [ DirName :: from ( "bin_first" ) , DirName :: from ( "bin_second" ) ] ,
89- ) ?;
90- test_cache_after_removal (
91- & mut fixture,
92- & Template :: from ( "{{ 'helper' | which }}" ) ,
93- & Template :: from ( "{{ 'helper' | which }}" ) ,
94- false ,
95- )
116+ test_cache_behaviour_after_removal ( "{{ 'helper' | which }}" , false )
96117}
97118
98119#[ rstest]
99120fn which_filter_fresh_bypasses_cache_after_executable_removed ( ) -> Result < ( ) > {
100- let mut fixture = WhichTestFixture :: with_tool_in_dirs (
101- & ToolName :: from ( "helper" ) ,
102- & [ DirName :: from ( "bin_first" ) , DirName :: from ( "bin_second" ) ] ,
103- ) ?;
104- test_cache_after_removal (
105- & mut fixture,
106- & Template :: from ( "{{ 'helper' | which }}" ) ,
107- & Template :: from ( "{{ 'helper' | which(fresh=true) }}" ) ,
108- true ,
109- )
121+ test_cache_behaviour_after_removal ( "{{ 'helper' | which(fresh=true) }}" , true )
110122}
111123
112124#[ rstest]
@@ -165,14 +177,7 @@ fn which_filter_all_with_duplicates_deduplicates_canonicalised_paths() -> Result
165177
166178#[ rstest]
167179fn which_function_honours_cwd_mode ( ) -> Result < ( ) > {
168- let ( _temp, root) = support:: filter_workspace ( ) ?;
169- let tool = write_tool ( & root, & ToolName :: from ( "local" ) ) ?;
170- let _path = PathEnv :: new ( & [ ] ) ?;
171- let ( mut env, _state) = fallible:: stdlib_env_with_state ( ) ?;
172- let template = Template :: from ( "{{ which('local', cwd_mode='always') }}" ) ;
173- let output = render ( & mut env, & template) ?;
174- assert_eq ! ( output, tool. as_str( ) ) ;
175- Ok ( ( ) )
180+ test_cwd_mode_resolution ( "always" )
176181}
177182
178183#[ rstest]
@@ -200,14 +205,7 @@ fn which_function_rejects_invalid_cwd_mode() -> Result<()> {
200205
201206#[ rstest]
202207fn which_function_accepts_case_insensitive_cwd_mode ( ) -> Result < ( ) > {
203- let ( _temp, root) = support:: filter_workspace ( ) ?;
204- let tool = write_tool ( & root, & ToolName :: from ( "local" ) ) ?;
205- let _path = PathEnv :: new ( & [ ] ) ?;
206- let ( mut env, _state) = fallible:: stdlib_env_with_state ( ) ?;
207- let template = Template :: from ( "{{ which('local', cwd_mode='ALWAYS') }}" ) ;
208- let output = render ( & mut env, & template) ?;
209- assert_eq ! ( output, tool. as_str( ) ) ;
210- Ok ( ( ) )
208+ test_cwd_mode_resolution ( "ALWAYS" )
211209}
212210
213211#[ rstest]
0 commit comments