test_generator/
processors.rs

1//! Here we define the processors usable for each test genrator
2use crate::{Test, Testsuite, extract_name};
3use std::path::PathBuf;
4
5/// Given a Testsuite and a path, process the path in case is a wast
6/// file.
7pub fn wast_processor(_out: &mut Testsuite, p: PathBuf) -> Option<Test> {
8    let ext = p.extension()?;
9    // Only look at wast files.
10    if ext != "wast" {
11        return None;
12    }
13
14    // Ignore files starting with `.`, which could be editor temporary files
15    if p.file_stem()?.to_str()?.starts_with('.') {
16        return None;
17    }
18
19    let testname = extract_name(&p);
20
21    // The implementation of `run_wast` lives in /tests/spectest.rs
22    let body = format!("crate::run_wast(config, r#\"{}\"#)", p.display());
23
24    Some(Test {
25        name: testname,
26        body,
27    })
28}
29
30/// Given a Testsuite and a path, process the path in case is a WASI
31/// wasm file.
32pub fn wasi_processor(
33    _out: &mut Testsuite,
34    p: PathBuf,
35    wasi_filesystem_kind: &str,
36) -> Option<Test> {
37    let ext = p.extension()?;
38    // Only look at wast files.
39    if ext != "wast" {
40        return None;
41    }
42
43    let wasm_dir = {
44        let mut inner = p.clone();
45        inner.pop();
46        inner
47    };
48    let testname = extract_name(&p);
49
50    let body = format!(
51        "crate::run_wasi(config, r#\"{}\"#, \"{}\", crate::{})",
52        p.display(),
53        wasm_dir.display(),
54        wasi_filesystem_kind,
55    );
56
57    Some(Test {
58        name: testname,
59        body,
60    })
61}