Test for GHC compile time errors

I'm working on proto-lens#400 tweaking a Haskell code generator. In one of the tests I'd like to verify that certain API has not been built. Specifically, I want to ensure that a certain type of program will not type check successfully. I'd also have a similar program with one identifier changed which should compile, to guard against a typo breaking the test. Reading Extending and using GHC as a Library I have managed to have my test write a small file and compile it using GHC as a library.

But I need the code emitted by the test to load some other modules. Specifically the output of the code generator of that project and its runtime environment with transitive dependencies. I have at best a very rough understanding of stack and hpack, which is providing the build time system. I know I can add dependencies to some package.yaml file to make them available to individual tests, but I have no clue how to access such dependencies from the GHC session set up as part of running the test. I imagine I might find some usable data in some environment variables, but I also believe such an approach might be undocumented and prone to break without warning.

How can I have a test case use GHC as a library and have it access dependencies expressed in package.yaml? Или, в качестве альтернативы, могу ли я использовать какую-либо конструкцию, отличную от обычного тестового примера, для выражения файла с зависимостями, но проверить, что файл не компилируется?

1 ответ

Я не знаю, относится ли это к вам, потому что в моей голове слишком много деталей, но один из способов проверить ошибки типа - создать свой набор тестов с -fdefer-type-errors и перехватить исключение во время выполнения (типа TypeError).

Другие вопросы по тегам