hpack
hpack copied to clipboard
Verbatim imports put at bottom of stanza first time
https://github.com/sol/hpack/pull/490 moves import lines to the top of the stanza, but it only happens the first time hpack is called.
Repro:
- Run
rm *.cabal - Add
verbatim: { import: ... }line to a stanza - Run
hpack - Cabal file incorrectly has
importline at bottom - Run
hpackagain - Cabal file correctly has
importline moved to top
Hi @brandon-leapyear 👋 thanks for reporting this!
This is something we want to fix. I am away from my computer for the next couple of days. Still, I took a quick look at the code. From what I understand, these are the underlying issues:
- I did not add a test with #490. Our acceptance tests accept any field order, so adding an acceptance test may require some extra work. We have existing tests for field sorting in: https://github.com/sol/hpack/blob/7c46a3e4030b6d9c2e1eeb45d015e5f7d84825c9/test/Hpack/Render/DslSpec.hs#L134 However the code added in
#490is not covered by those tests. - We only sort stanza fields if we already have an existing
fieldOrder(and by extension only when we already have a.cabal-file): https://github.com/sol/hpack/blob/d9cbc10813e752140f0f22ee24c1420786c7e893/src/Hpack/Render.hs#L126
:sparkles: This is an old work account. Please reference @brandonchinn178 for all future communication :sparkles:
Makes sense! I don't know if you have any end-to-end tests, but I think a simple end-to-end test for this could be:
- In an empty directory, create
package.yamlthat imports a common stanza adding a dependency (e.g.aesonorcontainers) + write a library file using that dependency (such that a cabal file lacking that dependency would fail to build) - In that directory, run
hpackandcabal - Build should succeed