-
Notifications
You must be signed in to change notification settings - Fork 0
/
InvalidPrograms.cs
76 lines (72 loc) · 2.59 KB
/
InvalidPrograms.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections;
using System.IO;
using mini_lang;
using NUnit.Framework;
namespace UnitTests
{
[TestFixture]
[Parallelizable]
public class InvalidPrograms
{
private static int CompilationErrors(string file)
{
string path = Path.Combine(TestContext.CurrentContext.TestDirectory, $"TestSources/Invalid/{file}");
return Compiler.Compile(path).Item2;
}
[TestCaseSource(typeof(InvalidSources), nameof(InvalidSources.Sources))]
public void InvalidProgram(string path, int atLeast)
{
var errs = 0;
Assert.DoesNotThrow(() => { errs = CompilationErrors(path); }, "AST construction should not throw");
Assert.GreaterOrEqual(errs, atLeast, $"Expected to find at least {atLeast} errors");
Console.Error.WriteLine($"Passed, {errs} error{(errs == 1 ? "" : "s")} found");
}
}
public class InvalidSources
{
public static IEnumerable Sources
{
get
{
(string, int)[] cases =
{
("array_assignment.mini", 8),
("array_creation.mini", 12),
("array_decls.mini", 5),
("array_no_index.mini", 4),
("bit_ops.mini", 5),
("break.mini", 4),
("break_n.mini", 8),
("case.mini", 5),
("comp_ops.mini", 4),
("continue.mini", 4),
("emptyfile.mini", 1),
("eof.mini", 1),
("identifiers.mini", 10),
("ifelse.mini", 3),
("invalid_assignment.mini", 12),
("logic_ops.mini", 4),
("math_ops.mini", 5),
("missing_arg.mini", 5),
("mixed_decls.mini", 3),
("mixed_inner_decls.mini", 1),
("multi_assignment.mini", 5),
("multi_decls.mini", 2),
("no_conv2bool.mini", 1),
("onetoomany.mini", 1),
("out_of_scope.mini", 1),
("redeclaration.mini", 5),
("string.mini", 6),
("unary.mini", 5),
("undeclared.mini", 3),
("while.mini", 3),
};
foreach ((string path, int expected) in cases)
{
yield return new TestCaseData(path, expected);
}
}
}
}
}