Support a BROWSER_TESTS env variable to build tests for browsers

This commit is contained in:
Frank Denis 2015-12-07 01:44:33 +01:00
parent 7354964b91
commit 3d1e11fe81
3 changed files with 76 additions and 23 deletions

View File

@ -9,11 +9,15 @@ export LDFLAGS="-s TOTAL_MEMORY=${TOTAL_MEMORY} -s RESERVED_FUNCTION_POINTERS=8
rm -f test/js.done
if [ "x$BROWSER_TESTS" != "x" ]; then
echo "Tests will be built to be run in a web browser"
fi
emconfigure ./configure --enable-minimal --disable-shared --prefix="$PREFIX" \
CFLAGS="-O3" && \
emmake make clean && \
emmake make $MAKE_FLAGS install V=1 && \
emcc -O3 --llvm-lto 1 --memory-init-file 0 $LDFLAGS $JS_EXPORTS_FLAGS \
emcc -O3 --llvm-lto 1 --memory-init-file 0 $CPPFLAGS $LDFLAGS $JS_EXPORTS_FLAGS \
"${PREFIX}/lib/libsodium.a" -o "${PREFIX}/lib/libsodium.js" || exit 1
if test "x$NODE" = x; then
@ -27,16 +31,34 @@ if test "x$NODE" = x; then
fi
if test "x$NODE" = x; then
echo 'node.js not found - test suite skipped.' >&2
echo 'node.js not found - test suite skipped' >&2
exit 1
fi
echo "Using [${NODE}] as a Javascript runtime."
echo "Using [${NODE}] as a Javascript runtime"
if [ "x$BROWSER_TESTS" != "x" ]; then
echo 'Compiling the test suite for browsers...' && \
emmake make $MAKE_FLAGS CPPFLAGS="$CPPFLAGS -DBROWSER_TESTS=1" check \
> /dev/null 2>&1
else
echo 'Compiling the test suite...' && \
emmake make $MAKE_FLAGS check > /dev/null 2>&1
fi
echo 'Running the test suite.'
if [ "x$BROWSER_TESTS" != "x" ]; then
echo 'Creating the test suite for browsers'
(
cd test/default && \
mkdir -p browser && \
for file in *.js; do
fgrep -v "#! /usr/bin/env {NODE}" "$file" > "browser/${file}.tmp"
chmod -x "browser/${file}.tmp"
mv -f "browser/${file}.tmp" "browser/${file}"
done
)
else
echo 'Running the test suite'
(
cd test/default && \
for file in *.js; do
@ -47,5 +69,7 @@ echo 'Running the test suite.'
done
)
make $MAKE_FLAGS check || exit 1
fi
echo 'Done.'
touch -r "${PREFIX}/lib/libsodium.js" test/js.done

View File

@ -27,9 +27,12 @@
# define rand(X) arc4random(X)
#endif
FILE *fp_res;
int xmain(void);
#ifndef BROWSER_TESTS
FILE *fp_res;
int main(void)
{
FILE *fp_out;
@ -61,6 +64,24 @@ int main(void)
#undef printf
#define printf(...) fprintf(fp_res, __VA_ARGS__)
#else
int main(void)
{
if (sodium_init() != 0) {
return 99;
}
if (xmain() != 0) {
return 99;
}
printf("--- SUCCESS ---\n");
return 0;
}
#endif
#define main xmain
#endif

View File

@ -4,9 +4,17 @@ try {
} catch(e) {
this['Module'] = Module = {};
}
if (typeof process === 'object') {
Module['preRun'] = Module['preRun'] || [];
Module['preRun'].push(function() {
FS.init();
FS.mkdir('/test-data');
FS.mount(NODEFS, { root: '.' }, '/test-data');
});
} else {
Module['print'] = function(x) {
var event = new Event('test-output');
event.data = x;
window.dispatchEvent(event);
};
}