Test With The Same Name As A Function Error Message
This is what it looks like when I made a test that had the same name as the function I was trying to test.
Compiling neopoligen v0.1.0 (/Users/alan/workshop/neopoligen/neopoligen)
Building [=======================> ] 177/178: neo(bin test)
error[E0061]: this function takes 0 arguments but 1 argument was supplied
--> src/bin/neo.rs:320:21
|
320 | let right = get_initial_template(&page);
| ^^^^^^^^^^^^^^^^^^^^ -----
| |
| unexpected argument of type `&neopoligen::page_v2::page::Page`
| help: remove the extra argument
|
note: function defined here
--> src/bin/neo.rs:317:8
|
317 | fn get_initial_template() {
| ^^^^^^^^^^^^^^^^^^^^
error[E0308]: mismatched types
--> src/bin/neo.rs:321:9
|
321 | assert_eq!(left, right);
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<String, _>`, found `()`
|
= note: expected enum `Result<std::string::String, _>`
found unit type `()`
= note: this error originates in the macro ``$crate::assert_eq`` which comes from the expansion of the macro ``assert_eq`` (in Nightly builds, run with -Z macro-backtrace for more info)
help: try wrapping the expression in `Err`
--> /Users/alan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pretty_assertions-1.4.0/src/lib.rs:235:35
|
235 | if !(*left_val == Err(*right_val)) {
| ++++ +
Some errors have detailed explanations: E0061, E0308.
For more information about an error, try `rustc --explain E0061`.
error: could not compile ``neopoligen`` (bin "neo" test) due to 2 previous errors
This is what my code looked like
fn get_initial_template(page: &Page) -> Result<String, String> {
Ok("a bunch of actual stuff here".to_string()
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn get_initial_template() {
let page = Page::builder_with_source();
let left = Ok("asdf".to_string());
let right = get_initial_template(&page);
assert_eq!(left, right);
}
}
The thing that threw me was the message saying the function expected zero arguments but I was passing one. That's because the test function doesn't take arguments even though my actual function does. That's what finally led me to figure out what was up.
The solution was to rename the test function to something else (e.g. get_initial_template_basic
)
-- end of line --