/usr/share/mummy-1.0.3/CSharpTestDriver.cs.in is in libkitware-mummy-runtime1.0-cil 1.0.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | class MummyCSharpTestDriver
{
public static void Main(string[] args)
{
try
{
string test;
if (0 == args.Length)
{
test = GetTestNameInteractively();
}
else
{
test = args[0];
}
System.Type t = System.Type.GetType(test + "Class");
if (null == t)
{
throw new System.ArgumentException(System.String.Format(
"error: could not create a Type object for '{0}'...\n\n{1}\n{2}\n{3}\n{4}\n\n{5}\n\n",
test + "Class",
"Typo?",
"Did you follow the C# test driver naming convention?",
"Did you add the test to the CMakeLists.txt file?",
"Did you reconfigure/rebuild after adding the test?",
"Test 'method' name should equal 'file name without extension'... Test 'public class' name should be the same but with 'Class' appended..."
));
}
System.Reflection.MethodInfo mi = t.GetMethod(test);
if (null == mi)
{
throw new System.ArgumentException(System.String.Format(
"error: could not find method named '{0}'", test));
}
// Expected method signature is "same as C# Main": returns void
// and takes a string array as its one argument...
//
object[] invArgs = new object[1];
invArgs[0] = args;
mi.Invoke(null, invArgs);
// Before forced garbage collection, make sure the mummy Runtime
// is not holding onto any wrapper objects anymore:
//
Kitware.mummy.Runtime.Methods.ForceRemoveCallbacks();
Kitware.mummy.Runtime.Methods.ForceClearWrappedObjectsTable();
// Force a garbage collection prior to exiting the test
// so that any memory leaks reported are likely to be
// *actual* leaks of some sort rather than false reports:
//
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
// Test finished without throwing any exceptions...
// Therefore, it passed. Exit with a zero ExitCode.
//
System.Environment.ExitCode = 0;
}
catch(System.Exception exc)
{
// Catch anything, spit it out to the console so it can be captured
// by ctest. Exit with a non-zero ExitCode.
//
System.Console.Error.WriteLine("================================================================================");
System.Console.Error.WriteLine("");
System.Console.Error.WriteLine("Mummy C# test driver caught System.Exception:");
System.Console.Error.WriteLine("");
System.Console.Error.WriteLine("{0}", exc.ToString());
System.Console.Error.WriteLine("");
System.Console.Error.WriteLine("================================================================================");
System.Console.Error.WriteLine("");
System.Environment.ExitCode = 2345;
}
}
public static string[] GetAvailableTests()
{
System.Collections.ArrayList testList = new System.Collections.ArrayList();
System.Reflection.Assembly assy = System.Reflection.Assembly.GetExecutingAssembly();
foreach (System.Type et in assy.GetExportedTypes())
{
if (et.IsClass)
{
foreach (System.Reflection.MethodInfo mInfo in et.GetMethods())
{
if (et.Name == mInfo.Name + "Class")
{
testList.Add(mInfo.Name);
}
}
}
}
return (string[])testList.ToArray(System.Type.GetType("System.String"));
}
public static string GetTestNameInteractively()
{
string s = "Available tests:\n";
string[] tests = GetAvailableTests();
int i = 0;
foreach (string xyz in tests)
{
s = System.String.Format("{0} {1}: {2}\n", s, i, xyz);
++i;
}
s = System.String.Format("{0}To run a test, enter the test number: ", s);
System.Console.Write(s);
string choice = System.Console.ReadLine();
int choiceNumber = -1;
try
{
choiceNumber = System.Convert.ToInt32(choice);
if (choiceNumber < 0 || choiceNumber >= tests.Length)
{
throw new System.ArgumentOutOfRangeException(System.String.Format(
"'{0}' is an invalid test number.\nExiting without running a test.\n\n",
choice));
}
}
catch (System.Exception)
{
System.Console.Error.Write(System.String.Format(
"'{0}' is an invalid test number.\nExiting without running a test.\n\n",
choice));
throw;
}
return tests[choiceNumber];
}
}
|