Build the python binding as part of the tests

This commit is contained in:
Pierre Pronchery 2014-08-29 19:04:13 +02:00
parent 13da423c7d
commit 7ade6f79d4
8 changed files with 68 additions and 4 deletions

View File

@ -101,6 +101,7 @@ dist:
$(PACKAGE)-$(VERSION)/tests/variable.c \
$(PACKAGE)-$(VERSION)/tests/COPYING \
$(PACKAGE)-$(VERSION)/tests/Makefile \
$(PACKAGE)-$(VERSION)/tests/python.sh \
$(PACKAGE)-$(VERSION)/tests/tests.sh \
$(PACKAGE)-$(VERSION)/tests/project.conf \
$(PACKAGE)-$(VERSION)/tools/configctl.c \

View File

@ -34,6 +34,7 @@ typedef char String;
/* functions */
String * string_new(String const * string);
String * string_new_append(String const * string, ...);
String * string_new_format(String const * format, ...);
String * string_new_length(String const * string, size_t length);
void string_delete(String * string);

View File

@ -13,7 +13,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* TODO:
* - add string_new_format(), string_rtrim(), string_ltrim()... */
* - add string_rtrim(), string_ltrim()... */
@ -68,6 +68,37 @@ String * string_new_append(String const * string, ...)
}
/* string_new_format */
String * string_new_format(String const * format, ...)
{
String * ret;
va_list ap;
int len;
size_t s;
va_start(ap, format);
len = vsnprintf(NULL, 0, format, ap);
va_end(ap);
if(len < 0)
{
error_set_code(1, "%s", strerror(errno));
return NULL;
}
s = (size_t)len + 1;
if((ret = object_new(s)) == NULL)
return NULL;
va_start(ap, format);
if(vsnprintf(ret, s, format, ap) != len)
{
error_set_code(1, "%s", strerror(errno));
object_delete(ret);
ret = NULL;
}
va_end(ap);
return ret;
}
/* string_new_length */
String * string_new_length(String const * string, size_t length)
{

View File

@ -39,7 +39,7 @@ variable_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
variable: $(variable_OBJS)
$(CC) -o variable $(variable_OBJS) $(variable_LDFLAGS)
tests.log: includes string tests.sh variable
tests.log: includes python.sh string tests.sh variable
./tests.sh -P "$(PREFIX)" -- "tests.log"
includes.o: includes.c

View File

@ -4,7 +4,7 @@ cflags_force=-W
cflags=-Wall -g -O2
ldflags_force=-L ../src -lSystem
ldflags=-L$(PREFIX)/lib -Wl,-rpath,"$(PWD)/../src"
dist=COPYING,Makefile,tests.sh
dist=COPYING,Makefile,python.sh,tests.sh
[includes]
type=binary
@ -20,7 +20,7 @@ depends=../src/string.c
[tests.log]
type=script
script=./tests.sh
depends=includes,string,tests.sh,variable
depends=includes,python.sh,string,tests.sh,variable
[variable]
type=binary

24
tests/python.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/sh
#$Id$
#Copyright (c) 2014 Pierre Pronchery <khorben@defora.org>
#This file is part of DeforaOS System libSystem
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, version 3 of the License.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#variables
#executables
MAKE="make"
(cd ../src/python && $MAKE clean all)

View File

@ -30,6 +30,7 @@ static int _test(char const * progname, String * s)
printf("%s: Testing %s\n", progname, "string_get_length()");
if((len = string_get_length(s)) == 0)
return 2;
printf("\"%s\" => %lu\n", s, len);
/* string_clear */
printf("%s: Testing %s\n", progname, "string_clear()");
string_clear(s);
@ -50,5 +51,9 @@ int main(int argc, char * argv[])
return 2;
ret |= _test(argv[0], s);
string_delete(s);
if((s = string_new_format("%s", argv[0])) == NULL)
return 2;
ret |= _test(argv[0], s);
string_delete(s);
return 0;
}

View File

@ -101,6 +101,8 @@ echo "Performing tests:" 1>&2
_test "includes"
_test "string"
_test "variable"
echo "Expected failures:" 1>&2
_fail "python.sh"
if [ -n "$FAILED" ]; then
echo "Failed tests:$FAILED" 1>&2
exit 2