@@ -39,6 +39,7 @@ class TestFileLister : public TestFixture {
3939 TEST_CASE (recursiveAddFilesEmptyPath);
4040 TEST_CASE (excludeFile1);
4141 TEST_CASE (excludeFile2);
42+ TEST_CASE (addFiles);
4243 }
4344
4445 // TODO: generate file list instead
@@ -81,11 +82,25 @@ class TestFileLister : public TestFixture {
8182 };
8283
8384 // Make sure source files are added..
84- ASSERT (find_file (dirprefix + " cli/main.cpp" ) != files.end ());
85- ASSERT (find_file (dirprefix + " lib/token.cpp" ) != files.end ());
86- ASSERT (find_file (dirprefix + " lib/tokenize.cpp" ) != files.end ());
87- ASSERT (find_file (dirprefix + " gui/main.cpp" ) != files.end ());
88- ASSERT (find_file (dirprefix + " test/testfilelister.cpp" ) != files.end ());
85+ auto it = find_file (dirprefix + " cli/main.cpp" );
86+ ASSERT (it != files.end ());
87+ ASSERT_EQUALS_ENUM (Standards::Language::CPP, it->lang ());
88+
89+ it = find_file (dirprefix + " lib/token.cpp" );
90+ ASSERT (it != files.end ());
91+ ASSERT_EQUALS_ENUM (Standards::Language::CPP, it->lang ());
92+
93+ it = find_file (dirprefix + " lib/tokenize.cpp" );
94+ ASSERT (it != files.end ());
95+ ASSERT_EQUALS_ENUM (Standards::Language::CPP, it->lang ());
96+
97+ it = find_file (dirprefix + " gui/main.cpp" );
98+ ASSERT (it != files.end ());
99+ ASSERT_EQUALS_ENUM (Standards::Language::CPP, it->lang ());
100+
101+ it = find_file (dirprefix + " test/testfilelister.cpp" );
102+ ASSERT (it != files.end ());
103+ ASSERT_EQUALS_ENUM (Standards::Language::CPP, it->lang ());
89104
90105 // Make sure headers are not added..
91106 ASSERT (find_file (dirprefix + " lib/tokenize.h" ) == files.end ());
@@ -120,7 +135,65 @@ class TestFileLister : public TestFixture {
120135 ASSERT_EQUALS (basedir + " lib/token.cpp" , files.begin ()->path ());
121136 }
122137
138+ void addFiles () const {
139+ const std::string adddir = findBaseDir () + " ." ;
140+
141+ // TODO: on Windows the prefix is different from when a recursive a folder (see recursiveAddFiles test)
142+ const std::string dirprefix = adddir + " /" ;
143+ #ifdef _WIN32
144+ const std::string dirprefix_nat = Path::toNativeSeparators (dirprefix);
145+ #endif
146+
147+ std::list<FileWithDetails> files;
148+
149+ {
150+ const std::string addfile = Path::join (Path::join (adddir, " cli" ), " main.cpp" );
151+ const std::string err = FileLister::addFiles (files, addfile, {}, true ,PathMatch ({}));
152+ ASSERT_EQUALS (" " , err);
153+ }
154+ {
155+ const std::string addfile = Path::join (Path::join (adddir, " lib" ), " token.cpp" );
156+ const std::string err = FileLister::addFiles (files, addfile, {}, true ,PathMatch ({}));
157+ ASSERT_EQUALS (" " , err);
158+ }
159+ {
160+ const std::string addfile = Path::join (Path::join (adddir, " cli" ), " token.cpp" ); // does not exist
161+ const std::string err = FileLister::addFiles (files, addfile, {}, true ,PathMatch ({}));
162+ ASSERT_EQUALS (" " , err);
163+ }
164+ {
165+ const std::string addfile = Path::join (Path::join (adddir, " lib2" ), " token.cpp" ); // does not exist
166+ const std::string err = FileLister::addFiles (files, addfile, {}, true ,PathMatch ({}));
167+ #ifdef _WIN32
168+ // TODO: get rid of this error - caused by missing intermediate folder
169+ ASSERT_EQUALS (" finding files failed. Search pattern: '" + dirprefix_nat + " lib2\\ token.cpp'. (error: 3)" , err);
170+ #else
171+ ASSERT_EQUALS (" " , err);
172+ #endif
173+ }
174+ {
175+ const std::string addfile = Path::join (Path::join (adddir, " lib" ), " matchcompiler.h" );
176+ const std::string err = FileLister::addFiles (files, addfile, {}, true ,PathMatch ({}));
177+ ASSERT_EQUALS (" " , err);
178+ }
179+
180+ ASSERT_EQUALS (3 , files.size ());
181+ auto it = files.cbegin ();
182+ ASSERT_EQUALS (dirprefix + " cli/main.cpp" , it->path ());
183+ ASSERT_EQUALS (Path::simplifyPath (dirprefix + " cli/main.cpp" ), it->spath ());
184+ ASSERT_EQUALS_ENUM (Standards::Language::None, it->lang ());
185+ it++;
186+ ASSERT_EQUALS (dirprefix + " lib/token.cpp" , it->path ());
187+ ASSERT_EQUALS (Path::simplifyPath (dirprefix + " lib/token.cpp" ), it->spath ());
188+ ASSERT_EQUALS_ENUM (Standards::Language::None, it->lang ());
189+ it++;
190+ ASSERT_EQUALS (dirprefix + " lib/matchcompiler.h" , it->path ());
191+ ASSERT_EQUALS (Path::simplifyPath (dirprefix + " lib/matchcompiler.h" ), it->spath ());
192+ ASSERT_EQUALS_ENUM (Standards::Language::None, it->lang ());
193+ }
194+
123195 // TODO: test errors
196+ // TODO: test wildcards
124197};
125198
126199REGISTER_TEST (TestFileLister)
0 commit comments