-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFailingTests.cs
106 lines (90 loc) · 3.55 KB
/
FailingTests.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using JSIL.Internal;
using NUnit.Framework;
namespace JSIL.Tests {
[TestFixture]
public class FailingTests : GenericTestFixture {
[Test]
[TestCaseSource("FailingTestCasesSource")]
public void FailingTestCases (object[] parameters) {
var passed = false;
var testFilename = (string)parameters[0];
var translationFailures = new List<Exception>();
Exception thrown = null;
IEnumerable<Metacomment> metacomments = null;
try {
metacomments = RunSingleComparisonTestCase(
parameters,
makeConfiguration: () => {
var cfg = MakeConfiguration();
cfg.UseThreads = false;
return cfg;
},
onTranslationFailure: (exc) => {
lock (translationFailures)
translationFailures.Add(exc);
}
);
passed = true;
} catch (Exception exc) {
thrown = exc;
}
foreach (var failure in translationFailures)
Console.WriteLine(failure.ToString());
if (metacomments != null) {
foreach (var metacomment in metacomments) {
Console.WriteLine(metacomment);
switch (metacomment.Command.ToLower()) {
case "assertfailurestring":
Assert.IsTrue(
translationFailures.Any(
(f) => f.ToString().Contains(metacomment.Arguments)
),
"Expected translation to generate a failure containing the string '" + metacomment.Arguments + "'"
);
break;
case "assertthrows":
if ((thrown == null) || (thrown.GetType().Name.ToLower() != metacomment.Arguments.Trim().ToLower()))
Assert.Fail("Expected test to throw an exception of type '" + metacomment.Arguments + "'");
break;
case "reference":
case "compileroption":
case "jsiloption":
break;
default:
throw new NotImplementedException("Command type '" + metacomment.Command + "' not supported in metacomments");
}
}
}
Assert.IsFalse(passed, "Test passed when it should have failed");
}
protected IEnumerable<TestCaseData> FailingTestCasesSource () {
return FolderTestSource("FailingTestCases", MakeDefaultProvider(), new AssemblyCache());
}
[Test]
public void VerbatimDynamic()
{
try
{
var js = GetJavascript(
@"SpecialTestCases\Issue548.cs",
"{\"obj1\":\"{}\"}"
);
}
catch (Exception)
{
return;
}
Assert.Fail("Test passed when it should have failed");
}
}
}