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

Add alternate hint ('#') #503

Merged
merged 7 commits into from
Jun 11, 2021
Merged

Conversation

richard-uk1
Copy link
Contributor

@richard-uk1 richard-uk1 commented Jun 6, 2021

Also make formatting match core::fmt.

This changes the current behavior, so some thought should be given before accepting. I expect it will break some tests: I'm not sure how to run them all locally so I will rely on CI to find them.

Closes #491

Also make formatting match core::fmt.
@richard-uk1
Copy link
Contributor Author

I might need a little bit of help/advice getting this through the CI.

book/src/hints.md Show resolved Hide resolved
book/src/hints.md Outdated Show resolved Hide resolved
@@ -162,14 +171,23 @@ fn format_args_real(
buf: &mut String,
) -> Result<(), fmt::Error> {
match hint {
Some(DisplayHint::NoHint { zero_pad }) => write!(buf, "{:#01$}", x, zero_pad)?,
Some(DisplayHint::Binary { zero_pad }) => write!(buf, "{:#01$b}", x, zero_pad)?,
Some(DisplayHint::NoHint { zero_pad }) => write!(buf, "{:01$}", x, zero_pad)?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to future: The body of fn format_u128 and fn format_i128 is pretty much the same. Refactor!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did play around with doing this, but you would need something that is generic over u128/i128, or you could refactor it into a macro (since the actual language tokens are the same but the types are different).

parser/src/lib.rs Show resolved Hide resolved
@Urhengulas
Copy link
Member

I'm not sure how to run them all locally so I will rely on CI to find them.

You can run the ci, by invoking cargo xtask test-all in the repository root (see cargo xtask --help for more options).

decoder/src/lib.rs Outdated Show resolved Hide resolved
@Urhengulas
Copy link
Member

Urhengulas commented Jun 7, 2021

The snapshot tests fail because it is missing all the 0xes and 0bs, e.g.:

-0.000024 INFO hex     [0x48, 0x65, 0x7f, 0x6c, 0x6c, 0x6f]
-0.000025 INFO HEX     [0x48, 0x65, 0x7F, 0x6C, 0x6C, 0x6F]
-0.000026 INFO binary  [0b1001000, 0b1100101, 0b1111111, 0b1101100, 0b1101100, 0b1101111]
+0.000024 INFO hex     [48, 65, 7f, 6c, 6c, 6f]
+0.000025 INFO HEX     [48, 65, 7F, 6C, 6C, 6F]
+0.000026 INFO binary  [1001000, 1100101, 1111111, 1101100, 1101100, 1101111]

You can run only the snapshot tests with cargo xtask test-snapshot.

We should probably duplicate all the failing ones and have one with # and one without.

@richard-uk1
Copy link
Contributor Author

richard-uk1 commented Jun 7, 2021

Thanks for the review, I'll have another go at getting it working.

Is there a way to overwrite the .out files in firmware/qemu? I'm adding in new things into the .rs which means everything changes. Mighty be easier to read as a diff.

Also add the ability to overwrite output files in snapshot test using
xtask. It is sometimes quicker to overwrite the output and then compare
it, rather than altering it manually.
@richard-uk1 richard-uk1 force-pushed the hex_match_core_fmt branch from c5bdc36 to 4c19d20 Compare June 7, 2021 14:16
@richard-uk1
Copy link
Contributor Author

OK ready for review again. Let me know if you want me to take back out the --overwrite flag from xtask, but it is very useful!

@richard-uk1
Copy link
Contributor Author

Could you let me know how to fix the last CI error?

@Urhengulas
Copy link
Member

Let me know if you want me to take back out the --overwrite flag from xtask, but it is very useful!

I agree that it seems useful, but can you please send it as a separate PR?

@Urhengulas
Copy link
Member

Could you let me know how to fix the last CI error?

Will check :)

@Urhengulas
Copy link
Member

Could you let me know how to fix the last CI error?

The failing backwards-compatability check means, that the output changed compared to the decoder version 0.2.0.
(failing ci: https://github.com/knurling-rs/defmt/pull/503/checks?check_run_id=2764884042#step:7:174)

This might mean this change qualifies as breaking, but I will check with the others.

@richard-uk1 richard-uk1 mentioned this pull request Jun 7, 2021
@Urhengulas
Copy link
Member

Could you let me know how to fix the last CI error?

The failing backwards-compatability check means, that the output changed compared to the decoder version 0.2.0.
(failing ci: https://github.com/knurling-rs/defmt/pull/503/checks?check_run_id=2764884042#step:7:174)

This might mean this change qualifies as breaking, but I will check with the others.

Since we don't guarantee backwards-compatability this isn't a problem, we just need to update these tests.

@Urhengulas
Copy link
Member

Urhengulas commented Jun 8, 2021

Since we don't guarantee backwards-compatability this isn't a problem, we just need to update these tests.

So the solution is to install qemu-run from a commit including your changes. I got it to work locally, now it is the question how to teach the CI how to do this 🤔

Comment on lines 39 to 40
leading zeros. This matches [`core::fmt` behavior](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b11809759f975e266251f7968e542756). No further
customization like padding is supported (at the moment).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No further customization like padding is supported (at the moment).

Aren't the leading zeroes a kind of padding?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm good point, would you like me to change this? Maybe to No further customization is supported (at the moment).?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I guess this should have changed with your last PR, but good that we caught it now ;D)

@Urhengulas
Copy link
Member

Can you please apply following change which should make CI pass?

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6956a1f..6cae683 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -124,8 +124,7 @@ jobs:
       - name: Run QEMU snapshot tests
         run: cargo xtask test-snapshot
       - name: install decoder v0.2.0
-        working-directory: firmware/qemu
-        run: cargo install --debug --git https://github.com/knurling-rs/defmt --rev v0.2.0-with-qemu-run-ignore-version qemu-run
+        run: cargo install --debug --path qemu-run
       - name: Backward compatibility check against decoder v0.2.0
         env:
           CARGO_TARGET_THUMBV7M_NONE_EABI_RUNNER: qemu-run

Copy link
Member

@Urhengulas Urhengulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the text-nit and then we are good to merge :)

@Urhengulas
Copy link
Member

bors d+ (now you should be able to merge it via bors yourself)

@bors
Copy link
Contributor

bors bot commented Jun 11, 2021

✌️ derekdreery can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@richard-uk1
Copy link
Contributor Author

richard-uk1 commented Jun 11, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Jun 11, 2021

Build succeeded:

@bors bors bot merged commit 19f92c5 into knurling-rs:main Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zero padding display hint diverges from core::fmt
2 participants