From 8f70804a42dc13c182706b00275f0de75c150ee4 Mon Sep 17 00:00:00 2001 From: Bernhard Urban-Forster Date: Tue, 28 Apr 2020 20:40:42 +0200 Subject: [enc] add AddClass test (fails) --- mono/tests/enc/AddClass.cs | 36 ++++++++++++++++++++++++++++++++++++ mono/tests/enc/AddClass_v1.cs | 38 ++++++++++++++++++++++++++++++++++++++ mono/tests/enc/Makefile.am | 1 + 3 files changed, 75 insertions(+) create mode 100644 mono/tests/enc/AddClass.cs create mode 100644 mono/tests/enc/AddClass_v1.cs diff --git a/mono/tests/enc/AddClass.cs b/mono/tests/enc/AddClass.cs new file mode 100644 index 00000000000..24e362dc183 --- /dev/null +++ b/mono/tests/enc/AddClass.cs @@ -0,0 +1,36 @@ +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using MonoEnc; + +public class AddClass { + public static int Main (string []args) { + Assembly assm = typeof (AddClass).Assembly; + var replacer = EncHelper.Make (); + + var secondClassType = ReplaceMe (); + if (secondClassType != typeof (AddClass)) + return 1; + + try { + replacer.Update (assm); + /* doesn't work yet, thus should throw exception */ + return 2; + } catch (TargetInvocationException e) { + Console.WriteLine ("e: " + e); + if (e.InnerException.Message.Contains ("cannot add new class")) + return 0; + } + /* we should not get here, yet */ + secondClassType = ReplaceMe (); + if (secondClassType != typeof (AddClass)) { + /* would be expected if it would work */ + return 4; + } + return 3; + } + + public static System.Type ReplaceMe () { + return typeof (AddClass); + } +} diff --git a/mono/tests/enc/AddClass_v1.cs b/mono/tests/enc/AddClass_v1.cs new file mode 100644 index 00000000000..ada9324b394 --- /dev/null +++ b/mono/tests/enc/AddClass_v1.cs @@ -0,0 +1,38 @@ +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using MonoEnc; + +public class AddClass { + public static int Main (string []args) { + Assembly assm = typeof (AddClass).Assembly; + var replacer = EncHelper.Make (); + + var secondClassType = ReplaceMe (); + if (secondClassType != typeof (AddClass)) + return 1; + + try { + replacer.Update (assm); + /* doesn't work yet, thus should throw exception */ + return 2; + } catch (TargetInvocationException e) { + Console.WriteLine ("e: " + e); + if (e.InnerException.Message.Contains ("cannot add new class")) + return 0; + } + /* we should not get here, yet */ + secondClassType = ReplaceMe (); + if (secondClassType != typeof (AddClass)) { + /* would be expected if it would work */ + return 4; + } + return 3; + } + + public static System.Type ReplaceMe () { + return typeof (SecondClass); + } +} + +class SecondClass { } diff --git a/mono/tests/enc/Makefile.am b/mono/tests/enc/Makefile.am index d14219d95b4..ae1019892d2 100644 --- a/mono/tests/enc/Makefile.am +++ b/mono/tests/enc/Makefile.am @@ -2,6 +2,7 @@ include ../common_mixed.mk ROSLYNILDIFF ?=/Users/lewurm/work/roslynildiff/bin/Debug/roslynildiff.exe TESTS_REGULAR := \ + AddClass.dll \ AddStaticMethod.dll \ CallExisting.dll \ LambdaFunc.dll \ -- cgit v1.2.3