1
use std::env;
2
use std::error::Error;
3
use std::fs::create_dir;
4
use std::path::Path;
5

            
6
use duct::cmd;
7
use which::which_in;
8

            
9
/// Runs various tools for testing purposes. This can be used to test a release
10
/// package to ensure that basic functionality works fine.
11
pub fn test_tools(directory: &Path) -> Result<(), Box<dyn Error>> {
12
    // Create a temporary directory to perform the tests in.
13
    let tmp_path = Path::new("tmp/");
14
    if !tmp_path.exists() {
15
        create_dir(tmp_path)?;
16
    }
17

            
18
    // Find the binaries
19
    let merc_lts = which_in("merc-lts", Some(directory), env::current_dir()?)?;
20

            
21
    // Copy some test files to the temporary directory.
22
    std::fs::copy(directory.join("../examples/lts/abp.aut"), tmp_path.join("abp.aut"))?;
23

            
24
    for algorithm in ["strong-bisim", "branching-bisim", "weak-bisim"] {
25
        cmd!(
26
            &merc_lts,
27
            "reduce",
28
            algorithm,
29
            "abp.aut",
30
            format!("abp.{}.aut", algorithm)
31
        )
32
        .dir(tmp_path)
33
        .run()?;
34
    }
35

            
36
    Ok(())
37
}