noir-lang / noir

Noir is a domain specific language for zero knowledge proofs
https://noir-lang.org
Apache License 2.0
823 stars 178 forks source link

nargo test --package <PACKAGE_NAME> fails to run tests #4003

Open nfurfaro opened 6 months ago

nfurfaro commented 6 months ago

Aim

High level context

I want to create temporary noir files with tests and run the tests. This is related to a WIP tool for mutation testing. Currently, the temp files are created in a sibling directory to /src called /temp, but the location is not a hard requirement. I've tried making the /temp dir its own package by adding a Nargo.toml, and setting the package type to lib. Here is an simplified example of the project structure (Verifier.toml & Prover.toml omitted):

├── Nargo.toml
├── src
│   └── main.nr
├── temp
│   ├── lib.nr
│   ├── mutation_0.nr
│   ├── mutation_1.nr
│   ├── mutation_2.nr
│   ├── mutation_3.nr
│   ├── mutation_4.nr
│   ├── mutation_5.nr
│   └── Nargo.toml

Here is my Nargo.toml in the /temp lib: image

And here is the lib.nr: image

Expected Behavior

I expected Nargo to run the tests in the temp files in the /temp dir.

Bug

When I run nargo test --package temp from the project root, I get the following: image

If I cd into the temp dir and try the same command, I get the same result: image

Note

I tried adding a log for debugging purposes to this line in the nargo_cli source code: https://github.com/noir-lang/noir/blob/5be049eee6c342649462282ee04f6411e6ea392c/tooling/nargo_cli/src/cli/test_cmd.rs#L60 to see the value of the selection var at this point. selection is set correctly here:

❯ /home/furnic/Dev/noir_dev/noir/target/debug/nargo test --package hunter
Running tests for Selected(CrateName("hunter"))...
Selected package `hello_world` was not found

To Reproduce

  1. Create a new noir project with nargo new
  2. Add a subdirectory to the project and create a second library package inside.
  3. Include at least 1 noir test in the new package
  4. Attempt to run your new test.

I've scaffolded this in a gist to simplify reproducing: https://gist.github.com/nfurfaro/4a2f49cf0564393b7cec7b776423220d

Note

I installed via Noirup, but this option is not available in the dropdown menu.

Installation Method

Binary

Nargo Version

nargo version = 0.19.4 (git version hash: 4d133c50a50f21ca23861a9d1987207bd8783d36, is dirty: false)

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

TomAFrench commented 5 months ago

It's hard to diagnose this without having a concrete example of the structure you're describing. Having a Nargo package inside of another Nargo project isn't supported, instead temp should be another package under a https://noir-lang.org/docs/noir/modules_packages_crates/workspaces.

Savio-Sou commented 5 months ago

@nfurfaro thanks for submitting the Issue. Is this still relevant in newer versions of Noir?

nfurfaro commented 5 months ago

@Savio-Sou I will test this weekend and get back to you. I think so, but need to confirm.