Author: marek
Date: 2005-03-10 03:59:37 -0500 (Thu, 10 Mar 2005)
New Revision: 41639

Added:
   trunk/mcs/errors/TestRunner.cs
   trunk/mcs/errors/know-issues-mcs
Modified:
   trunk/mcs/errors/ChangeLog
Log:
2005-03-10 Marek Safar <[EMAIL PROTECTED]>

        * TestRunner.cs: New fast test runner.

Modified: trunk/mcs/errors/ChangeLog
===================================================================
--- trunk/mcs/errors/ChangeLog  2005-03-10 08:52:34 UTC (rev 41638)
+++ trunk/mcs/errors/ChangeLog  2005-03-10 08:59:37 UTC (rev 41639)
@@ -1,3 +1,7 @@
+2005-03-10 Marek Safar <[EMAIL PROTECTED]>
+
+       * TestRunner.cs: New fast test runner.
+
 2005-03-09  Raja R Harinath  <[EMAIL PROTECTED]>
 
        * cs1618-2.cs: New test for partial classes.

Added: trunk/mcs/errors/TestRunner.cs
===================================================================
--- trunk/mcs/errors/TestRunner.cs      2005-03-10 08:52:34 UTC (rev 41638)
+++ trunk/mcs/errors/TestRunner.cs      2005-03-10 08:59:37 UTC (rev 41639)
@@ -0,0 +1,250 @@
+using System;
+using System.IO;
+using System.Diagnostics;
+using System.Reflection;
+using System.Text;
+using System.Collections;
+
+namespace TestRunner {
+
+       interface ITester
+       {
+               string Output { get; }
+               bool Invoke (string[] args);
+       }
+
+       class ReflectionTester: ITester {
+               MethodInfo ep;
+               object[] method_arg;
+               StringWriter output;
+
+               public ReflectionTester (Assembly a)
+               {
+                       ep = a.GetType 
("Mono.CSharp.CompilerCallableEntryPoint").GetMethod ("InvokeCompiler", 
+                               BindingFlags.Static | BindingFlags.Public);
+                       if (ep == null)
+                               throw new MissingMethodException ("static 
InvokeCompiler");
+                       method_arg = new object [1];
+               }
+
+               public string Output {
+                       get {
+                               return output.GetStringBuilder ().ToString ();
+                       }
+               }
+
+               public bool Invoke(string[] args)
+               {
+                       TextWriter old_writer = Console.Error;
+                       output = new StringWriter ();
+                       Console.SetError (output);
+                       method_arg [0] = args;
+                       try {
+                               return (bool)ep.Invoke (null, method_arg);
+                       }
+                       finally {
+                               Console.SetError (old_writer);
+                       }
+               }
+       }
+
+       class ProcessTester: ITester
+       {
+               ProcessStartInfo pi;
+               string output;
+
+               public ProcessTester (string p_path)
+               {
+                       pi = new ProcessStartInfo ();
+                       pi.FileName = p_path;
+                       pi.CreateNoWindow = true;
+                       pi.WindowStyle = ProcessWindowStyle.Hidden;
+                       pi.RedirectStandardError = true;
+                       pi.UseShellExecute = false;
+               }
+
+               public string Output {
+                       get {
+                               return output;
+                       }
+               }
+
+               public bool Invoke(string[] args)
+               {
+                       StringBuilder sb = new StringBuilder ();
+                       foreach (string s in args) {
+                               sb.Append (s);
+                               sb.Append (" ");
+                       }
+                       pi.Arguments = sb.ToString ();
+                       Process p = Process.Start (pi);
+                       output = p.StandardError.ReadToEnd ();
+                       p.WaitForExit ();
+                       return p.ExitCode == 0;
+               }
+       }
+
+       class Tester {
+
+               static ArrayList know_issues = new ArrayList ();
+               static ArrayList regression = new ArrayList ();
+
+               static int Main(string[] args) {
+                       if (args.Length != 3) {
+                               Console.WriteLine ("Usage: TestRunner test-dir 
compiler know-issues");
+                               return 1;
+                       }
+
+                       string test_directory = args [0];
+                       string mcs = args [1];
+                       string issue_file = args [2];
+
+                       string wrong_errors_file = Path.Combine 
(test_directory, issue_file);
+                       string[] files = Directory.GetFiles (test_directory, 
"cs*.cs");
+
+                       ReadWrongErrors (wrong_errors_file);
+                       ITester tester;
+                       try {
+                               tester = new ReflectionTester 
(Assembly.LoadFile (mcs));
+                       }
+                       catch (Exception) {
+                               Console.Error.WriteLine ("Switching to command 
line mode (compiler entry point was not found)");
+                               if (!File.Exists (mcs)) {
+                                       Console.WriteLine ("ERROR: Tested 
compiler was not been found");
+                                       return 1;
+                               }
+                               tester = new ProcessTester (mcs);
+                       }
+
+                       string[] test_args;
+                       int success = 0;
+                       int total = files.Length;
+                       foreach (string s in files) {
+                               string filename = Path.GetFileName (s);
+                               if (filename.StartsWith ("CS")) { // Windows 
hack
+                                       total--;
+                                       continue;
+                               }
+                           
+                               Console.Write (filename);
+
+                               string[] extra = GetExtraOptions (s);
+                               if (extra != null) {
+                                       test_args = new string [1 + 
extra.Length];
+                                       extra.CopyTo (test_args, 0);
+                               } else {
+                                       test_args = new string [1];
+                               }
+                               test_args [test_args.Length - 1] = s;
+
+                               Console.Write ("...\t");
+                               try {
+
+                                       bool result = tester.Invoke (test_args);
+                                       if (result) {
+                                               PrintFailed (filename);
+                                               continue;
+                                       }
+
+                                       int end_char = filename.IndexOfAny (new 
char [] { '-', '.' } );
+                                       string expected = filename.Substring 
(2, end_char - 2);
+                                       if (CheckCompilerError (expected, 
tester.Output)) {
+                                               success++;
+
+                                               if (know_issues.Contains (s)) {
+                                                       Console.WriteLine 
("FIXED ISSUE");
+                                                       continue;
+                                               }
+                                               Console.WriteLine ("OK");
+                                               continue;
+                                       }
+                                       PrintFailed (filename);
+                                       Console.WriteLine (tester.Output);
+                               }
+                               catch (Exception e) {
+                                       PrintFailed (filename);
+                                       Console.WriteLine (e.ToString ());
+                               }
+                       }
+
+                       Console.WriteLine ("Done" + Environment.NewLine);
+                       Console.WriteLine ("{0} correctly detected error cases 
({1:.##%})", success, (float) (success) / (float)total);
+                       if (know_issues.Count > 0) {
+                               Console.WriteLine ();
+                               Console.WriteLine (issue_file + " contains 
already fixed issues. Please remove");
+                               foreach (string s in know_issues)
+                                       Console.WriteLine (s);
+                       }
+                       if (regression.Count > 0) {
+                               Console.WriteLine ();
+                               Console.WriteLine ("The latest changes caused 
regression in {0} file(s)", regression.Count);
+                               foreach (string s in regression)
+                                       Console.WriteLine (s);
+                       }
+
+                       return 0;
+               }
+
+               static void ReadWrongErrors (string file) {
+                       using (StreamReader sr = new StreamReader (file)) {
+                               String line;
+                               while ((line = sr.ReadLine()) != null) {
+                                       if (line.StartsWith ("#"))
+                                               continue;
+
+                                       string file_name = line.Split (' ')[0];
+                                       if (file_name.Length == 0)
+                                               continue;
+                                       know_issues.Add (file_name);
+                               }
+                       }
+               }
+
+               static void PrintFailed (string file) {
+                       if (know_issues.Contains (file)) {
+                               Console.WriteLine ("KNOW ISSUE");
+                               know_issues.Remove (file);
+                               return;
+                       }
+                       Console.WriteLine ("REGRESSION");
+                       regression.Add (file);
+               }
+
+               static bool CheckCompilerError (string expected, string buffer) 
{
+                       string tested_text = "error CS" + expected;
+                       StringReader sr = new StringReader (buffer);
+                       string line = sr.ReadLine ();
+                       int row = 0;
+                       while (line != null) {
+                               row++;
+                               if (line.IndexOf (tested_text) != -1) {
+                                       //if (row > 1)
+                                       //      Console.WriteLine ("WARNING: 
Not reported as primary error");
+                                       return true;
+                               }
+                               line = sr.ReadLine ();
+                       }
+                       
+                       return false;
+               }
+
+               static string[] GetExtraOptions (string file) {
+                       const string options = "// Compiler options:";
+
+                       int row = 0;
+                       using (StreamReader sr = new StreamReader (file)) {
+                               String line;
+                               while (row++ < 3 && (line = sr.ReadLine()) != 
null) {
+                                       int index = line.IndexOf (options);
+                                       if (index != -1) {
+                                               string[] o = line.Substring 
(index + options.Length).Split (' ');
+                                               for (int i = 0; i < o.Length; 
i++)
+                                                       o [i] = o[i].TrimStart 
();
+                                               return o;
+                                       }                               
+                               }
+                       }
+                       return null;
+               }                       
+       }
+}

Added: trunk/mcs/errors/know-issues-mcs
===================================================================
--- trunk/mcs/errors/know-issues-mcs    2005-03-10 08:52:34 UTC (rev 41638)
+++ trunk/mcs/errors/know-issues-mcs    2005-03-10 08:59:37 UTC (rev 41639)
@@ -0,0 +1,66 @@
+#
+# These files are give the wrong warning when compiled.
+# If you add a new test that should generate an error but generates the
+# wrong one, it should be added here.
+#
+# If you fix the compiler so that it emits the correct error,
+# the file should be removed.
+#
+
+cs0118.cs
+cs0119.cs
+cs0122-12.cs
+cs0128.cs
+cs0156-2.cs
+cs0192-2.cs
+cs0201.cs
+cs0208-3.cs
+cs0229-2.cs
+cs0266.cs
+cs0407.cs
+cs0428.cs
+cs0525.cs
+cs0526.cs
+cs0529.cs
+cs0547.cs
+cs0548-4.cs
+cs0548.cs
+cs0560.cs
+cs0567.cs
+cs0610-4.cs
+cs0642-3.cs
+cs0642-4.cs
+cs0642-5.cs
+cs0642-6.cs
+cs0647-15.cs # corlib bug 73143
+cs0657-17.cs
+cs0720.cs
+cs1501-5.cs
+cs1513.cs
+cs1518.cs
+cs1525.cs
+cs1527-2.cs
+cs1528.cs
+cs1535.cs
+cs1552.cs
+cs1586.cs
+cs1615.cs
+cs1620.cs
+cs1622.cs
+cs1626.cs
+cs1638.cs
+cs1641.cs
+cs1656.cs
+cs1657.cs
+cs1666.cs
+cs1715.cs
+cs2007.cs
+
+cs0121-3.cs
+cs0229.cs
+cs0266-2.cs
+cs0642-2.cs
+cs0642.cs
+cs0647.cs # corlib bug #73142
+cs0652.cs
+cs2023.cs

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to