Skip to content

Commit ea49968

Browse files
bors[bot]irevoire
andauthored
Merge #283
283: Improve the test-macro r=brunoocasali a=irevoire Before this PR, the test macro was using the name of the function as the name of the index. That caused a bug in our test suite because, at some point, we had two tests with the same name; ``` test indexes::tests::test_fetch_info ... ok test client::tests::test_fetch_info ... ok ``` Now, this PR uses the whole path of the test instead of only the name of the function, but since meilisearch doesn't allow `:` in the index name, it then proceeds to replace all the `::` with one `-`. Thus for the previous examples the generated index name would be ``` indexes-tests-test_fetch_info client-tests-test_fetch_info ``` That seems like a good solution since rust forbids having two functions with the same name in the same module, and it's still easily readable in case we need to debug something in meilisearch from the index name. Co-authored-by: Irevoire <[email protected]>
2 parents c2b3439 + 6c571b2 commit ea49968

File tree

1 file changed

+5
-2
lines changed
  • meilisearch-test-macro/src

1 file changed

+5
-2
lines changed

meilisearch-test-macro/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@ pub fn meilisearch_test(params: TokenStream, input: TokenStream) -> TokenStream
8989

9090
// Now we do the same for the index name
9191
if use_name {
92-
let name = &outer_fn.sig.ident;
92+
let fn_name = &outer_fn.sig.ident;
93+
// the name we're going to return is the complete path to the function ie something like that;
94+
// `indexes::tests::test_fetch_info` but since the `::` are not allowed by meilisearch as an index
95+
// name we're going to rename that to `indexes-tests-test_fetch_info`.
9396
outer_block.push(parse_quote!(
94-
let name = stringify!(#name).to_string();
97+
let name = format!("{}::{}", std::module_path!(), stringify!(#fn_name)).replace("::", "-");
9598
));
9699
}
97100

0 commit comments

Comments
 (0)