Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writes linux tests, change how byond is detected by tests, fix block and list #6

Merged
merged 53 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
025755e
test scripts
jupyterkat Nov 19, 2023
afe9b0f
force-check
jupyterkat Nov 19, 2023
5cadf3a
fuck
jupyterkat Nov 19, 2023
eeba340
oops
jupyterkat Nov 19, 2023
d028604
commands
jupyterkat Nov 19, 2023
88800d9
tries again
jupyterkat Nov 20, 2023
b254438
hmmmhmm
jupyterkat Nov 20, 2023
c796390
don't use tempfile anymore
jupyterkat Nov 20, 2023
c25857d
Revert "don't use tempfile anymore"
jupyterkat Nov 20, 2023
5cf9246
rewrite tests completely
jupyterkat Nov 21, 2023
7d139dc
make this a flag
jupyterkat Nov 21, 2023
54befe2
do not do this, the user has to set it
jupyterkat Nov 21, 2023
2f3549a
FUCK
jupyterkat Nov 21, 2023
1fff8e8
make here
jupyterkat Nov 21, 2023
7db5963
wrong version
jupyterkat Nov 21, 2023
0327c1b
set it the fuck up
jupyterkat Nov 21, 2023
576ba10
hmmmhmmmmhmmm
jupyterkat Nov 21, 2023
33430b9
oops
jupyterkat Nov 21, 2023
8f6bb04
wrong target
jupyterkat Nov 21, 2023
32d8e53
hmm
jupyterkat Nov 21, 2023
95118af
try again
jupyterkat Nov 21, 2023
80186dc
ehhh
jupyterkat Nov 21, 2023
431a7a2
print dd out
jupyterkat Nov 21, 2023
9a8db0b
force-check
jupyterkat Nov 21, 2023
7bf82e9
ignore that file
jupyterkat Nov 21, 2023
d7daf08
rewrite this
jupyterkat Nov 21, 2023
af78d47
hmm
jupyterkat Nov 21, 2023
879441d
it works like this
jupyterkat Nov 21, 2023
22cc3fb
hnggg
jupyterkat Nov 21, 2023
d57296f
try and catch it
jupyterkat Nov 21, 2023
af74f41
comment out test_block
jupyterkat Nov 21, 2023
c3c8ebf
fuckin lists
jupyterkat Nov 21, 2023
f3eb82b
disable block for now
jupyterkat Nov 21, 2023
397ea64
frick
jupyterkat Nov 21, 2023
b7fbc2c
print it out then
jupyterkat Nov 21, 2023
c3a3495
mhm
jupyterkat Nov 21, 2023
578fa74
fix this test already
jupyterkat Nov 21, 2023
7c42749
minor stuff
jupyterkat Nov 21, 2023
91c2320
assumptions
jupyterkat Nov 21, 2023
7531935
now it does stuff correctly
jupyterkat Nov 21, 2023
b671678
better
jupyterkat Nov 21, 2023
dbdf2f0
try again
jupyterkat Nov 21, 2023
3ebcee3
fix windows
jupyterkat Nov 21, 2023
5fc129a
try this
jupyterkat Nov 21, 2023
b6d7af1
fuckin try this
jupyterkat Nov 21, 2023
45f97be
fuck
jupyterkat Nov 21, 2023
759b61c
print shit
jupyterkat Nov 21, 2023
0f097a8
eee
jupyterkat Nov 21, 2023
0813dc3
fuck off
jupyterkat Nov 21, 2023
748c853
just allocate the whole thing then
jupyterkat Nov 21, 2023
69be787
oopsie
jupyterkat Nov 21, 2023
8187b0e
rearrange it a bit
jupyterkat Nov 21, 2023
02773bf
don't need to export that
jupyterkat Nov 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .cargo/config.toml

This file was deleted.

55 changes: 41 additions & 14 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
uses: actions/checkout@v4

- name: Setup Toolchains
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
target: ${{ matrix.target_name }}
targets: ${{ matrix.target_name }}

- name: Install g++ multilib (Ubuntu)
run: |
Expand Down Expand Up @@ -54,32 +54,59 @@ jobs:
toolchain: stable
command: fmt
args: --all -- --check
# TODO: write linux tests
run_test:
name: Run test

run_test_windows:
name: Run test (Windows)
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Toolchains
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
target: i686-pc-windows-msvc
targets: i686-pc-windows-msvc

- name: Restore BYOND cache
uses: actions/cache@v3
with:
path: ~/BYOND
key: linux-byond

- name: Set up byond
run: bash ./test_byond.sh
key: windows-byond

- name: Run tests
uses: actions-rs/cargo@v1
run: |
bash ./tools/setup_byond_windows.sh
$Env:BYOND_LOCATION = "$HOME\BYOND\byond\bin"
cargo test --package byondapi-test --target i686-pc-windows-msvc --test test -- test_byondapi_with_dreamdaemon --exact --nocapture

run_test_linux:
name: Run test (Ubuntu)
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Toolchains
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
command: test
args: test_byondapi_with_dreamdaemon --target i686-pc-windows-msvc
targets: i686-unknown-linux-gnu

- name: Install g++ multilib
run: |
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install build-essential g++-multilib libc6-i386 libstdc++6:i386

- name: Restore BYOND cache
uses: actions/cache@v3
with:
path: ~/BYOND
key: linux-byond

- name: Run tests
run: |
bash ./tools/setup_byond_linux.sh
source $HOME/BYOND/byond/bin/byondsetup
cargo test --package byondapi-test --target i686-unknown-linux-gnu --test test -- test_byondapi_with_dreamdaemon --exact --nocapture
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# Must be defined by users, since they may be on linux
.cargo/
2 changes: 1 addition & 1 deletion crates/byondapi-rs-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ crate-type = ["cdylib"]
byondapi = { path = "../byondapi-rs" }
byondapi-sys = { path = "../byondapi-sys" }
tempfile = "3.8.1"
test-cdylib = "1.1.0"
cargo_metadata = "0.18.1"
41 changes: 27 additions & 14 deletions crates/byondapi-rs-test/dm_project/dm_project.dme
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@
throw EXCEPTION("Object did not make it through FFI")

/test/proc/test_ref()
world.maxz = 1
world.maxx = 1
world.maxy = 1

var/turf/T = locate(1,1,1)
var/ret = call_ext("byondapi_test.dll", "byond:test_ref")(T)

world.maxz = 0
world.maxx = 0
world.maxy = 0

/test/proc/test_ptr()
var/x = "meow"
var/ptr = &x
Expand All @@ -55,6 +63,20 @@
/datum/data
var/name = "test name"

/test/proc/test_block()
world.maxz = 1
world.maxx = 2
world.maxy = 2

var/ret = call_ext("byondapi_test.dll", "byond:test_block")()

if(ret != 4)
throw EXCEPTION("Block failed [json_encode(ret)]")

world.maxz = 0
world.maxx = 0
world.maxy = 0

/test/proc/test_readwrite_var()
var/datum/data/stub = new()

Expand Down Expand Up @@ -102,20 +124,6 @@
if(ret != 5)
throw EXCEPTION("List length failed [json_encode(ret)]")

/test/proc/test_block()
world.maxz = 1
world.maxx = 2
world.maxy = 2

var/ret = call_ext("byondapi_test.dll", "byond:test_block")()

if(ret != 4)
throw EXCEPTION("Block failed [json_encode(ret)]")

world.maxz = 0
world.maxx = 0
world.maxy = 0

/test/proc/test_length_with_str()
var/str = "meowman"

Expand All @@ -136,6 +144,11 @@

if(L["parrot"] != 14)
throw EXCEPTION("list modification by key failed")

/test/proc/test_list_read()
var/list/L = list("cat" = 0, "dog" = 1, "parrot" = 5)
call_ext("byondapi_test.dll", "byond:test_list_read")(L)

// BEGIN_INTERNALS
// END_INTERNALS
// BEGIN_FILE_DIR
Expand Down
23 changes: 23 additions & 0 deletions crates/byondapi-rs-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,26 @@ pub unsafe extern "C" fn test_non_assoc_list(

ByondValue::new()
}

#[no_mangle]
pub unsafe extern "C" fn test_list_read(
argc: byondapi_sys::u4c,
argv: *mut ByondValue,
) -> ByondValue {
setup_panic_handler();
let args = parse_args(argc, argv);
let list = args.get(0).unwrap();

let map = list.get_list().unwrap();
let values = map
.into_iter()
.map(|item| item.get_string().unwrap())
.collect::<Vec<_>>();

assert_eq!(
values,
vec!["cat".to_owned(), "dog".to_owned(), "parrot".to_owned()]
);

ByondValue::new()
}
113 changes: 76 additions & 37 deletions crates/byondapi-rs-test/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,62 @@
use std::{
path::{Path, PathBuf},
process::Command,
process::{Command, Output},
};

use tempfile::TempDir;

#[test]
#[cfg(windows)]
fn test_byondapi_with_dreamdaemon() {
let dll = build_dylib();
compile();

let tempdir = tempfile::tempdir().expect("Failed to create temporary directory");

copy_to_tmp(&dll, &tempdir);
run_dreamdaemon(&tempdir);

let stderr = run_dreamdaemon(&tempdir);

check_output_rust(&tempdir);
check_output_dd(&tempdir);

#[cfg(unix)]
const LINE_COUNT: usize = 3;
#[cfg(windows)]
const LINE_COUNT: usize = 5;

if stderr.lines().count() > LINE_COUNT {
panic!("Stderr contains more than 3 lines, an error message might be printed!")
}
}

fn bin_path() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("dm_project")
.join("byond")
.join("bin")
match std::env::var("BYOND_LOCATION") {
Ok(value) => {
println!("Using byond from dir {value}");
value.into()
}
Err(_) => {
println!("Byond not found, using default location");
println!("To set a location for byond, set the BYOND_LOCATION environment variable to a path");
println!("Keep in mind that this path has to point to the /bin folder of byond");
"C:\\Program Files (x86)\\BYOND\\bin".into()
}
}
}

fn find_dm() -> Result<PathBuf, ()> {
let base_path = bin_path();

let path = if cfg!(windows) {
base_path.join("dm.exe")
} else {
base_path.join("DreamMaker")
};

if path.exists() {
Ok(path)
fn find_dm() -> PathBuf {
if cfg!(windows) {
bin_path().join("dm.exe")
} else {
Err(())
"DreamMaker".into()
}
}

fn find_dd() -> Result<PathBuf, ()> {
let base_path = bin_path();

let path = if cfg!(windows) {
base_path.join("dd.exe")
} else {
base_path.join("DreamDaemon")
};

if path.exists() {
Ok(path)
fn find_dd() -> PathBuf {
if cfg!(windows) {
bin_path().join("dd.exe")
} else {
Err(())
"DreamDaemon".into()
}
}

Expand All @@ -62,11 +65,35 @@ fn project_dir() -> PathBuf {
}

fn build_dylib() -> PathBuf {
test_cdylib::build_current_project()
let mut cmd = Command::new(option_env!("CARGO").unwrap_or("cargo"));

cmd.arg("build").arg("--message-format=json").arg("--lib");
#[cfg(windows)]
cmd.arg("--target=i686-pc-windows-msvc");
#[cfg(unix)]
cmd.arg("--target=i686-unknown-linux-gnu");
cmd.stderr(std::process::Stdio::inherit());
parse_output(cmd.output().unwrap())
}

fn parse_output(res: Output) -> PathBuf {
let mut artifact = None;
for message in cargo_metadata::Message::parse_stream(res.stdout.as_slice()) {
match message.unwrap() {
cargo_metadata::Message::CompilerMessage(m) => eprintln!("{}", m),
cargo_metadata::Message::CompilerArtifact(a) => artifact = Some(a),
_ => (),
}
}

if !res.status.success() {
panic!("Failed to build")
}
artifact.unwrap().filenames[0].clone().into()
}

fn compile() {
let dm_compiler = find_dm().expect("To run this integration test you must place a copy of BYOND binaries in dm_project/byond/bin");
let dm_compiler = find_dm();

let output = Command::new(dm_compiler)
.current_dir(project_dir())
Expand Down Expand Up @@ -98,17 +125,27 @@ fn copy_to_tmp(dll: &Path, tempdir: &TempDir) {
std::fs::copy(dll, target.join("byondapi_test.dll")).expect("Failed to copy byondapi_test.dll");
}

fn run_dreamdaemon(tempdir: &TempDir) {
let dream_daemon = find_dd().expect("To run this integration test you must place a copy of BYOND binaries in dm_project/byond/bin");
fn run_dreamdaemon(tempdir: &TempDir) -> String {
let dream_daemon = find_dd();

let _dd_output = Command::new(dream_daemon)
let dd_output = Command::new(dream_daemon)
.current_dir(tempdir.path())
.arg("dm_project.dmb")
.arg("-trusted")
.output()
.expect("DreamDaemon crashed");
let stdout = std::str::from_utf8(&dd_output.stdout).unwrap();
let stderr = std::str::from_utf8(&dd_output.stderr).unwrap();
if !stdout.is_empty() {
eprintln!("Stdout:-------------------------------------------------------------------");
eprintln!("{stdout}");
}

// println!("{:#?}", _dd_output);
if !stderr.is_empty() {
eprintln!("Stderr:-------------------------------------------------------------------");
eprintln!("{stderr}");
}
stderr.to_owned()
}

fn check_output_dd(tempdir: &TempDir) {
Expand All @@ -118,6 +155,7 @@ fn check_output_dd(tempdir: &TempDir) {

let log = std::fs::read_to_string(log).expect("Failed to read log");

eprintln!("DDlogs:-------------------------------------------------------------------");
eprintln!("{}", log);

assert!(
Expand All @@ -131,6 +169,7 @@ fn check_output_rust(tempdir: &TempDir) {

if log.exists() {
let log = std::fs::read_to_string(log).expect("Failed to read log");
eprintln!("Rustlogs:-----------------------------------------------------------------");
eprintln!("{}", log);
panic!("Rust error log was produced!");
}
Expand Down
Loading
Loading