Skip to content

Failure to run unit test when using with workspace #19

@nbigaouette-eai

Description

@nbigaouette-eai

When using this crate in another crate part of a workspace, calling cargo test will fail at the machine!() macro. For example:

error: proc macro panicked
  --> /Users/nbigaouette/example/subcrate/src/lib.rs:18:1
   |
18 | / machine::machine!(
19 | |     /// Different states
20 | |     #[derive(Debug, PartialEq)]
21 | |     enum MyState {
...  |
26 | |     }
27 | | );
   | |__^
   |
   = help: message: error writing machine definition: Os { code: 2, kind: NotFound, message: "No such file or directory" }

error: aborting due to previous error

error: test failed, to rerun pass '--doc'

The error comes from this file:

machine/src/lib.rs

Lines 448 to 456 in 20b140d

let file_name = format!("target/machine/{}.rs", name.to_string().to_lowercase());
let _ = create_dir("target/machine");
File::create(&file_name)
.and_then(|mut file| {
file.seek(std::io::SeekFrom::End(0))?;
file.write_all(gen.to_string().as_bytes())?;
file.flush()
})
.expect("error writing machine definition");

The macro will use target/machine to output the generated file, but this is not the proper way to get the path. The target directory is expected to be under subcrate/target but this directory does not get created by cargo. I had to manually create it for the macro to succeed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions