@@ -9,7 +9,7 @@ suite() ->
99 [].
1010
1111all () ->
12- [test_completion_gen , check_bash , check_zsh ].
12+ [test_completion_gen , check_bash , check_zsh , check_bash_file_completion ].
1313
1414groups () ->
1515 [].
@@ -30,6 +30,13 @@ init_per_testcase(check_bash, Config) ->
3030 false ->
3131 {skip , " bash not found" }
3232 end ;
33+ init_per_testcase (check_bash_file_completion , Config ) ->
34+ case shell_available (bash ) of
35+ true ->
36+ rebar_test_utils :init_rebar_state (Config , " completion_" );
37+ false ->
38+ {skip , " bash not found" }
39+ end ;
3340init_per_testcase (check_zsh , Config ) ->
3441 case shell_available (zsh ) of
3542 true ->
@@ -69,7 +76,7 @@ check_bash(Config) ->
6976 % % function definition
7077 {match , _ } = re :run (Completion , " _rebar3\\ (\\ )\\ {" ),
7178 % % aliases
72- CompleteCmd = " complete -o nospace -F _rebar3 " ,
79+ CompleteCmd = " complete -o filenames -F _rebar3 " ,
7380 lists :foreach (fun (Alias ) ->
7481 ? assertMatch ({Alias , {match , _ }}, {Alias , re :run (Completion , CompleteCmd ++ Alias ++ " \n " )})
7582 end ,
@@ -91,6 +98,27 @@ check_zsh(Config) ->
9198 end ,
9299 [" rebar3" | Aliases ]).
93100
101+ check_bash_file_completion (Config ) ->
102+ ComplFile = ? config (compl_file , Config ),
103+ Opts = #{shell => bash , file => ComplFile },
104+ completion_gen (Config , Opts ),
105+ {ok , Completion } = file :read_file (ComplFile ),
106+
107+ % % Check that file completion logic is present for ct and eunit
108+ {match , _ } = re :run (Completion , " \\ $\\ {prev1\\ } == ct \\ |\\ | \\ $\\ {prev1\\ } == eunit" ),
109+
110+ % % Check that .erl file completion is included
111+ {match , _ } = re :run (Completion , " compgen -f -X '!\\ *\\ .erl'" ),
112+
113+ % % Check that directory completion is included
114+ {match , _ } = re :run (Completion , " compgen -d" ),
115+
116+ % % Check that other file-accepting commands are handled
117+ {match , _ } = re :run (Completion , " \\ $\\ {prev1\\ } == completion \\ |\\ | \\ $\\ {prev1\\ } == shell \\ |\\ | \\ $\\ {prev1\\ } == tar" ),
118+
119+ % % Check that fallback completion is present
120+ {match , _ } = re :run (Completion , " If no completions found, fall back to normal completion" ).
121+
94122% % helpers
95123
96124completion_gen (Config , CmplOpts ) ->
0 commit comments