Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
CMake
CMake
Commits
a5b83311
Commit
a5b83311
authored
Mar 26, 2002
by
Sebastien Barre
Browse files
ENH: now supports tests inside sub-dirs
parent
9c4922b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Source/cmCreateTestSourceList.cxx
View file @
a5b83311
...
...
@@ -25,18 +25,25 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
this
->
SetError
(
"called with wrong number of arguments."
);
return
false
;
}
std
::
vector
<
std
::
string
>
args
;
cmSystemTools
::
ExpandListArguments
(
argsIn
,
args
);
cmSystemTools
::
ExpandListArguments
(
argsIn
,
args
,
true
);
std
::
vector
<
std
::
string
>::
iterator
i
=
args
.
begin
();
// Name of the source list
const
char
*
sourceList
=
i
->
c_str
();
++
i
;
// Name of the test driver
std
::
string
driver
=
m_Makefile
->
GetCurrentOutputDirectory
();
driver
+=
"/"
;
driver
+=
*
i
;
driver
+=
".cxx"
;
++
i
;
std
::
vector
<
std
::
string
>::
iterator
testsBegin
=
i
;
std
::
ofstream
fout
(
driver
.
c_str
());
if
(
!
fout
)
{
...
...
@@ -46,14 +53,33 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
this
->
SetError
(
err
.
c_str
());
return
false
;
}
// Create the test driver file
fout
<<
"#include <stdio.h>
\n
"
;
fout
<<
"#include <string.h>
\n
"
;
fout
<<
"// forward declare test functions
\n
"
;
std
::
vector
<
std
::
string
>::
iterator
testsBegin
=
i
;
std
::
vector
<
std
::
string
>
tests_filename
;
// The rest of the arguments consist of a list of test source files.
// Sadly, they can be in directories. Let's modify each arg to get
// a unique function name for the corresponding test, and push the
// real source filename to the tests_filename var (used at the end).
// For the moment:
// - replace spaces ' ', ':' and '/' with underscores '_'
for
(
i
=
testsBegin
;
i
!=
args
.
end
();
++
i
)
{
tests_filename
.
push_back
(
*
i
);
cmSystemTools
::
ConvertToUnixSlashes
(
*
i
);
cmSystemTools
::
ReplaceString
(
*
i
,
" "
,
"_"
);
cmSystemTools
::
ReplaceString
(
*
i
,
"/"
,
"_"
);
cmSystemTools
::
ReplaceString
(
*
i
,
":"
,
"_"
);
fout
<<
"int "
<<
*
i
<<
"(int, char**);
\n
"
;
}
fout
<<
"// Create map
\n
"
;
fout
<<
"typedef int (*MainFuncPointer)(int , char**);
\n
"
;
fout
<<
"struct functionMapEntry
\n
"
...
...
@@ -62,12 +88,14 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
<<
"MainFuncPointer func;
\n
"
<<
"};
\n\n
"
;
fout
<<
"functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
\n
"
;
int
numTests
=
0
;
for
(
i
=
testsBegin
;
i
!=
args
.
end
();
++
i
)
{
fout
<<
"{
\"
"
<<
*
i
<<
"
\"
, "
<<
*
i
<<
"},
\n
"
;
numTests
++
;
}
fout
<<
"};
\n
"
;
fout
<<
"int main(int ac, char** av)
\n
"
<<
"{
\n
"
;
...
...
@@ -112,19 +140,25 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
fout
<<
" return -1;
\n
"
;
fout
<<
"}
\n
"
;
fout
.
close
();
// create the source list
// Create the source list
cmSourceFile
cfile
;
cfile
.
SetIsAnAbstractClass
(
false
);
cfile
.
SetName
(
args
[
1
].
c_str
(),
m_Makefile
->
GetCurrentOutputDirectory
(),
"cxx"
,
false
);
cfile
.
SetName
(
args
[
1
].
c_str
(),
m_Makefile
->
GetCurrentOutputDirectory
(),
"cxx"
,
false
);
m_Makefile
->
AddSource
(
cfile
,
sourceList
);
for
(
i
=
tests
B
egin
;
i
!=
args
.
end
();
++
i
)
for
(
i
=
tests
_filename
.
b
egin
()
;
i
!=
tests_filename
.
end
();
++
i
)
{
cmSourceFile
cfile
;
cfile
.
SetIsAnAbstractClass
(
false
);
cfile
.
SetName
(
i
->
c_str
(),
m_Makefile
->
GetCurrentDirectory
(),
"cxx"
,
false
);
cfile
.
SetName
(
i
->
c_str
(),
m_Makefile
->
GetCurrentDirectory
(),
"cxx"
,
false
);
m_Makefile
->
AddSource
(
cfile
,
sourceList
);
}
...
...
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