2008-09-24 Miguel de Icaza <miguel@novell.com>
authorMiguel de Icaza <miguel@gnome.org>
Wed, 24 Sep 2008 23:11:15 +0000 (23:11 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Wed, 24 Sep 2008 23:11:15 +0000 (23:11 -0000)
* eval-test.cs: Add an evaluation test, to test the basic
primitives of the expression evaluator.

svn path=/trunk/mcs/; revision=114034

mcs/tests/ChangeLog
mcs/tests/Makefile
mcs/tests/eval-test.cs [new file with mode: 0644]

index 9a0422ccc69bea5080ac3179a39c5405e12bc1b8..cff24bdc62a2a6b86abef12c32033dbc21b069d9 100644 (file)
@@ -1,3 +1,8 @@
+2008-09-24  Miguel de Icaza  <miguel@novell.com>
+
+       * eval-test.cs: Add an evaluation test, to test the basic
+       primitives of the expression evaluator.
+
 2008-09-16  Jb Evain  <jbevain@novell.com>
 
        * gtest-278.cs, gtest-278-3-lib.cs, gtest-278-2-lib.cs: complete
index 5aace793a56c96331e3847860109083fccdcc26c..72451973ff0956da066e3a322b31063e84aee37a 100644 (file)
@@ -54,6 +54,8 @@ test-casts: boot-casts.out mcs-casts.out
 
 test-local: casts-boot.exe
 
+eval.exe: eval-tests.cs
+       
 ifeq (net_2_1, $(PROFILE))
 COMPILER_NAME = smcs
 TEST_PATTERN = '*test-*.cs'
@@ -76,9 +78,17 @@ TESTER = MONO_RUNTIME='$(RUNTIME)' $(TEST_RUNTIME) $(RUNTIME_FLAGS) $(LOCAL_RUNT
 
 TEST_ILS := $(wildcard *-lib.il)
 
+ifeq (net_2_0, $(PROFILE))
+eval-test: 
+       $(RUNTIME) $(RUNTIME_FLAGS) $(COMPILER) eval-test.cs -r:$(COMPILER)
+       MONO_PATH=$(topdir)/class/lib/$(PROFILE):. $(RUNTIME) eval-test.exe
+else
+eval-test:
+endif
+
 check: run-test
 
-run-test-local: $(TEST_ILS:.il=.dll)
+run-test-local: $(TEST_ILS:.il=.dll) eval-test
        $(TESTER) -mode:pos -files:$(TEST_PATTERN) -compiler:$(COMPILER) -issues:known-issues-$(COMPILER_NAME) -log:$(COMPILER_NAME).log $(TOPTIONS)
 
 test-everything:
@@ -108,7 +118,7 @@ ilasm:
        $(ILASM) /dll property-il.il
        $(CSCOMPILE) /r:property-il.dll property-main.cs /out:property-main.exe
        $(TEST_RUNTIME) property-main.exe
-       
+
        $(CSCOMPILE) -t:library dlls/test-679-2/test-679-lib-2.cs
        $(CSCOMPILE) -t:library dlls/test-679-1/test-679-lib.cs -r:dlls/test-679-2/test-679-lib-2.dll
 endif
diff --git a/mcs/tests/eval-test.cs b/mcs/tests/eval-test.cs
new file mode 100644 (file)
index 0000000..6cbe397
--- /dev/null
@@ -0,0 +1,45 @@
+using System;
+using Mono.CSharp;
+
+class X {
+       static void Run (string id, string stmt)
+       {
+               try {
+                       Evaluator.Run (stmt);
+               } catch {
+                       Console.WriteLine ("Failed on test {0}", id);
+                       throw;
+               }
+       }
+
+       static void Evaluate (string id, string expr, object expected)
+       {
+               try {
+                       object res = Evaluator.Evaluate (expr);
+                       if (res == null && expected == null)
+                               return;
+
+                       if (!expected.Equals (res)){
+                               Console.WriteLine ("Failed on test {2} Expecting {0}, got {1}", expected, res, id);
+                               throw new Exception ();
+                       }
+               } catch {
+                       Console.WriteLine ("Failed on test {0}", id);
+                       throw;
+               }
+       }
+       
+       static void Main ()
+       {
+               Run ("1",      "System.Console.WriteLine (100);");
+               Run ("Length", "var a = new int [] {1,2,3}; var b = a.Length");
+               
+               Evaluate ("CompareString", "\"foo\" == \"bar\";", false);
+               Evaluate ("CompareInt", "var a = 1; a+2;", 3);
+
+               Evaluator.Run ("using System; using System.Linq;");
+               Run ("LINQ-1", "var a = new int[]{1,2,3};\nfrom x in a select x;");
+               Run ("LINQ-2", "var a = from f in System.IO.Directory.GetFiles (\"/tmp\") where f == \"passwd\" select f;");
+       }
+       
+}
\ No newline at end of file