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
3d6f280 1
#![allow(non_snake_case)]
50effc5 2
use std::process::Command;
50effc5 3
3d6f280 4
fn plumBin() -> std::path::PathBuf {
50effc5 5
    let mut path = std::env::current_exe().unwrap();
50effc5 6
    path.pop(); // remove test binary
50effc5 7
    if path.ends_with("deps") {
50effc5 8
        path.pop();
50effc5 9
    }
50effc5 10
    path.push("plum");
50effc5 11
    path
50effc5 12
}
50effc5 13
50effc5 14
#[test]
3d6f280 15
fn compileSimpleAddProducesWasm() {
50effc5 16
    let src_path = concat!(env!("CARGO_MANIFEST_DIR"), "/../test/simple_add.plum");
1e3672d 17
    let out_path = std::env::temp_dir().join(format!("plum_test_{}.wasm", std::process::id()));
1e3672d 18
    let out_path_str = out_path.to_str().unwrap();
3d6f280 19
    let status = Command::new(plumBin())
1e3672d 20
        .args(["compile", src_path, "-o", out_path_str])
50effc5 21
        .status()
50effc5 22
        .expect("failed to run plum compile");
50effc5 23
    assert!(status.success(), "plum compile exited with: {}", status);
50effc5 24
    let bytes = std::fs::read(out_path).expect("output wasm not found");
50effc5 25
    assert_eq!(&bytes[0..4], b"\0asm");
50effc5 26
}
1a9a65c 27
1a9a65c 28
#[test]
3d6f280 29
fn compileWithImportResolvesViaLibPath() {
1a9a65c 30
    let src_path = concat!(env!("CARGO_MANIFEST_DIR"), "/../test/import_fixtures/main.plum");
1a9a65c 31
    let lib_path = concat!(env!("CARGO_MANIFEST_DIR"), "/../test/import_fixtures");
1a9a65c 32
    let out_path = std::env::temp_dir().join(format!("plum_test_import_{}.wasm", std::process::id()));
1a9a65c 33
    let out_path_str = out_path.to_str().unwrap();
3d6f280 34
    let status = Command::new(plumBin())
1a9a65c 35
        .args(["compile", src_path, "--lib-path", lib_path, "-o", out_path_str])
1a9a65c 36
        .status()
1a9a65c 37
        .expect("failed to run plum compile");
1a9a65c 38
    assert!(status.success(), "plum compile exited with: {}", status);
1a9a65c 39
    let bytes = std::fs::read(out_path).expect("output wasm not found");
1a9a65c 40
    assert_eq!(&bytes[0..4], b"\0asm");
1a9a65c 41
}