Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/naasking/codefault

A simple testing library to check that compilation fails on code fragments
https://github.com/naasking/codefault

Last synced: 9 days ago
JSON representation

A simple testing library to check that compilation fails on code fragments

Awesome Lists containing this project

README

        

# CodeFault

A library to check that compilation fails on code fragments:

using (var code = new Compiler("C#"))
{
code.Reference() // reference System.dll assembly
.Compile(@"
using System;

class Foo where T : Delegate
{
}")
.FailsWith(code.Error("CS0702", line:4)); // Constraint cannot be special class 'Delegate'
}

If the compilation does not have that error at the given line,
it will throw an exception. This allows unit testing abstractions
that are supposed to prevent certain errors at compile-time.