Skip to content

Commit

Permalink
some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Y0SH1M4S73R committed Jul 1, 2024
1 parent 3f9049f commit c249573
Show file tree
Hide file tree
Showing 9 changed files with 500 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "i686-pc-windows-msvc"
32 changes: 16 additions & 16 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ jobs:
env:
BYOND_MAJOR: 515
BYOND_MINOR: 1640
#PKG_CONFIG_ALLOW_CROSS: 1
PKG_CONFIG_ALLOW_CROSS: 1
steps:
- uses: actions/checkout@v4
- run: |
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install g++-multilib zlib1g-dev:i386 libssl-dev:i386
# ./scripts/install_byond.sh
./scripts/install_byond.sh
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -87,20 +87,20 @@ jobs:
toolchain: stable
command: check
args: --target i686-unknown-linux-gnu --all-features
#- name: Build (Debug) (all features)
# uses: actions-rs/cargo@v1
# with:
# toolchain: stable
# command: build
# args: --target i686-unknown-linux-gnu --all-features
#- name: Run tests (all features)
# uses: actions-rs/cargo@v1
# with:
# toolchain: stable
# command: test
# args: --target i686-unknown-linux-gnu --all-features
# env:
# BYOND_BIN: /home/runner/BYOND/byond/bin
- name: Build (Debug) (all features)
uses: actions-rs/cargo@v1
with:
toolchain: stable
command: build
args: --target i686-unknown-linux-gnu --all-features
- name: Run tests (all features)
uses: actions-rs/cargo@v1
with:
toolchain: stable
command: test
args: --target i686-unknown-linux-gnu --all-features
env:
BYOND_BIN: /home/runner/BYOND/byond/bin
- name: Build (release) (default features)
uses: actions-rs/cargo@v1
with:
Expand Down
114 changes: 101 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ crate-type = ["cdylib"]
meowtonin = { git = "https://github.com/Absolucy/meowtonin" }
mlua = { version = "0.9.5", features = ["luau", "unstable"] }
thiserror = { version = "*" }
ctor = { version = "*" }
constcat = { version = "*" }
dreamluau_proc_macro = { path = "./proc_macro" }

[dev-dependencies]
glob = { version = "*" }
portpicker = { version = "*" }
test-cdylib = { version = "*" }
2 changes: 2 additions & 0 deletions dmsrc/api.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#ifndef DREAMLUAU
#define DREAMLUAU (world.system_type == MS_WINDOWS ? "dreamluau.dll" : "libdreamluau.so")
#endif

#define DREAMLUAU_CALL(func) call_ext(DREAMLUAU, "byond:[#func]")

Expand Down
11 changes: 11 additions & 0 deletions tests/dm/tests.dme
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// BEGIN_INTERNALS
// END_INTERNALS
// BEGIN_FILE_DIR
#define FILE_DIR .
// END_FILE_DIR
// BEGIN_PREFERENCES
// END_PREFERENCES
// BEGIN_INCLUDE
#include "util.dm"
#include "world.dm"
// END_INCLUDE
52 changes: 52 additions & 0 deletions tests/dm/util.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#define ASSERT_EQ_MSG(l, r, msg) if(##l != ##r) \
{\
throw EXCEPTION("Assertion failed: [##msg]");\
}

#define ASSERT_EQ(l, r) ASSERT_EQ_MSG(l, r, "[#l] == [r]")

#define ASSERT_FINDTEXT(value, needle, msg) if(!findtext(needle, value)) \
{\
throw EXCEPTION("Assertion failed: [##msg]");\
}

/proc/deep_compare_list(list/list_1, list/list_2, index_name = "")
if(list_1 == list_2)
return TRUE

if(!islist(list_1) || !islist(list_2))
return FALSE

if(list_1.len != list_2.len)
return FALSE

for(var/i in 1 to list_1.len)
var/key_1 = list_1[i]
var/key_2 = list_2[i]
if (islist(key_1) && islist(key_2))
deep_compare_list(key_1, key_2, "[index_name]\[[i]\]")
else
ASSERT_EQ_MSG(key_1, key_2, "[index_name]\[[i]\] == [key_2]")
if(istext(key_1) || islist(key_1) || ispath(key_1) || istype(key_1, /datum) || key_1 == world)
var/value_1 = list_1[key_1]
var/value_2 = list_2[key_1]
if (islist(value_1) && islist(value_2))
deep_compare_list(value_1, value_2, "[index_name]\[[key_1]\]")
else
ASSERT_EQ_MSG(value_1, value_2, "[index_name]\[[key_1]\] == [value_2]")
return TRUE

/proc/assert_result(result, status, values, variants, errmsg)
if(istext(result))
throw EXCEPTION(result)
ASSERT(islist(result))
if(status)
ASSERT_EQ_MSG(result["status"], status, "expexted status of \"[status]\", got \"[result["status"]]\"")
if(status == "error")
ASSERT_FINDTEXT(result["message"], errmsg, "expected error message containing \"[errmsg]\", got \"[result["message"]]\"")
if(isnum(values))
ASSERT_EQ(length(result["return_values"]), values)
else if(islist(values))
deep_compare_list(result["return_values"], values, "return values")
if(islist(variants))
deep_compare_list(result["variants"], variants, "variants")
Loading

0 comments on commit c249573

Please sign in to comment.