Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to write unit tests for rust build scripts?

I developed a fairly long build script. Now I need to add a set of unit tests to build.rs file. I tried to do the same as I do for regular files:

// build.rs

#[cfg(test)]
mod tests {

    #[test]
    fn test1() {
        //...
    }
}

but seems it didn’t work. Running tests doesn’t result in running test1.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This is issue #1581, that was closed as "needs an RFC". So this is not possible currently. The workaround, as @MeetTitan said, is to extract the build script logic into its own crate and make it a build-dependency and call it from the build script.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading