-
Notifications
You must be signed in to change notification settings - Fork 0
/
ValidPrograms.cs
58 lines (50 loc) · 1.79 KB
/
ValidPrograms.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Collections;
using System.IO;
using mini_lang;
using NUnit.Framework;
namespace UnitTests
{
[TestFixture]
[Parallelizable]
public class ValidPrograms
{
private static (Program, int) RunCompiler(string file)
{
string path = Path.Combine(TestContext.CurrentContext.TestDirectory, $"TestSources/Valid/{file}");
return Compiler.Compile(path);
}
[TestCaseSource(typeof(Data), nameof(Data.AllPrograms))]
public void CorrectProgram(string path)
{
var errs = 0;
Program program = null;
Assert.DoesNotThrow(() =>
{
(Program p, int errors) = RunCompiler(path);
errs = errors;
program = p;
},
"AST construction should not throw");
Assert.Zero(errs);
var codeGen = new CodeBuilder(Path.Combine(TestContext.CurrentContext.WorkDirectory, path));
Assert.DoesNotThrow(() => { program.Accept(codeGen); }, "Code generation should not throw");
string ilPath = codeGen.OutputFile;
Utils.Link(ilPath);
Utils.Verify(Path.ChangeExtension(ilPath, "exe"));
}
}
public class Data
{
public static IEnumerable AllPrograms
{
get
{
string folder = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestSources/Valid");
foreach (string path in Directory.EnumerateFiles(folder))
{
yield return Path.GetFileName(path);
}
}
}
}
}