diff --git a/.gitmodules b/.gitmodules index ee9246bd..74e39492 100644 --- a/.gitmodules +++ b/.gitmodules @@ -91,3 +91,6 @@ [submodule "third_party/luacov"] path = third_party/luacov url = https://github.com/grumpycoders/luacov.git +[submodule "third_party/luaunit"] + path = third_party/luaunit + url = https://github.com/bluebird75/luaunit.git diff --git a/src/main/main.cc b/src/main/main.cc index 3e9292a0..fc1879ac 100644 --- a/src/main/main.cc +++ b/src/main/main.cc @@ -333,7 +333,7 @@ int pcsxMain(int argc, char **argv) { bool luacovEnabled = false; if (args.get("luacov")) { auto L = *emulator->m_lua; - L.load("package.path = package.path .. ';./lua_modules/share/lua/5.1/?.lua;./third_party/luacov/src/?.lua'", + L.load("package.path = package.path .. ';./lua_modules/share/lua/5.1/?.lua;../../../third_party/luacov/src/?.lua;./third_party/luacov/src/?.lua'", "internal:package.path.lua"); try { L.load(R"( diff --git a/tests/lua/basic.lua b/tests/lua/basic.lua new file mode 100644 index 00000000..8545e8ef --- /dev/null +++ b/tests/lua/basic.lua @@ -0,0 +1,28 @@ +-- Copyright (C) 2024 PCSX-Redux authors +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the +-- Free Software Foundation, Inc., +-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +local lu = require 'luaunit' + +TestBasic = {} + +function TestBasic:test_basic() + lu.assertEquals(1, 1) +end + +local runner = lu.LuaUnit.new() +runner:setOutputType 'text' +PCSX.quit(runner:runSuite()) diff --git a/tests/pcsxrunner/lua.cc b/tests/pcsxrunner/lua.cc new file mode 100644 index 00000000..fd697ce8 --- /dev/null +++ b/tests/pcsxrunner/lua.cc @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2024 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include "gtest/gtest.h" +#include "main/main.h" + +static const char prefix[] = R"( + os.exit = PCSX.quit + package.path = package.path .. ';../../../third_party/luaunit/?.lua' + package.path = package.path .. ';./third_party/luaunit/?.lua' + package.path = package.path .. ';../../../tests/lua/?.lua' + package.path = package.path .. ';./tests/lua/?.lua' +)"; + +TEST(LuaBasic, Interpreter) { + MainInvoker invoker("-no-ui", "-run", "-bios", "src/mips/openbios/openbios.bin", "-testmode", "-interpreter", + "-luacov", "-exec", prefix, "-exec", "require 'basic'"); + int ret = invoker.invoke(); + EXPECT_EQ(ret, 0); +} + +TEST(LuaBasic, Dynarec) { + MainInvoker invoker("-no-ui", "-run", "-bios", "src/mips/openbios/openbios.bin", "-testmode", "-dynarec", "-luacov", + "-exec", prefix, "-exec", "require 'basic'"); + int ret = invoker.invoke(); + EXPECT_EQ(ret, 0); +} diff --git a/third_party/luaunit b/third_party/luaunit new file mode 160000 index 00000000..86f68228 --- /dev/null +++ b/third_party/luaunit @@ -0,0 +1 @@ +Subproject commit 86f68228d73345dabd62a9596feac1f8f8fcaca2 diff --git a/vsprojects/pcsx-redux.sln b/vsprojects/pcsx-redux.sln index 3d2f1ed5..578d9c76 100644 --- a/vsprojects/pcsx-redux.sln +++ b/vsprojects/pcsx-redux.sln @@ -97,6 +97,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "supportpsx", "supportpsx\su EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lpeg", "lpeg\lpeg.vcxproj", "{CE54ED92-4645-4AE9-BDC8-C0B9607765F8}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lua", "Lua", "{394627A0-57EB-46B1-B768-E02ACFC798A8}" + ProjectSection(SolutionItems) = preProject + ..\tests\lua\basic.lua = ..\tests\lua\basic.lua + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -530,9 +535,10 @@ Global {CDED480F-14EE-475E-97F5-97F2B62DB3CE} = {C6DD47BC-0C38-4AE6-B517-9675F3AC8A50} {B2E2AD84-9D7F-4976-9572-E415819FFD7F} = {008A2872-432F-480B-828D-FF9AAA4846BC} {CE54ED92-4645-4AE9-BDC8-C0B9607765F8} = {64A05F50-3203-42CC-B632-09D6EE6EA856} + {394627A0-57EB-46B1-B768-E02ACFC798A8} = {9D5A1DB2-E74D-4CDD-8377-9EA08CF4AADE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {AC54A867-F976-4B3D-A6EF-F57EB764DCD4} SolutionGuid = {284E91C1-764E-441A-854D-CFD3623A6501} + SolutionGuid = {AC54A867-F976-4B3D-A6EF-F57EB764DCD4} EndGlobalSection EndGlobal diff --git a/vsprojects/tests/pcsxrunner/pcsxrunner.vcxproj b/vsprojects/tests/pcsxrunner/pcsxrunner.vcxproj index 520b5c08..fd036f74 100644 --- a/vsprojects/tests/pcsxrunner/pcsxrunner.vcxproj +++ b/vsprojects/tests/pcsxrunner/pcsxrunner.vcxproj @@ -389,6 +389,7 @@ + diff --git a/vsprojects/tests/pcsxrunner/pcsxrunner.vcxproj.filters b/vsprojects/tests/pcsxrunner/pcsxrunner.vcxproj.filters index 03e5ce46..6e7582d3 100644 --- a/vsprojects/tests/pcsxrunner/pcsxrunner.vcxproj.filters +++ b/vsprojects/tests/pcsxrunner/pcsxrunner.vcxproj.filters @@ -36,6 +36,9 @@ Source Files + + Source Files +