haskell-src-match: Testing code generators piece by piece.

[ bsd3, library, testing ] [ Propose Tags ]

Matching of Haskell source fragments for code generator unit tests.

[Skip to Readme]
Versions [faq]
Change log ChangeLog.md
Dependencies base (>=4.3 && <4.15), containers, haskell-src-exts, interpolatedstring-perl6, pretty-simple, split, template-haskell, transformers [details]
License BSD-3-Clause
Copyright 2018-2019, Migamake Pte Ltd
Author Dmitry Krylov, Michal J. Gajda
Maintainer haskell-src-match@migamake.com
Category testing
Home page https://github.com/migamake/haskell-src-match#readme
Bug tracker https://github.com/migamake/haskell-src-match/issues
Source repo head: git clone https://github.com/migamake/haskell-src-match
Uploaded by MichalGajda at 2020-08-23T17:38:24Z
Distributions NixOS:
Downloads 35 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2020-08-23 [all 1 reports]


[Index] [Quick Jump]


Maintainer's Corner

For package maintainers and hackage trustees

Readme for haskell-src-match-

[back to package description]


Leverage your knowledge of haskell-src-exts for parsing Haskell source files, and checking that they contain prescribed fragments. This is a general problem of functional testing of code generators: One would like to make it modular, but at the same time as close to produced source as possible. I propose that you parse a Haskell output from code generator with haskell-src-exts and then match on the produced file. Matching would be best done using TemplateHaskell. Or you may also use Haskell-src-exts here in quasiquotes. so this could be an independent library that we use to make xml-typelift and json-autotype better.


  1. Parse input module with haskell-src-exts, and get a list of type declarations, and a list of instance declarations. (Easy)
  2. Use haskell-src-exts to get a data structure from quasiquote.
  3. Make a matching function out of a data structure returned by quasiquote.
  4. Add convenience interface to parse output file with haskell-src-exts and match patterns.
  5. Change all identifiers starting with an underbar (like _function) to be variables. Modify matching function accordingly
  6. Change all type identifiers starting with an U_ to be variables.
  7. Change all class identitifers starting with an U_ to be variables.
  8. Make a test suite for xml-typelift using this.

Possible improvements for the future

Not yet clear that we need this last feature for testing:

  • Generate variable substitutions from successful match.