I use the standard way (according to the Rust book) to write unit tests:
fn func() -> i32 {
0
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn func_test() {
let res = func();
}
}
to make it compile, I have to make func
public via the pub
keyword.
Is it possible to make func
private, but use it inside the inner test module?
You can have multiple named exports per module but only one default export. Each type corresponds to one of the above syntax. After the export keyword, you can use let , const , and var declarations, as well as function or class declarations.
The module is a plain JavaScript Object representing the current module. It is local to each module and also it is private. It has exports property which is a plain JavaScript variable, set to module. exports. At the end of the file, Node.
You can export as many functions as needed as long as you remember that there can be only one default export. The default export in JavaScript is used to export a single/fallback value from a module.
Module exports are the instructions that tell Node. js which bits of code (functions, objects, strings, etc.) to export from a given file so that other files are allowed to access the exported code.
As of Rust 1.15 your code works without problems!
Previously only public symbols were imported via a wildcard-import (like use super::*;
). This behavior changed as specified in RFC 1560. You can see my full previous answer in the edit logs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With