22
22
single_dir_and_single_suite /1 ,
23
23
suite_at_root /1 ,
24
24
suite_at_app_root /1 ,
25
+ data_in_app_test_folder /1 ,
25
26
data_dir_correct /1 ,
26
27
cmd_label /1 ,
27
28
cmd_config /1 ,
63
64
64
65
-include_lib (" eunit/include/eunit.hrl" ).
65
66
-include_lib (" common_test/include/ct.hrl" ).
67
+ -include_lib (" kernel/include/file.hrl" ).
68
+
66
69
67
70
all () -> [{group , basic_app },
68
71
{group , multi_app },
@@ -100,7 +103,8 @@ groups() -> [{basic_app, [], [basic_app_default_dirs,
100
103
all_suite ,
101
104
single_dir_and_single_suite ,
102
105
suite_at_root ,
103
- suite_at_app_root ]},
106
+ suite_at_app_root ,
107
+ data_in_app_test_folder ]},
104
108
{data_dirs , [], [data_dir_correct ]},
105
109
{ct_opts , [], [cmd_label ,
106
110
cmd_config ,
@@ -193,6 +197,11 @@ init_per_group(dirs_and_suites, Config) ->
193
197
AppDir1 = filename :join ([AppDir , " apps" , Name1 ]),
194
198
rebar_test_utils :create_app (AppDir1 , Name1 , Vsn1 , [kernel , stdlib ]),
195
199
200
+ ok = file :write_file (
201
+ filename :join ([AppDir , " some_data_in_root.txt" ]),
202
+ <<" I'm the content of a file in the root folder" >>
203
+ ),
204
+
196
205
Suite1 = filename :join ([AppDir1 , " test" , Name1 ++ " _SUITE.erl" ]),
197
206
ok = filelib :ensure_dir (Suite1 ),
198
207
ok = file :write_file (Suite1 , test_suite (Name1 )),
@@ -205,6 +214,13 @@ init_per_group(dirs_and_suites, Config) ->
205
214
Suite2 = filename :join ([AppDir2 , " test" , Name2 ++ " _SUITE.erl" ]),
206
215
ok = filelib :ensure_dir (Suite2 ),
207
216
ok = file :write_file (Suite2 , test_suite (Name2 )),
217
+ ok = filelib :ensure_dir (filename :join ([AppDir2 , " test" , Name2 ++ " _SUITE_data" , " dummy.txt" ])),
218
+ ok = file :write_file (filename :join ([AppDir2 , " test" , Name2 ++ " _SUITE_data" , " some_data.txt" ]), <<" hello" >>),
219
+ ok = file :make_symlink (
220
+ filename :join ([AppDir , " some_data_in_root.txt" ]),
221
+ filename :join ([AppDir2 , " test" , Name2 ++ " _SUITE_data" , " symlink_some_data_in_root.txt" ])
222
+ ),
223
+
208
224
209
225
Suite3 = filename :join ([AppDir , " test" , " extras_SUITE.erl" ]),
210
226
ok = filelib :ensure_dir (Suite3 ),
@@ -225,6 +241,10 @@ init_per_group(dirs_and_suites, Config) ->
225
241
226
242
ok = filelib :ensure_dir (filename :join ([AppDir , " apps" , Name2 , " app_root_SUITE_data" , " dummy.txt" ])),
227
243
ok = file :write_file (filename :join ([AppDir , " apps" , Name2 , " app_root_SUITE_data" , " some_data.txt" ]), <<>>),
244
+ ok = file :make_symlink (
245
+ filename :join ([AppDir , " some_data_in_root.txt" ]),
246
+ filename :join ([AppDir , " apps" , Name2 , " app_root_SUITE_data" , " symlink_some_data_in_root.txt" ])
247
+ ),
228
248
229
249
{ok , State } = rebar_test_utils :run_and_check (C , [], [" as" , " test" , " lock" ], return ),
230
250
@@ -787,6 +807,12 @@ suite_at_app_root(Config) ->
787
807
DataFile = filename :join ([AppDir , " _build" , " test" , " lib" , Name2 , " app_root_SUITE_data" , " some_data.txt" ]),
788
808
true = filelib :is_file (DataFile ),
789
809
810
+ SymFile = filename :join ([AppDir , " _build" , " test" , " lib" , Name2 , " app_root_SUITE_data" , " symlink_some_data_in_root.txt" ]),
811
+ true = filelib :is_file (SymFile ),
812
+ % At this point, the symbolic link should have been dereference and it is a regular file
813
+ {ok , # file_info {type = regular }} = file :read_link_info (SymFile ),
814
+ ? assertEqual ({ok , <<" I'm the content of a file in the root folder" >>}, file :read_file (SymFile )),
815
+
790
816
% % Same test again using relative path to the suite from the project root
791
817
{ok ,Cwd } = file :get_cwd (),
792
818
ok = file :set_cwd (AppDir ),
@@ -812,6 +838,54 @@ suite_at_app_root(Config) ->
812
838
813
839
ok .
814
840
841
+ data_in_app_test_folder (Config ) ->
842
+ % the ct data folder in app_name/test is properly copied to destination
843
+ AppDir = ? config (apps , Config ),
844
+ [_Name1 , Name2 ] = ? config (appnames , Config ),
845
+ State = ? config (s , Config ),
846
+
847
+ LibDirs = rebar_dir :lib_dirs (State ),
848
+ State1 = rebar_app_discover :do (State , LibDirs ),
849
+
850
+ Providers = rebar_state :providers (State1 ),
851
+ Namespace = rebar_state :namespace (State1 ),
852
+ CommandProvider = providers :get_provider (ct , Providers , Namespace ),
853
+ GetOptSpec = providers :opts (CommandProvider ),
854
+ {ok , GetOptResult } = getopt :parse (GetOptSpec ,
855
+ [" --suite=" ++ filename :join ([AppDir ,
856
+ " apps" ,
857
+ Name2 ,
858
+ " test" ,
859
+ Name2 ++ " _SUITE" ])]),
860
+ State2 = rebar_state :command_parsed_args (State1 , GetOptResult ),
861
+ Tests = rebar_prv_common_test :prepare_tests (State2 ),
862
+ {ok , NewState } = rebar_prv_common_test :compile (State2 , Tests ),
863
+ {ok , T } = Tests ,
864
+ _Opts = rebar_prv_common_test :translate_paths (NewState , T ),
865
+ DataFile = filename :join ([AppDir ,
866
+ " _build" ,
867
+ " test" ,
868
+ " lib" ,
869
+ Name2 ,
870
+ " test" ,
871
+ Name2 ++ " _SUITE_data" ,
872
+ " some_data.txt" ]),
873
+
874
+ true = filelib :is_file (DataFile ),
875
+ ? assertEqual ({ok , <<" hello" >>}, file :read_file (DataFile )),
876
+
877
+ SymFile = filename :join ([AppDir ,
878
+ " _build" ,
879
+ " test" ,
880
+ " lib" ,
881
+ Name2 ,
882
+ " test" ,
883
+ Name2 ++ " _SUITE_data" ,
884
+ " symlink_some_data_in_root.txt" ]),
885
+ % At this point, the symbolic link should have been dereference and it is a regular file
886
+ {ok , # file_info {type = regular }} = file :read_link_info (SymFile ),
887
+ ? assertEqual ({ok , <<" I'm the content of a file in the root folder" >>}, file :read_file (SymFile )).
888
+
815
889
% % this test probably only fails when this suite is run via rebar3 with the --cover flag
816
890
data_dir_correct (Config ) ->
817
891
DataDir = ? config (data_dir , Config ),
0 commit comments