From 88b2feff6fcd0aca0414df7a43c205c10fcaba3f Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Mon, 18 Nov 2013 12:49:57 -0800 Subject: [PATCH] test(doc/lua): add script for validating examples in the Lua API documentation Signed-off-by: Leonardo de Moura --- doc/lua/test.sh | 26 ++++++++++++++++++++++++++ src/shell/lua/CMakeLists.txt | 4 ++++ 2 files changed, 30 insertions(+) create mode 100755 doc/lua/test.sh diff --git a/doc/lua/test.sh b/doc/lua/test.sh new file mode 100755 index 0000000000..316f34c865 --- /dev/null +++ b/doc/lua/test.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Test is all examples in the .md files are working +if [ $# -ne 1 ]; then + echo "Usage: test.sh [leanlua-executable-path]" + exit 1 +fi +ulimit -s unlimited +LEANLUA=$1 +NUM_ERRORS=0 +for f in `ls *.md`; do + echo "-- testing $f" + awk 'BEGIN{ in_block = 0 } !/```/{ if (in_block == 1) print $0; else print "" } /```/{ in_block = 0; print "" } /```lua/{ in_block = 1; print "" }' $f > $f.lua + if $LEANLUA $f.lua > $f.produced.out; then + echo "-- worked" + else + echo "ERROR executing $f.lua, produced output is at $f.produced.out" + NUM_ERRORS=$(($NUM_ERRORS+1)) + fi +done +if [ $NUM_ERRORS -gt 0 ]; then + echo "-- Number of errors: $NUM_ERRORS" + exit 1 +else + echo "-- Passed" + exit 0 +fi diff --git a/src/shell/lua/CMakeLists.txt b/src/shell/lua/CMakeLists.txt index c23d32f39c..a0e25680cf 100644 --- a/src/shell/lua/CMakeLists.txt +++ b/src/shell/lua/CMakeLists.txt @@ -4,6 +4,10 @@ add_test(NAME leanluatests WORKING_DIRECTORY "${LEAN_SOURCE_DIR}/../tests/lua" COMMAND "./test.sh" "${CMAKE_CURRENT_BINARY_DIR}/leanlua") +add_test(NAME leanluadocs + WORKING_DIRECTORY "${LEAN_SOURCE_DIR}/../doc/lua" + COMMAND "./test.sh" "${CMAKE_CURRENT_BINARY_DIR}/leanlua") + if((${CYGWIN} EQUAL "1") OR (${CMAKE_SYSTEM_NAME} MATCHES "Linux")) if (NOT (${CMAKE_CXX_COMPILER} MATCHES "clang")) add_test(NAME leanluathreadtests