Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that nargo fmt is idempotent #4666

Closed
michaeljklein opened this issue Mar 28, 2024 · 0 comments · Fixed by #4765
Closed

Test that nargo fmt is idempotent #4666

michaeljklein opened this issue Mar 28, 2024 · 0 comments · Fixed by #4765
Assignees
Labels
enhancement New feature or request

Comments

@michaeljklein
Copy link
Contributor

Problem

We currently lack tests that nargo fmt is idempotent, i.e. that running it twice is equivalent to running it once.

This can catch bugs of the following forms:

  • Input
fn foo(){ let x = a_really_long_variable_name.followed_by_a_really_long_method_name(); x }
  • First nargo fmt
fn foo() {
    let x = a_really_long_variable_name
      .followed_by_a_really_long_method_name();
    x
}
  • Second nargo fmt
fn foo()  { // <- extra space
      let x = a_really_long_variable_name                           
                                                                   ^ trailing spaces
        .followed_by_a_really_long_method_name();
      x
    // ^ extra indent
}

Happy Case

Run nargo fmt an twice and check that the output is the same both times

Project Impact

Nice-to-have

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@michaeljklein michaeljklein added the enhancement New feature or request label Mar 28, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Mar 28, 2024
github-merge-queue bot pushed a commit that referenced this issue Apr 12, 2024
# Description

## Problem\*

Resolves #4666

## Summary\*

Ensures that `nargo_fmt(nargo_fmt(source_code)) ==
nargo_fmt(source_code)`.

Because we have expected outputs, we can avoid re-running on the
unformatted inputs:

```rust
nargo_fmt(expected_output) == expected_output
```

### Bugs found

- #4766
- #4767
- #4768

Currently failing on arrays and tuples:

```bash

---- tests::format_idempotent_array stdout ----
thread 'tests::format_idempotent_array' panicked at /Users/michaelklein/Coding/rust/noir/target/debug/build/nargo_fmt-14fb91f269fc38b6/out/execute.rs:3418:9:
assertion failed: `(left == right)`'
  left: `"fn big_array() {\n    [\n        1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 1..."` (truncated)
 right: `"fn big_array() {\n    [\n        1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 1..."` (truncated)

Differences (-left|+right):
     [
         // hello!
         1,
         // asd
-        10
+        10 
         // asdasd
     ];
 
     [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]], [[13, 14, 15], [16, 17, 18]]];


note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- tests::format_idempotent_tuple stdout ----
thread 'tests::format_idempotent_tuple' panicked at /Users/michaelklein/Coding/rust/noir/target/debug/build/nargo_fmt-14fb91f269fc38b6/out/execute.rs:776:9:
assertion failed: `(left == right)`'
  left: `"fn main() {\n    (1,);\n    (// hello\n        1,);\n    (/*hello*/ 1,);\n    (1/*hello*/,);\n    (1,);\n    (/*test*/ 1,);\n    (/*a*/ 1/*b*/,);\n    (/*a*/ 1/*b*/, /*c*/ 2/*d*/, /*c*/ 2/*d*/);\n    (/*a*/ 1/*..."` (truncated)
 right: `"fn main() {\n    (1,);\n    (// hello\n        1,);\n    (/*hello*/ 1,);\n    (1/*hello*/,);\n    (1,);\n    (/*test*/ 1,);\n    (/*a*/ 1/*b*/,);\n    (/*a*/ 1/*b*/, /*c*/ 2/*d*/, /*c*/ 2/*d*/);\n    (/*a*/ 1/*..."` (truncated)

Differences (-left|+right):
     (//
         1,);
 
     (// 1
-        1,// 2,
+        1, // 2,
         2);
 
     (/*1*/ 1, /*2*/ 2);
 
     // FIXME:
     (((//2
                 1,),),);
     (/*a*/
-        1/*b*/, /*c*/ 2/*d*/, /*c*/ 2/*d*/, /*e*/ 3/*f*/);
+        1/*b*/,
+/*c*/ 2/*d*/, /*c*/ 2/*d*/, /*e*/ 3/*f*/);
 }
```


## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: Tom French <[email protected]>
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant