plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


plum-cli/tests/compile_tests.rs
#![allow(non_snake_case)]
use std::process::Command;

fn plumBin() -> std::path::PathBuf {
    let mut path = std::env::current_exe().unwrap();
    path.pop(); // remove test binary
    if path.ends_with("deps") {
        path.pop();
    }
    path.push("plum");
    path
}

#[test]
fn compileSimpleAddProducesWasm() {
    let src_path = concat!(env!("CARGO_MANIFEST_DIR"), "/../test/simple_add.plum");
    let out_path = std::env::temp_dir().join(format!("plum_test_{}.wasm", std::process::id()));
    let out_path_str = out_path.to_str().unwrap();
    let status = Command::new(plumBin())
        .args(["compile", src_path, "-o", out_path_str])
        .status()
        .expect("failed to run plum compile");
    assert!(status.success(), "plum compile exited with: {}", status);
    let bytes = std::fs::read(out_path).expect("output wasm not found");
    assert_eq!(&bytes[0..4], b"\0asm");
}

#[test]
fn compileWithImportResolvesViaLibPath() {
    let src_path = concat!(env!("CARGO_MANIFEST_DIR"), "/../test/import_fixtures/main.plum");
    let lib_path = concat!(env!("CARGO_MANIFEST_DIR"), "/../test/import_fixtures");
    let out_path = std::env::temp_dir().join(format!("plum_test_import_{}.wasm", std::process::id()));
    let out_path_str = out_path.to_str().unwrap();
    let status = Command::new(plumBin())
        .args(["compile", src_path, "--lib-path", lib_path, "-o", out_path_str])
        .status()
        .expect("failed to run plum compile");
    assert!(status.success(), "plum compile exited with: {}", status);
    let bytes = std::fs::read(out_path).expect("output wasm not found");
    assert_eq!(&bytes[0..4], b"\0asm");
}