Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Olena
olena
Commits
5ee999b4
Commit
5ee999b4
authored
Aug 10, 2010
by
Guillaume Lazzara
Browse files
build-aux/build_unit_test.sh: Add support for conditional unit-tests.
parent
af62462e
Changes
2
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
5ee999b4
2010-08-10 Guillaume Lazzara <z@lrde.epita.fr>
* build-aux/build_unit_test.sh: Add support for conditional
unit-tests.
2010-08-03 Guillaume Lazzara <z@lrde.epita.fr>
* configure.ac: Improve configure's outputs for external library
...
...
build-aux/build_unit_test.sh
View file @
5ee999b4
#! /bin/sh
# Copyright (C) 200
7
, 200
9
EPITA Research and Development Laboratory
# Copyright (C) 200
9
, 20
1
0 EPITA Research and Development Laboratory
# (LRDE)
#
# This file is part of Olena.
...
...
@@ -17,6 +17,25 @@
# You should have received a copy of the GNU General Public License
# along with Olena. If not, see <http://www.gnu.org/licenses/>.
## Build a list of unit tests.
##
## Conditional tests (external dependencies) can be handled
## automaticaly. For each dependency, a file named
## "cond_tests_{DEPS}" must contain the list of files which need the
## dependency. If a test needs more than one dependency, several
## dependency names can be used in the file name.
##
## Ex: cond_tests_qt_tesseract
##
## All the tests listed in this file will need both qt and tesseract
## to be compiled.
##
## "cond_tests_*" files must be created in the directory where
## unit-test.mk is generated (usually the unit-tests directory).
##
## WARNING: don't forget to add "cond_tests_*" files in the COND_TESTS
## variable in the right Makefile.am.
## FIXME: Don't use `echo -n', as echo's options are not portable.
##
## http://www.gnu.org/software/autoconf/manual/html_node/Limitations-of-Builtins.html#Limitations-of-Builtins
...
...
@@ -25,44 +44,38 @@
## would be to only emit lines ended with newlines.
ECHO_N
=
printf
# Use the C locale to have a deterministic sort.
export
LC_ALL
=
C
test
$#
-eq
3
||
{
echo
"Usage:
$0
<scanned dir> <output_dir> <disabled_tests>"
&&
exit
1
;
}
add_targets
()
{
HEADERS_
=
"
$1
"
output_dir
=
"
$2
"
output
=
"
$3
"
IFDEF
=
"
$4
"
scanned_dir
=
$1
output_dir
=
$2
disabled_tests
=
$3
if
!
(
test
-z
"
$IFDEF
"
)
;
then
echo
"# Starting a conditional unit test list."
>>
"
$output
"
else
echo
"# Starting non-conditional unit test list."
>>
"
$output
"
fi
## FIXME: We do not include these directories
##
## mln/io/dicom
## mln/io/fits
## mln/io/magick
## mln/io/tiff
##
## because they contain files depending on optional (external)
## libraries. We should test them conditionally.
HEADERS
=
$(
find
$scanned_dir
-type
f
-name
"*.hh"
\
|
sort
\
|
sed
-e
's/.*\/mln\/\(.*\)/mln\/\1/g'
|
sed
's/\.\.\/\.\.\///g'
\
|
comm
-23
-
"
$disabled_tests
"
)
# Start conditions if necessary
output
=
"
$output_dir
/unit-tests.mk"
# Construct a list of conditions in reverse order to write valid
# endif further.
IFDEF_TMP
=
""
for
i
in
$IFDEF
;
do
echo
"if HAVE_
$i
"
>>
"
$output
"
IFDEF_TMP
=
"
$i
$IFDEF_TMP
"
done
IFDEF
=
"
$IFDEF_TMP
"
rm
-f
"
$output
"
rm
-f
mln_
*
.cc
$ECHO_N
"check_PROGRAMS += "
>>
"
$output
"
# Build unit-tests.mk.
echo
"## Generated by
$0
, do not modify."
>
"
$output
"
echo
>>
"
$output
"
$ECHO_N
"check_PROGRAMS = "
>>
"
$output
"
for
i
in
$HEADERS
;
do
FILE_CC
=
`
echo
$i
|
sed
's/[/.]/_/g'
|
sed
's/_hh/\.cc/g'
`
for
i
in
$HEADERS_
;
do
FILE_CC
=
`
echo
$i
|
sed
's/[/.]/_/g'
|
sed
's/_hh/\.cc/g'
`
# Build .cc.
cat
>
$output_dir
/
$FILE_CC
<<
EOF
cat
>
$output_dir
/
$FILE_CC
<<
EOF
// Unit test for
$i
.
// Generated by
$0
, do not modify.
...
...
@@ -77,16 +90,115 @@ int main()
EOF
# Build unit-tests.mk.
TARGET
=
`
echo
"
${
FILE_CC
}
"
|
sed
's/\.cc//'
`
echo
"
\\
"
>>
"
$output
"
$ECHO_N
"
${
TARGET
}
"
>>
"
$output
"
TARGET
=
`
echo
"
${
FILE_CC
}
"
|
sed
's/\.cc//'
`
echo
"
\\
"
>>
"
$output
"
$ECHO_N
"
${
TARGET
}
"
>>
"
$output
"
done
# Build "$output".
echo
""
>>
"
$output
"
echo
""
>>
"
$output
"
for
i
in
$HEADERS_
;
do
FILE_CC
=
`
echo
$i
|
sed
's/[/.]/_/g'
|
sed
's/_hh/\.cc/g'
`
NAME
=
`
echo
$FILE_CC
|
sed
's/\.cc//g'
`
# Write specific flags if there are dependencies.
if
!
(
test
-z
"
$IFDEF
"
)
;
then
cppflags
=
"
${
NAME
}
_CPPFLAGS="
ldflags
=
"
${
NAME
}
_LDFLAGS="
for
i
in
$IFDEF
;
do
cppflags
=
"
${
cppflags
}
\$
{
${
i
}
_CPPFLAGS} "
ldflags
=
"
${
ldflags
}
\$
{
${
i
}
_LDFLAGS} "
done
echo
"
$cppflags
\$
{AM_CPPFLAGS}"
>>
"
$output
"
echo
"
$ldflags
\$
{AM_LDFLAGS}"
>>
"
$output
"
fi
echo
"
${
NAME
}
_SOURCES =
$FILE_CC
"
>>
"
$output
"
done
# End conditions if necessary
for
i
in
$IFDEF
;
do
echo
"endif HAVE_
$i
"
>>
"
$output
"
done
echo
""
>>
"
$output
"
}
# Use the C locale to have a deterministic sort.
export
LC_ALL
=
C
test
$#
-eq
4
||
{
echo
"Usage:
$0
<scanned dir> <output_dir> <disabled_tests> <base include dir>"
&&
exit
1
;
}
scanned_dir
=
$1
output_dir
=
$2
disabled_tests
=
$3
base_inc_dir
=
$4
# Create a list of tests to be disabled or considered as conditional.
ignored_list
=
"
$output_dir
/ignored_list.tmp"
cat
"
$disabled_tests
"
>
$ignored_list
COND_TESTS
=
$(
find
$output_dir
-type
f
-name
"cond_tests_*"
|
sort
)
for
f
in
$COND_TESTS
;
do
cat
"
$f
"
>>
"
$ignored_list
"
done
cat
"
$ignored_list
"
|
sort
>
"
$ignored_list
.tmp"
mv
-f
"
$ignored_list
.tmp"
"
$ignored_list
"
# Build "$output".
echo
""
>>
"
$output
"
HEADERS
=
$(
find
$scanned_dir
-type
f
-name
"*.hh"
\
|
sort
\
|
sed
-e
"s/.*
\/
${
base_inc_dir
}
\/\(
.*
\)
/
${
base_inc_dir
}
\/\1
/g"
\
|
sed
's/\.\.\/\.\.\///g'
\
|
comm
-23
-
"
$ignored_list
"
)
output
=
"
$output_dir
/unit-tests.mk"
# Cleanup previously generated data.
rm
-f
"
$output
"
rm
-f
${
base_inc_dir
}
_
*
.cc
# Build unit-tests.mk.
echo
"## Generated by
$0
, do not modify."
>
"
$output
"
echo
>>
"
$output
"
echo
"check_PROGRAMS ="
>>
"
$output
"
echo
""
>>
"
$output
"
for
i
in
$HEADERS
;
do
FILE_CC
=
`
echo
$i
|
sed
's/[/.]/_/g'
|
sed
's/_hh/\.cc/g'
`
NAME
=
`
echo
$FILE_CC
|
sed
's/\.cc//g'
`
echo
"
${
NAME
}
_SOURCES =
$FILE_CC
"
>>
"
$output
"
#-----------------------------------
# Insert lists of conditional tests.
#-----------------------------------
for
f
in
$COND_TESTS
;
do
# Generate the list of conditions.
fpostfix
=
"
`
echo
\"
$f
\"
|
sed
-e
's/.*\/cond_tests_//g'
`
_"
i
=
1
COND_LIST
=
""
while
true
;
do
name
=
`
echo
$fpostfix
|
cut
-s
-d
'_'
-f
$i
\
|
tr
"[:lower:]"
"[:upper:]"
`
i
=
$((
$i
+
1
))
if
(
test
-z
"
$name
"
)
;
then
break
;
fi
COND_LIST
=
"
${
COND_LIST
}
$name
"
done
COND_HEADERS
=
$(
cat
$f
)
# Writing conditional targets
add_targets
"
$COND_HEADERS
"
"
$output_dir
"
"
$output
"
"
$COND_LIST
"
done
#-------------------------------------
# Insert list of non-conditional tests
#-------------------------------------
add_targets
"
$HEADERS
"
"
$output_dir
"
"
$output
"
""
# Remove temporary files
rm
-f
"
$ignored_list
"
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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