Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
performance
Megadep
Commits
f0f5262d
Commit
f0f5262d
authored
Jul 09, 2019
by
Pádraig Ó Conbhuí
Browse files
Added failing test for list_includes function.
parent
5b96b7f9
Changes
4
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
f0f5262d
...
...
@@ -9,7 +9,7 @@ project(
add_library
(
libmegadep
src/megadep/
megadep
.cpp
src/megadep/
filesystem
.cpp
)
set_target_properties
(
libmegadep
...
...
@@ -28,7 +28,7 @@ if(MEGADEP_ENABLE_TESTING)
add_executable
(
libmegadep.test
src/megadep/
megadep
.test.cpp
src/megadep/
filesystem
.test.cpp
)
target_link_libraries
(
libmegadep.test PRIVATE libmegadep medagep::catch2_runner
...
...
src/megadep/
megadep
.cpp
→
src/megadep/
filesystem
.cpp
View file @
f0f5262d
#include
<megadep/filesystem.hpp>
#include
<megadep/common_types.hpp>
#include
<megadep/megadep.hpp>
#include
<cerrno>
#include
<cstring>
...
...
@@ -48,4 +48,9 @@ std::vector<FileName> list_files(const DirectoryName &directory) {
return
file_names
;
}
std
::
vector
<
std
::
string
>
read_includes
(
const
std
::
string
&
file_name
)
{
return
{};
}
}
// namespace megadep
src/megadep/
megadep
.hpp
→
src/megadep/
filesystem
.hpp
View file @
f0f5262d
...
...
@@ -10,6 +10,8 @@ namespace megadep {
std
::
vector
<
FileName
>
list_files
(
const
DirectoryName
&
directory
);
std
::
vector
<
std
::
string
>
read_includes
(
const
std
::
string
&
file_name
);
}
// namespace megadep
#endif // MEGADEP_MEGADEP_HPP
src/megadep/
megadep
.test.cpp
→
src/megadep/
filesystem
.test.cpp
View file @
f0f5262d
#include
<iostream>
// DELETE ME
#include
<megadep/filesystem.hpp>
#include
<catch2/catch.hpp>
#include
<iostream>
#include
<
stdio.h
>
#include
<
algorithm
>
#include
<array>
#include
<stdio.h>
#include
<string>
#include
<vector>
#include
<megadep/megadep.hpp>
//
// These tests assume the test runner is run in the project root directory!
//
// This test assumes the test runner is run in the project root directory.
TEST_CASE
(
"megadep::list_files recursively lists files in a directory"
,
"[list_files][unit]"
)
{
"[list_files][
filesystem][
unit]"
)
{
// Compare list_files with find.
// list_files and find should return the same files.
...
...
@@ -18,24 +25,60 @@ TEST_CASE("megadep::list_files recursively lists files in a directory",
REQUIRE
(
files
.
size
()
>
0
);
// Run system find and get list of files
FILE
*
find_fd
=
popen
(
"find src -type f"
,
"r"
);
FILE
*
find_fd
=
popen
(
"find src -type f"
,
"r"
);
std
::
vector
<
std
::
string
>
find_files
;
std
::
array
<
char
,
1024
>
line_buf
;
while
(
fgets
(
line_buf
.
data
(),
line_buf
.
size
(),
find_fd
)
!=
NULL
)
{
while
(
fgets
(
line_buf
.
data
(),
line_buf
.
size
(),
find_fd
)
!=
NULL
)
{
std
::
string
line
=
line_buf
.
data
();
line
.
resize
(
line
.
size
()
-
1
);
// strip newline
line
.
resize
(
line
.
size
()
-
1
);
// strip newline
find_files
.
push_back
(
line
);
}
// Sort both lists so we can compare like-for-like
std
::
sort
(
files
.
begin
(),
files
.
end
());
std
::
sort
(
find_files
.
begin
(),
find_files
.
end
());
REQUIRE
(
files
.
size
()
==
find_files
.
size
());
for
(
size_t
i
=
0
;
i
<
files
.
size
();
i
++
)
{
for
(
size_t
i
=
0
;
i
<
files
.
size
();
i
++
)
{
REQUIRE
(
files
[
i
]
==
find_files
[
i
]);
}
}
TEST_CASE
(
"megadep::read_includes reads all the #include statements"
,
"[read_includes][filesystem][unit]"
)
{
// read the includes from *this* file
std
::
string
this_file
=
"src/megadep/filesystem.test.cpp"
;
std
::
string
this_file_macro
=
__FILE__
;
// Ensure the `this_file` path is a suffix of __FILE__
// in case of name changes in future.
REQUIRE
(
this_file_macro
.
size
()
>=
this_file
.
size
());
REQUIRE
(
this_file_macro
.
compare
(
this_file_macro
.
size
()
-
this_file
.
size
(),
this_file
.
size
(),
this_file
)
==
0
);
auto
includes
=
megadep
::
read_includes
(
this_file
);
// includes copy/pasted from the top of this file!!
std
::
vector
<
std
::
string
>
expected_includes
=
{
"<megadep/filesystem.hpp>"
,
"<catch2/catch.hpp>"
,
"<algorithm>"
,
"<array>"
,
"<stdio.h>"
,
"<string>"
,
"<vector>"
};
std
::
sort
(
includes
.
begin
(),
includes
.
end
());
std
::
sort
(
expected_includes
.
begin
(),
expected_includes
.
end
());
// Compare includes and expected_includes
REQUIRE
(
includes
.
size
()
==
expected_includes
.
size
());
for
(
size_t
i
=
0
;
i
<
includes
.
size
();
i
++
)
{
REQUIRE
(
includes
[
i
]
==
expected_includes
[
i
]);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment