From 2adcc76cf61f74eb6493b166fa73b745c288c9ff Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 25 Apr 2014 15:40:43 -0700 Subject: [PATCH] Switch automation tests to busted This requires shuffling a bunch of stuff around to get a CLI lua executable that uses an automation-like environment, but that's something that'll be nice to have in the future anyway. Busted indirectly depends on lfs and we currently can't use external binary modules, so add a copy of lfs to the repo and build it with Aegisub. --- .gitignore | 1 + automation/Makefile | 9 +- automation/tests/aegisub.cpp | 59 +- automation/tests/modules/re.moon | 494 +++++----- automation/tests/modules/unicode.moon | 48 +- automation/tests/runner.moon | 24 - build/libaegisub/libaegisub.vcxproj | 2 + build/libaegisub/libaegisub.vcxproj.filters | 6 + libaegisub/Makefile | 2 + .../include/libaegisub/lua/script_reader.h | 6 + libaegisub/include/libaegisub/lua/utils.h | 56 +- libaegisub/lua/modules.cpp | 16 +- libaegisub/lua/modules/lfs.cpp | 891 ++++++++++++++++++ libaegisub/lua/script_reader.cpp | 74 ++ libaegisub/lua/utils.cpp | 178 ++++ src/auto4_lua.cpp | 202 +--- src/auto4_lua_assfile.cpp | 3 +- src/auto4_lua_dialog.cpp | 3 +- vendor/lua/Makefile | 4 +- 19 files changed, 1530 insertions(+), 548 deletions(-) delete mode 100644 automation/tests/runner.moon create mode 100644 libaegisub/lua/modules/lfs.cpp create mode 100644 libaegisub/lua/utils.cpp diff --git a/.gitignore b/.gitignore index 1a3b6110f..02db4d667 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ acconf.h acconf.h.in aclocal.m4 autom4te.cache +automation/aegisub-lua conf.sh config.log config.status diff --git a/automation/Makefile b/automation/Makefile index 955e2b1dd..d65ed375b 100644 --- a/automation/Makefile +++ b/automation/Makefile @@ -2,9 +2,7 @@ include ../Makefile.inc PRECOMPILED_HEADER_NAME = ../libaegisub/lagi_pre.h -LIB_SHARED = aegisub.so -LIB_VERSION = 0.1.0 -BUILD_LIB = no +PROGRAM = aegisub-lua CXXFLAGS += -I../libaegisub/include -I../src -I ../vendor/lua/src $(CXXFLAGS_WX) CPPFLAGS += $(CPPFLAGS_BOOST) @@ -15,8 +13,8 @@ LIBS += $(LIBS_WX) $(LIBS_BOOST) $(LIBS_ICU) SRC += tests/aegisub.cpp -test: $(LIB_SHARED) - moon tests/runner.moon +test: $(PROGRAM) + LUA=./aegisub-lua busted -p 'moon' tests/modules .PHONY: test @@ -58,3 +56,4 @@ install: install-share EXTRA_DIST = $(DATA_AUTOMATION) include ../Makefile.target +-include tests/*.d diff --git a/automation/tests/aegisub.cpp b/automation/tests/aegisub.cpp index e733978b7..7a1291122 100644 --- a/automation/tests/aegisub.cpp +++ b/automation/tests/aegisub.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2013, Thomas Goyne +// Copyright (c) 2014, Thomas Goyne // // Permission to use, copy, modify, and distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -15,8 +15,59 @@ // Aegisub Project http://www.aegisub.org/ #include +#include +#include -extern "C" int luaopen_aegisub(lua_State *L) { - agi::lua::preload_modules(L); - return 1; +#include +#include +#include +#include +#include + +using namespace agi::lua; + +namespace { +void check(lua_State *L, int status) { + if (status && !lua_isnil(L, -1)) { + fprintf(stderr, "%s\n", get_string_or_default(L, -1).c_str()); + exit(status); + } } +} + +int main(int argc, char **argv) { + if (argc < 2) { + fprintf(stderr, "usage: aegisub-lua