Permalink
Browse files

Add automated tests for some tricky cases that type caching needs to …

…handle
  • Loading branch information...
1 parent 6259267 commit 4257687b25de01e899c2862aca6a0982fe201fc8 @kg kg committed Aug 14, 2012
View
@@ -2867,23 +2867,13 @@ JSIL.InitializeType = function (type) {
var key = $jsilcore.cctorKeys[i];
var cctor = classObject[key];
- // Type cachers need to be able to form reference cycles, so we suppress warning messages
- // while one of them is running.
- var suppress = (key === "__TypeCacher__");
-
- if (suppress)
- $jsilcore.SuppressRecursiveConstructionErrors += 1;
-
if (typeof (cctor) === "function") {
try {
cctor.call(classObject);
} catch (e) {
JSIL.Host.error(e, "Unhandled exception in static constructor for type " + JSIL.GetTypeName(type) + ": ");
}
}
-
- if (suppress)
- $jsilcore.SuppressRecursiveConstructionErrors -= 1;
}
}
View
@@ -44,6 +44,7 @@ public class ComparisonTests : GenericTestFixture {
test.Run("8");
}
}
+
[Test]
[TestCaseSource("DynamicsSource")]
public void Dynamics (object[] parameters) {
@@ -439,6 +440,16 @@ public class ComparisonTests : GenericTestFixture {
);
}
+ [Test]
+ public void TypeReferences () {
+ RunComparisonTests(
+ new[] {
+ @"SpecialTestCases\CyclicTypeReferences.cs",
+ @"SpecialTestCases\CyclicTypeInheritance.cs"
+ }, null, MakeDefaultProvider()
+ );
+ }
+
#region Folders
[Test]
@@ -0,0 +1,33 @@
+using System;
+using JSIL.Meta;
+
+public static class Program {
+ public static void Main (string[] args) {
+ var o = new Obj();
+ Console.WriteLine(o.Value);
+ }
+
+ public static int Double (int x) {
+ return x * 2;
+ }
+}
+
+public class Obj : Base {
+ public static int StaticValue;
+ public int Value;
+
+ static Obj () {
+ StaticValue = Program.Double(2);
+ }
+
+ public Obj ()
+ : base () {
+ Value = Program.Double(StaticValue);
+ }
+}
+
+public class Base {
+ public Base () {
+ Console.WriteLine(Obj.StaticValue);
+ }
+}
@@ -0,0 +1,50 @@
+using System;
+using JSIL.Meta;
+
+public static class Program {
+ public static void Main (string[] args) {
+ Console.WriteLine(A.GetB());
+ Console.WriteLine(B.GetC());
+ Console.WriteLine(C.GetA());
+ }
+
+ public static int Double (int x) {
+ return x * 2;
+ }
+}
+
+public static class A {
+ public static int a;
+
+ static A () {
+ a = Program.Double(1);
+ }
+
+ public static int GetB () {
+ return B.b;
+ }
+}
+
+public static class B {
+ public static int b;
+
+ static B () {
+ b = Program.Double(2);
+ }
+
+ public static int GetC () {
+ return C.c;
+ }
+}
+
+public static class C {
+ public static int c;
+
+ static C () {
+ c = Program.Double(4);
+ }
+
+ public static int GetA () {
+ return A.a;
+ }
+}
View
@@ -206,6 +206,8 @@
<None Include="SimpleTestCases\EnumPrePostIncrement.cs" />
<None Include="TestCases\StructBoxing.cs" />
<None Include="SpecialTestCases\AsyncStateMachineSwitchGoto.cs" />
+ <None Include="SpecialTestCases\CyclicTypeReferences.cs" />
+ <None Include="SpecialTestCases\CyclicTypeInheritance.cs" />
<Compile Include="XMLTests.cs" />
<Compile Include="DependencyTests.cs" />
<None Include="TestCases\GenericParameterNameShadowing.cs" />

0 comments on commit 4257687

Please sign in to comment.