diff --git a/_multibuild b/_multibuild
new file mode 100644
index 0000000..fcc7b97
--- /dev/null
+++ b/_multibuild
@@ -0,0 +1,3 @@
+
+ test
+
diff --git a/attrib_test.patch b/attrib_test.patch
index 2055bd1..5f6f84f 100644
--- a/attrib_test.patch
+++ b/attrib_test.patch
@@ -1,5 +1,5 @@
---- a/lua-tests/attrib.lua
-+++ b/lua-tests/attrib.lua
+--- a/attrib.lua
++++ b/attrib.lua
@@ -269,7 +269,7 @@ local p = "" -- On Mac OS X, redefine
local st, err, when = package.loadlib(DC"lib1", "*")
if not st then
diff --git a/files_test.patch b/files_test.patch
index 9d22629..16bbd08 100644
--- a/files_test.patch
+++ b/files_test.patch
@@ -1,7 +1,7 @@
-Index: lua/lua-tests/files.lua
+Index: lua/files.lua
===================================================================
---- lua.orig/lua-tests/files.lua
-+++ lua/lua-tests/files.lua
+--- lua.orig/files.lua
++++ lua/files.lua
@@ -81,7 +81,7 @@ assert(io.output() ~= io.stdout)
if not _port then -- invalid seek
diff --git a/lua54.changes b/lua54.changes
index 14a6c3d..bd7aa0d 100644
--- a/lua54.changes
+++ b/lua54.changes
@@ -1,3 +1,8 @@
+-------------------------------------------------------------------
+Fri Jan 22 12:38:04 UTC 2021 - Callum Farmer
+
+- Move tests to separate build
+
-------------------------------------------------------------------
Sat Dec 5 12:48:18 UTC 2020 - Callum Farmer
diff --git a/lua54.spec b/lua54.spec
index 4968cad..1e3c10a 100644
--- a/lua54.spec
+++ b/lua54.spec
@@ -15,10 +15,15 @@
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
-
+%global flavor @BUILD_FLAVOR@%{nil}
+%if "%{flavor}" == "test"
+%define name_ext -test
+%else
+%define name_ext %{nil}
+%endif
%define major_version 5.4
%define libname liblua5_4-5
-Name: lua54
+Name: lua54%{name_ext}
Version: 5.4.2
Release: 0
Summary: Small Embeddable Language with Procedural Syntax
@@ -37,10 +42,14 @@ Patch2: files_test.patch
Patch3: main_test.patch
# PATCH-FIX-UPSTREAM https://www.lua.org/bugs.html#5.4.2
#Patch4: upstream-bugs.patch
+%if "%{flavor}" == "test"
+BuildRequires: lua54
+%else
BuildRequires: libtool
BuildRequires: lua-macros
BuildRequires: pkgconfig
BuildRequires: readline-devel
+%endif
Requires(post): update-alternatives
Requires(postun): update-alternatives
Provides: lua = %{version}
@@ -123,11 +132,18 @@ scripting, and rapid prototyping. Lua is implemented as a small library
of C functions, written in ANSI C.
%prep
-%setup -q -n lua-%{version} -a1
-mv lua-%{version}-tests lua-tests
-%autopatch -p1
+%if "%{flavor}" == "test"
+%setup -T -q -b1 -n lua-%{version}-tests
+%patch1 -p1
+%patch2 -p1
+%patch3 -p1
+%else
+%setup -q -n lua-%{version}
+%patch0 -p1
+%endif
# manpage
+%if "%{flavor}" != "test"
cat doc/lua.1 | sed 's/TH LUA 1/TH LUA%{major_version} 1/' > doc/lua%{major_version}.1
cat doc/luac.1 | sed 's/TH LUAC 1/TH LUAC%{major_version} 1/' > doc/luac%{major_version}.1
@@ -185,11 +201,12 @@ touch %{buildroot}%{_sysconfdir}/alternatives/liblua.so
ln -sf %{_sysconfdir}/alternatives/liblua.so %{buildroot}%{_libdir}/liblua.so
touch %{buildroot}%{_sysconfdir}/alternatives/lua.pc
ln -sf %{_sysconfdir}/alternatives/lua.pc %{buildroot}%{_libdir}/pkgconfig/lua.pc
-
+%else
%check
-cd ./lua-tests/
-LD_LIBRARY_PATH=%{buildroot}%{_libdir} %{buildroot}%{_bindir}/lua%{major_version} all.lua
+LD_LIBRARY_PATH=%{_libdir} %{_bindir}/lua%{major_version} all.lua
+%endif
+%if "%{flavor}" != "test"
%post -n %{libname} -p /sbin/ldconfig
%postun -n %{libname} -p /sbin/ldconfig
@@ -258,4 +275,5 @@ fi
%files doc
%doc doc/*
+%endif
%changelog
diff --git a/main_test.patch b/main_test.patch
index 2880023..0037896 100644
--- a/main_test.patch
+++ b/main_test.patch
@@ -1,5 +1,5 @@
---- a/lua-tests/main.lua
-+++ b/lua-tests/main.lua
+--- a/main.lua
++++ b/main.lua
@@ -307,11 +307,11 @@
]]
RUN([[lua -e "%s" -i < %s > %s]], prompt, prog, out)