-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1553 from grumpycoders/lua-unit-tests
Adding Lua unit testing.
- Loading branch information
Showing
11 changed files
with
161 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
-- 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 | ||
|
||
function TestBasic:test_coroutine() | ||
local testCoroutine = coroutine.running() | ||
PCSX.nextTick(function() | ||
coroutine.resume(testCoroutine, 42) | ||
end) | ||
local r = coroutine.yield() | ||
lu.assertEquals(r, 42) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- 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' | ||
|
||
TestFile = {} | ||
|
||
function TestFile:test_buffer() | ||
local buf = Support.File.buffer() | ||
buf:write('hello') | ||
buf:write(' ') | ||
buf:write('world') | ||
lu.assertEquals(buf:size(), 11) | ||
local r = buf:read(buf:size()) | ||
lu.assertEquals(tostring(r), 'hello world') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*************************************************************************** | ||
* 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"( | ||
package.path = package.path | ||
.. ';../../../third_party/luaunit/?.lua' | ||
.. ';./third_party/luaunit/?.lua' | ||
.. ';../../../?.lua' | ||
.. ';./?.lua' | ||
)"; | ||
|
||
static const char suffix[] = R"( | ||
coroutine.resume(coroutine.create(function() | ||
PCSX.quit(require('luaunit').LuaUnit.new():runSuite '--verbose') | ||
end)) | ||
)"; | ||
|
||
template <typename... Args> | ||
int runLuaInt(Args... args) { | ||
MainInvoker invoker("-no-ui", "-cli", "-bios", "src/mips/openbios/openbios.bin", "-testmode", "-interpreter", "-luacov", | ||
"-exec", prefix, args..., "-exec", suffix); | ||
return invoker.invoke(); | ||
} | ||
|
||
template <typename... Args> | ||
int runLuaDyn(Args... args) { | ||
MainInvoker invoker("-no-ui", "-cli", "-bios", "src/mips/openbios/openbios.bin", "-testmode", "-dynarec", "-luacov", | ||
"-exec", prefix, args..., "-exec", suffix); | ||
return invoker.invoke(); | ||
} | ||
|
||
static int runLuaIntTest(const char* name) { | ||
std::string req = "require '"; | ||
req += name; | ||
req += "'"; | ||
return runLuaInt("-exec", req.c_str()); | ||
} | ||
|
||
static int runLuaDynTest(const char* name) { | ||
std::string req = "require '"; | ||
req += name; | ||
req += "'"; | ||
return runLuaDyn("-exec", req.c_str()); | ||
} | ||
|
||
TEST(LuaBasic, Interpreter) { EXPECT_EQ(runLuaIntTest("tests.lua.basic"), 0); } | ||
TEST(LuaBasic, Dynarec) { EXPECT_EQ(runLuaDynTest("tests.lua.basic"), 0); } | ||
TEST(LuaFile, Interpreter) { EXPECT_EQ(runLuaIntTest("tests.lua.file"), 0); } | ||
TEST(LuaFile, Dynarec) { EXPECT_EQ(runLuaDynTest("tests.lua.file"), 0); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters