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 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" \ emconfigure ./configure --enable-minimal --disable-shared --prefix="$PREFIX" \
CFLAGS="-O3" && \ CFLAGS="-O3" && \
emmake make clean && \ emmake make clean && \
emmake make $MAKE_FLAGS install V=1 && \ 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 "${PREFIX}/lib/libsodium.a" -o "${PREFIX}/lib/libsodium.js" || exit 1
if test "x$NODE" = x; then if test "x$NODE" = x; then
@ -27,17 +31,35 @@ if test "x$NODE" = x; then
fi fi
if test "x$NODE" = x; then 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 exit 1
fi fi
echo "Using [${NODE}] as a Javascript runtime." echo "Using [${NODE}] as a Javascript runtime"
echo 'Compiling the test suite...' && \ if [ "x$BROWSER_TESTS" != "x" ]; then
emmake make $MAKE_FLAGS check > /dev/null 2>&1 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 && \ cd test/default && \
for file in *.js; do for file in *.js; do
echo "#! /usr/bin/env ${NODE}" > "${file}.tmp" echo "#! /usr/bin/env ${NODE}" > "${file}.tmp"
@ -45,7 +67,9 @@ echo 'Running the test suite.'
chmod +x "${file}.tmp" chmod +x "${file}.tmp"
mv -f "${file}.tmp" "$file" mv -f "${file}.tmp" "$file"
done done
) )
make $MAKE_FLAGS check || exit 1 make $MAKE_FLAGS check || exit 1
fi
echo 'Done.' echo 'Done.'
touch -r "${PREFIX}/lib/libsodium.js" test/js.done touch -r "${PREFIX}/lib/libsodium.js" test/js.done

View File

@ -27,9 +27,12 @@
# define rand(X) arc4random(X) # define rand(X) arc4random(X)
#endif #endif
FILE *fp_res;
int xmain(void); int xmain(void);
#ifndef BROWSER_TESTS
FILE *fp_res;
int main(void) int main(void)
{ {
FILE *fp_out; FILE *fp_out;
@ -61,6 +64,24 @@ int main(void)
#undef printf #undef printf
#define printf(...) fprintf(fp_res, __VA_ARGS__) #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 #define main xmain
#endif #endif

View File

@ -4,9 +4,17 @@ try {
} catch(e) { } catch(e) {
this['Module'] = Module = {}; this['Module'] = Module = {};
} }
Module['preRun'] = Module['preRun'] || []; if (typeof process === 'object') {
Module['preRun'].push(function(){ Module['preRun'] = Module['preRun'] || [];
Module['preRun'].push(function() {
FS.init(); FS.init();
FS.mkdir('/test-data'); FS.mkdir('/test-data');
FS.mount(NODEFS, { root: '.' }, '/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);
};
}