Browse Source

2002-07-31 Martin Baulig <[email protected]>

	* test-154.cs: New test for the flow analysis code.

	* error-1.cs: Each method in this test must produce a compiler
	error message.

	* makefile (test-unsafe-mono): New target to compile and run all
	the --unsafe tests wich MCS and the Mono runtime.

svn path=/trunk/mcs/; revision=6292
Martin Baulig 23 năm trước cách đây
mục cha
commit
c8f29d7894
5 tập tin đã thay đổi với 353 bổ sung1 xóa
  1. 10 0
      mcs/tests/ChangeLog
  2. 12 0
      mcs/tests/README.tests
  3. 85 0
      mcs/tests/error-1.cs
  4. 17 1
      mcs/tests/makefile
  5. 229 0
      mcs/tests/test-154.cs

+ 10 - 0
mcs/tests/ChangeLog

@@ -1,3 +1,13 @@
+2002-07-31  Martin Baulig  <[email protected]>
+
+	* test-154.cs: New test for the flow analysis code.
+
+	* error-1.cs: Each method in this test must produce a compiler
+	error message.
+
+	* makefile (test-unsafe-mono): New target to compile and run all
+	the --unsafe tests wich MCS and the Mono runtime.
+
 2002-07-29  Martin Baulig  <[email protected]>
 
 	* makefile: Put back test-152.cs.

+ 12 - 0
mcs/tests/README.tests

@@ -37,6 +37,10 @@ Test cases listed by Category:
 
   test-153.cs
 
+* Flow Analysis
+
+  test-154.cs error-1.cs
+
 Test cases listed by Number:
 ============================
 
@@ -78,6 +82,14 @@ test-153.cs
 -----------
 Testing invocation of varargs function.
 
+test-154.cs
+-----------
+Flow analysis: This test contains all situations which are "allowed".
+
+error-1.cs
+----------
+Flow analysis: Check whether mcs correctly reports all errors.
+
 verify-1.cs
 -----------
 Test whether we do not jump out of the method in a Try/Finally block.

+ 85 - 0
mcs/tests/error-1.cs

@@ -0,0 +1,85 @@
+// This test must produce a compilation error in each method.
+using System;
+
+public class X
+{
+	public static int Main ()
+	{
+		// This is a compilation-only test.
+		return 0;
+	}
+
+	// Must assign out parameter.
+	public static void test1 (out float f)
+	{
+	}
+
+	// Must assign it before returning.
+	public static void test2 (int a, out float f)
+	{
+		if (a == 5)
+			return;
+
+		f = 8.53F;
+	}
+
+	public static void test3 (out float f)
+	{
+		try {
+			f = 8.53F;
+		} catch {
+			return;
+		}
+	}
+
+	public static int test4 ()
+	{
+		int a;
+
+		try {
+			a = 3;
+		} catch {
+			Console.WriteLine ("EXCEPTION");
+		}
+
+		return a;
+	}
+
+	public static int test5 ()
+	{
+		int a;
+
+		try {
+			Console.WriteLine ("TRY");
+			a = 8;
+		} catch {
+			a = 9;
+		} finally {
+			Console.WriteLine (a);
+		}
+
+		return a;
+	}
+
+	public static void test6 (int a, out float f)
+	{
+		do {
+			if (a == 8) {
+				Console.WriteLine ("Hello");
+				return;
+			}
+		} while (false);
+
+		f = 1.3F;
+		return;
+	}
+
+	public static void test7 (out float f)
+	{
+		goto World;
+		f = 8.0F;
+
+	World:
+		;
+	}
+}

+ 17 - 1
mcs/tests/makefile

@@ -24,7 +24,7 @@ TEST_SOURCES = \
 	test-121          test-123          test-125 test-126 test-127 test-128 test-129 test-130 \
 	test-131                   test-134 test-135 test-136 test-137 test-138 test-139 test-140 \
 	test-141 test-142 test-143 test-144 test-145 test-146 test-147 test-148 test-149 test-150 \
-	                  test-153
+	                  test-153 test-154
 
 UNSAFE_SOURCES = \
 	unsafe-1 unsafe-2 unsafe-3 test-58.cs
@@ -123,6 +123,22 @@ test-compiler-mono:
 		fi \
 	done
 
+# Compile with mono, run with mono jit
+test-unsafe-mono:
+	@rm -f *.exe; \
+	for i in $(UNSAFE_SOURCES); do \
+		echo -n "Running $$i ... "; \
+		if $(MCS2) --unsafe $$i.cs > /dev/null; then \
+			if mono ./$$i.exe > /dev/null; then \
+				echo OK; \
+			else \
+				echo FAILED; exit 1; \
+			fi; \
+		else \
+			echo FAILED TO COMPILE; exit 1; \
+		fi \
+	done
+
 verify:
 	@for i in $(TEST_SOURCES); do \
 		if $(MCS) -o mcs-gen-code.exe $$i.cs > /dev/null; then \

+ 229 - 0
mcs/tests/test-154.cs

@@ -0,0 +1,229 @@
+using System;
+using System.Collections;
+
+public class X
+{
+	public static int Main ()
+	{
+		// This is a compilation-only test.
+		return 0;
+	}
+
+	// All code paths throw an exception, no need to set out parameters.
+	public static void test1 (out float f)
+	{
+		throw new NotSupportedException ();
+	}
+
+	// The while loop breaks but does not return, so this is ok.
+	public static void test2 (int a, out float f)
+	{
+		while (a > 0) {
+			if (a == 5)
+				continue;
+
+			Console.WriteLine (a);
+		}
+
+		f = 8.53F;
+	}
+
+	// a has been assigned in all code paths which do not return.
+	public static void test3 (long[] b, int c)
+	{
+		ICollection a;
+		if (b == null)
+			throw new ArgumentException ();
+		else
+			a = (ICollection) b;
+
+		Console.WriteLine (a);
+	}
+
+	// Forward goto, it's ok to set f after the target label.
+	public static int test4 (int b, out float f)
+	{
+		long a;
+
+		Console.WriteLine ("Hello World");
+
+		a = 5;
+
+		goto World;
+
+	World:
+		Console.WriteLine (a);
+
+		f = 8.53F;
+
+		return 0;
+	}
+
+	// try { ... } catch { ... } finally { ... } block
+	static public int test4 (out float f, long d)
+	{
+                int a;
+		long b = 8;
+
+		try {
+			f = 8.53F;
+
+			if (d == 500)
+				return 9;
+
+			a = 5;
+		} catch (NotSupportedException e) {
+			a = 9;
+		} catch (Exception e) {
+			return 9;
+		} finally {
+			f = 9.234F;
+		}
+
+		return a;
+        }
+
+	// Passing out parameter to method invocation
+	static public int test5 (out float f)
+	{
+		return test4 (out f, 50);
+	}
+
+	// Loop-variable of foreach() and for() loop.
+	static public long test6 (int[] a, int stop)
+	{
+		long b = 0;
+		foreach (int i in a)
+			b += i;
+
+		for (int i = 1; i < stop; i++)
+			b *= i;
+
+		return b;
+	}
+
+	// Initializing locals in initialize or test of for block
+	static public long test7 (int stop)
+	{
+		int i;
+		long b;
+		for (i = 1; (b = stop) > 3; i++) {
+			stop--;
+			b += i;
+		}
+		return b;
+	}
+
+	// Initializing locals in test of while block
+	static public long test8 (int stop)
+	{
+		long b;
+		while ((b = stop) > 3) {
+			stop--;
+			b += stop;
+		}
+		return b;
+	}
+
+	// Return in subblock
+	public static void test9 (int a, out float f)
+	{
+		if (a == 5) {
+			f = 8.53F;
+			return;
+		}
+
+		f = 9.0F;
+	}
+
+	// Switch block
+	public static long test10 (int a)
+	{
+		long b;
+
+		switch (a) {
+		case 5:
+			b = 1;
+			break;
+
+		case 9:
+			b = 3;
+			break;
+
+		default:
+			return 9;
+		}
+
+		return b;
+	}
+
+	// Try block which rethrows exception.
+	public static void test11 (out float f)
+	{
+		try {
+			f = 9.0F;
+		} catch {
+			throw new NotSupportedException ();
+		}
+	}
+
+	// Return in subblock.
+	public static void test12 (int a, out float f)
+	{
+		do {
+			if (a == 8) {
+				f = 8.5F;
+				return;
+			}
+		} while (false);
+
+		f = 1.3F;
+		return;
+	}
+
+	// Switch block with goto case / goto default.
+	public static long test13 (int a, out float f)
+	{
+		long b;
+
+		switch (a) {
+		case 1:
+			goto case 2;
+
+		case 2:
+			f = 9.53F;
+			return 9;
+
+		case 3:
+			goto default;
+
+		default:
+			b = 10;
+			break;
+		}
+
+		f = 10.0F;
+
+		return b;
+	}
+
+	// Forward goto, it's ok to set f before the jump.
+	public static int test4 (int b, out float f)
+	{
+		long a;
+
+		Console.WriteLine ("Hello World");
+
+		a = 5;
+		f = 8.53F;
+
+		goto World;
+
+	World:
+		Console.WriteLine (a);
+
+		return 0;
+	}
+
+
+}