kowainik / stan

🕵️ Haskell STatic ANalyser
https://kowainik.github.io/projects/stan
Mozilla Public License 2.0
562 stars 47 forks source link

downstream failure in test cases for STAN-0204 and STAN-0205 #409

Open maralorn opened 3 years ago

maralorn commented 3 years ago

Hey!

I am trying to get stan tests running in nixpkgs. As dependencies we use stackage-nightly + newest versions from hackage if not on stackage. This conforms to the cabal bounds given in stan.cabal (with exception of pretty-simple (see #408), if that's the culprit I am very sorry, but it seems unlikely.) I get the following test error, which does not happen in your CI:

    ObservationId is properly ignored

Failures:

  test/Test/Stan/Analysis/Common.hs:62:5:
  1) Static Analysis, Anti-patterns, STAN-0204: finds usage of 'Data.HashMap.size'
       expected: Just (Observation {observationId = Id {unId = "OBS-STAN-0204-wu5bTi-28:19"}, observationInspectionId = Id {unId = "STAN-0204"}, observationSrcSpan = SrcSpanOneLine "target/Target/AntiPattern.hs" 28 19 26, observationFile = "target/Target/AntiPattern.hs", observationModuleName = ModuleName {unModuleName = "Target.AntiPattern"}, observationFileContent = ""})
        but got: Nothing

  To rerun use: --match "/Static Analysis/Anti-patterns/STAN-0204: finds usage of 'Data.HashMap.size'/"

  test/Test/Stan/Analysis/Common.hs:62:5:
  2) Static Analysis, Anti-patterns, STAN-0204: finds usage of 'length' for 'HashMap'
       expected: Just (Observation {observationId = Id {unId = "OBS-STAN-0204-wu5bTi-31:21"}, observationInspectionId = Id {unId = "STAN-0204"}, observationSrcSpan = SrcSpanOneLine "target/Target/AntiPattern.hs" 31 21 27, observationFile = "target/Target/AntiPattern.hs", observationModuleName = ModuleName {unModuleName = "Target.AntiPattern"}, observationFileContent = ""})
        but got: Nothing

  To rerun use: --match "/Static Analysis/Anti-patterns/STAN-0204: finds usage of 'length' for 'HashMap'/"

  test/Test/Stan/Analysis/Common.hs:62:5:
  3) Static Analysis, Anti-patterns, STAN-0205: finds usage of 'Data.HashSet.size'
       expected: Just (Observation {observationId = Id {unId = "OBS-STAN-0205-wu5bTi-34:19"}, observationInspectionId = Id {unId = "STAN-0205"}, observationSrcSpan = SrcSpanOneLine "target/Target/AntiPattern.hs" 34 19 26, observationFile = "target/Target/AntiPattern.hs", observationModuleName = ModuleName {unModuleName = "Target.AntiPattern"}, observationFileContent = ""})
        but got: Nothing

  To rerun use: --match "/Static Analysis/Anti-patterns/STAN-0205: finds usage of 'Data.HashSet.size'/"

  test/Test/Stan/Analysis/Common.hs:62:5:
  4) Static Analysis, Anti-patterns, STAN-0205: finds usage of 'length' for 'HashSet'
       expected: Just (Observation {observationId = Id {unId = "OBS-STAN-0205-wu5bTi-37:21"}, observationInspectionId = Id {unId = "STAN-0205"}, observationSrcSpan = SrcSpanOneLine "target/Target/AntiPattern.hs" 37 21 27, observationFile = "target/Target/AntiPattern.hs", observationModuleName = ModuleName {unModuleName = "Target.AntiPattern"}, observationFileContent = ""})
        but got: Nothing

  To rerun use: --match "/Static Analysis/Anti-patterns/STAN-0205: finds usage of 'length' for 'HashSet'/"

Randomized with seed 1738248362

Any insight into what could be going wrong would be highly appreciated.

chshersh commented 3 years ago

Hi @maralorn! Most likely the reason for this error is the fact that the name of the unordered-containers package is not mentioned in the HIE files. Turns out, different build tools change package names on different systems using different tricks to satisfy the file path limit. Moreover, GHC itself allows registering packages under arbitrary names.

We've implemented several hacks to support as many standard use cases as possible:

https://github.com/kowainik/stan/blob/eed7dc32157be02911020ca2590bbb4eae109b87/src/Stan/NameMeta.hs#L65-L75

But I'm personally not on NixOS and I don't use Nix to build Haskell packages, so I can't debug the issue by myself. My guess would be is that Nix doesn't mention the package name at all when registering dependencies. But to be sure, one must debug the content of HIE files.