Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 8e0d01e

Browse files
committed
[Tests][emscripten] Add a way to run tests in the browser.
1 parent 6cffbbf commit 8e0d01e

6 files changed

Lines changed: 136 additions & 4 deletions

File tree

docs/testing.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ Open the `livecode.sln` solution file in Visual Studio, and build the "check" pr
2222

2323
There's not currently a convenient way to run the LiveCode Script and LiveCode Builder tests on Windows.
2424

25+
### Running tests on Emscripten
26+
27+
To run the C++ tests, run `make check-emscripten` from the top of the livecode git repository working tree.
28+
29+
To run the LiveCode Script tests:
30+
31+
1) Run `tools/emscripten_testgen.sh`. This generates an HTML5 standalone in the `_tests/emscripten` directory.
32+
33+
2) Open `_tests/emscripten/tests.html` in a web browser.
34+
35+
The tests are run automatically as the web page loads, and the TAP log
36+
output is shown in the browser.
37+
2538
## Writing Tests
2639

2740
If at all possible, please add tests whenever make a change to LiveCode -- whether it's a feature added, a bug fixed, or a behaviour tweaked.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
script "EmscriptenTestRunner"
2+
3+
private command TestLoadLibrary pBasename
4+
local tStackname
5+
put the name of stack (pBasename & ".livecodescript") into tStackname
6+
7+
dispatch revLoadLibrary to tStackname
8+
end TestLoadLibrary
9+
10+
on startup
11+
set the defaultfolder to "/boot/standalone"
12+
13+
-- Load test libraries
14+
write "# Loading test libraries" & return to stdout
15+
TestLoadLibrary "_testlib"
16+
TestLoadLibrary "_testerlib"
17+
18+
-- Run tests
19+
local tTestFile, tStackName, tCommand, tSetupResult
20+
21+
repeat for each element tTestFile in TesterGetTestFileNames()
22+
put the name of stack tTestFile into tStackName
23+
24+
TestDiagnostic "framework: Running tests from" && tTestFile
25+
write return to stdout
26+
27+
repeat for each element tCommand in TesterParseTestCommandNames(tTestFile)
28+
29+
TestDiagnostic "framework: Running" && tCommand
30+
31+
-- Send setup command and check if skip is requested
32+
dispatch "TestSetup" to tStackName
33+
put the result into tSetupResult
34+
if word 1 of tSetupResult is "skip" then
35+
TestSkip tCommand, word 2 to -1 of tSetupResult
36+
write return to stdout
37+
next repeat
38+
end if
39+
40+
-- Run tests
41+
dispatch tCommand to tStackName
42+
43+
-- Send teardown command
44+
dispatch "TestTearDown" to tStackName
45+
46+
write return to stdout
47+
end repeat
48+
end repeat
49+
50+
end startup
51+
52+
on ErrorDialog executionError, parseError
53+
write executionError & return to stderr
54+
quit 1
55+
end ErrorDialog
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
script "EmscriptenTestStartup"
2+
3+
on startup
4+
end startup

tests/lcs/core/engine/engine.livecodescript

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,12 @@ TestAssert "test", tError is not 0
220220

221221
end TestEngine19
222222

223-
on TestEngine20
223+
on TestSystemVersion
224+
if the platform is "HTML" then
225+
TestSkip "systemVersion not empty", "bug 16539"
226+
TestAssert "test", the systemVersion is not empty
227+
end TestSystemVersion
224228

225-
TestAssert "test", the systemVersion is not empty
226-
227-
end TestEngine20
228229
on TestEngine21
229230

230231

tests/lcs/docs/docsparser.livecodescript

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ You should have received a copy of the GNU General Public License
1717
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1818

1919
on TestSetup
20+
-- Only run these tests on desktop platforms
21+
if the platform is not among the items of "MacOS,Windows,Linux" then
22+
return "SKIP Tests are not runnable on" && the platform
23+
end if
24+
2025
local tDocsParser
2126
put TestGetEngineRepositoryPath() & "/ide-support/revdocsparser.livecodescript" into tDocsParser
2227
start using stack tDocsParser

tools/emscripten_testgen.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# This script generates a standalone .zip file that contains
6+
# LiveCodeScript tests.
7+
8+
# Preparation
9+
# -----------
10+
11+
# Figure out some paths
12+
top_src_dir=$(cd $(dirname $0)/.. && pwd)
13+
em_bin_dir=${top_src_dir}/emscripten-bin
14+
15+
test_src_dir=${top_src_dir}/tests
16+
em_test_src_dir=${test_src_dir}/_emscripten
17+
test_build_dir=${top_src_dir}/_tests
18+
em_test_build_dir=${test_build_dir}/emscripten
19+
em_stack_dir=${em_test_build_dir}/standalone/boot/standalone
20+
21+
# Get version information
22+
short_ver=$(perl ${top_src_dir}/util/decode_version.pl BUILD_SHORT_VERSION ${top_src_dir}/version)
23+
24+
# Clean up from previous run and create required directories
25+
rm -rf ${em_test_build_dir}
26+
mkdir -p ${em_test_build_dir}
27+
28+
# Engine
29+
# ------
30+
31+
# Copy the engine into place
32+
cp -a ${em_bin_dir}/standalone-community-${short_ver}.{js,html.mem} ${em_test_build_dir}
33+
cp -a ${em_bin_dir}/standalone-community-${short_ver}.html ${em_test_build_dir}/tests.html
34+
35+
# Standalone
36+
# ----------
37+
# Construct a basic standalone boot filesystem
38+
cp -r ${top_src_dir}/engine/rsrc/emscripten-standalone-template ${em_test_build_dir}/standalone
39+
# Copy in test suite stacks
40+
mkdir -p ${em_stack_dir}
41+
cp -a ${test_src_dir} ${em_stack_dir}
42+
# Clean up undesirable files
43+
find ${test_src_dir} \
44+
-not -name \*.livecodescript -o \
45+
-name '_*' -o \
46+
-name '.*' \
47+
-print \
48+
-exec rm '{}' ';'
49+
cp ${test_src_dir}/_test*lib.livecodescript ${em_stack_dir}
50+
# Copy in startup and boot stacks
51+
cp ${em_test_src_dir}/__boot.livecodescript ${em_test_build_dir}/standalone/boot/standalone/__boot.livecode
52+
cp ${em_test_src_dir}/__startup.livecodescript ${em_test_build_dir}/standalone/boot/__startup.livecode
53+
# Create the standalone.zip file
54+
( cd ${em_test_build_dir}/standalone && zip -0qr ${em_test_build_dir}/standalone.zip * )

0 commit comments

Comments
 (0)