root/trunk/ProjectFortress/src/com/sun/fortress/compiler/CompilerJUTest.scala @ 3292

Revision 3292, 6.4 KB (checked in by EricAllen, 11 months ago)

Added a type normalizer to improve presentation of types in error messages.
Got the type checker working over more of our first 20 compiled programs.
Added corresponding tests to CompilerJUTests.

Line 
1/*******************************************************************************
2    Copyright 2009 Sun Microsystems, Inc.,
3    4150 Network Circle, Santa Clara, California 95054, U.S.A.
4    All rights reserved.
5
6    U.S. Government Rights - Commercial software.
7    Government users are subject to the Sun Microsystems, Inc. standard
8    license agreement and applicable provisions of the FAR and its supplements.
9
10    Use is subject to license terms.
11
12    This distribution may include materials developed by third parties.
13
14    Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
15    trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
16 ******************************************************************************/
17package com.sun.fortress.compiler
18
19import _root_.java.util.Arrays
20
21import junit.framework.TestSuite
22
23import com.sun.fortress.compiler.phases.PhaseOrder
24import com.sun.fortress.exceptions.ProgramError
25import com.sun.fortress.exceptions.WrappedException
26import com.sun.fortress.Shell
27import com.sun.fortress.exceptions.StaticError
28import com.sun.fortress.repository.ProjectProperties
29import com.sun.fortress.useful.TestCaseWrapper
30import com.sun.fortress.nodes_util.NodeUtil
31import com.sun.fortress.interpreter.glue.WellKnownNames
32
33import edu.rice.cs.plt.tuple.Option
34
35
36class CompilerJUTest() extends TestCaseWrapper {
37
38  val STATIC_TESTS_DIR =
39    ProjectProperties.BASEDIR + "compiler_tests"
40
41  def compile(s:String) = {
42    val s_ = STATIC_TESTS_DIR + "/" + s
43    val name = NodeUtil.apiName(s_)
44    val path = Shell.sourcePath(s_, name)
45
46    WellKnownNames.useCompilerLibraries()
47    Shell.setTypeChecking(true)
48    Shell.setPhase(PhaseOrder.CODEGEN)
49    Shell.compile(path, name + ".fss")
50  }
51
52  def testXXXCompiled0() = {
53    val expected =
54      "\n" + STATIC_TESTS_DIR + "/XXXCompiled0.fss:17:11-15\n" +
55      "    Component/API names must match their enclosing file names.\n" +
56      "    File name: " + STATIC_TESTS_DIR + "/XXXCompiled0.fss\n" +
57      "    Component/API name: Hello"
58    try {
59      compile("XXXCompiled0.fss").iterator()
60      assert(false, "Compilation should have signaled an error")
61    }
62    catch {
63      case e:ProgramError =>
64        assert (e.getMessage().equals(expected),
65                "Bad error message: " + e.getMessage() + "\n" +
66                "Should be: " + expected)
67    }
68  }
69
70  def testXXXCompiled1() = {
71    val expected =
72      STATIC_TESTS_DIR + "/XXXCompiled1.fss:18:8-16\n" +
73      "    Could not find API Runnable in file named Runnable.fsi on path\n    " +
74      STATIC_TESTS_DIR + ":" + ProjectProperties.SOURCE_PATH
75
76    try {
77      compile("XXXCompiled1.fss").iterator()
78      assert(false, "Compilation should have signaled an error")
79    }
80    catch {
81      case e:WrappedException => {
82        assert (e.getMessage().equals(expected),
83                "Bad error message: " + e.getMessage() + "\n" +
84                "Should be: " + expected)
85      }
86    }
87  }
88
89  def testXXXCompiled2() = {
90    val expected =
91      STATIC_TESTS_DIR + "/XXXCompiled2.fss:20:28-39\n" +
92      "    Variable printlnSimple is not defined."
93    Shell.assertStaticErrors(compile("XXXCompiled2.fss"), expected)
94  }
95
96  def testXXXCompiled3() = {
97    val expected =
98      STATIC_TESTS_DIR + "/XXXCompiled3.fss:20:3-50\n" +
99      "    Unmatched delimiter \"component\"."
100    Shell.assertStaticErrors(compile("XXXCompiled3.fss"), expected)
101  }
102
103  def testXXXCompiled4() = {
104    val expected =
105      STATIC_TESTS_DIR + "/XXXCompiled4.fss:24:1-2\n" +
106      "    Unmatched delimiter \"end\"."
107    Shell.assertStaticErrors(compile("XXXCompiled4.fss"), expected)
108  }
109
110  def testXXXCompiled5() = {
111    val expected =
112      STATIC_TESTS_DIR + "/XXXCompiled5.fss:20:23\n" +
113      "    Unmatched delimiter \"(\"."
114    Shell.assertStaticErrors(compile("XXXCompiled5.fss"), expected)
115  }
116
117  def testXXXCompiled6() = {
118    val expected =
119      STATIC_TESTS_DIR + "/XXXCompiled6.fss:20:23\n" +
120      "    Unmatched delimiter \"(\".\n" +
121      STATIC_TESTS_DIR + "/XXXCompiled6.fss:24:1-2\n" +
122      "    Unmatched delimiter \"end\"."
123    Shell.assertStaticErrors(compile("XXXCompiled6.fss"), expected)
124  }
125
126  def testXXXCompiled7() = {
127    val expected =
128      STATIC_TESTS_DIR + "/XXXCompiled7.fss:20:25\n" +
129      "    Unmatched delimiter \")\"."
130    Shell.assertStaticErrors(compile("XXXCompiled7.fss"), expected)
131  }
132
133  def testXXXCompiled8() = {
134    val expected =
135      STATIC_TESTS_DIR + "/XXXCompiled8.fss:20:6\n" +
136      "    Unmatched delimiter \"[\\\"."
137    Shell.assertStaticErrors(compile("XXXCompiled8.fss"), expected)
138  }
139
140  def testXXXCompiled9() = {
141    val expected =
142      STATIC_TESTS_DIR + "/XXXCompiled9.fss:20:6-7\n" +
143      "    Unmatched delimiter \"[\" and \"\\]\"."
144    Shell.assertStaticErrors(compile("XXXCompiled9.fss"), expected)
145  }
146
147  def testXXXCompiled10() = {
148    val expected =
149      STATIC_TESTS_DIR + "/XXXCompiled10.fss:20:37-50\n" +
150      "    Unmatched delimiter \"\\\"\"."
151    Shell.assertStaticErrors(compile("XXXCompiled10.fss"), expected)
152  }
153
154  def testXXXCompiled11() = {
155    val expected =
156      STATIC_TESTS_DIR + "/XXXCompiled11.fss:20:28-21:24\n" +
157      "    Unmatched delimiter \"do\".\n" +
158      STATIC_TESTS_DIR + "/XXXCompiled11.fss:20:3-21:24\n" +
159      "    Unmatched delimiter \"component\".\n" +
160      STATIC_TESTS_DIR + "/XXXCompiled11.fss:21:25\n" +
161      "    Unmatched delimiter \"\\\"\"."
162    Shell.assertStaticErrors(compile("XXXCompiled11.fss"), expected)
163  }
164
165  def testXXXCompiled12() = {
166    val expected =
167      STATIC_TESTS_DIR + "/XXXCompiled12.fss:20:3-22:2\n" +
168      "    Unmatched delimiter \"component\".\n" +
169      STATIC_TESTS_DIR + "/XXXCompiled12.fss:21:13-25\n" +
170      "    Unmatched delimiter \"\\\"\"."
171    Shell.assertStaticErrors(compile("XXXCompiled12.fss"), expected)
172  }
173
174  def testXXXCompiled13() = {
175    val expected =
176      STATIC_TESTS_DIR + "/XXXCompiled13.fss:20:3-35\n" +
177      "    Function body has type FlatString->(), but declared return type is ()"
178    Shell.assertStaticErrors(compile("XXXCompiled13.fss"), expected)
179  }
180
181
182  def testXXXCompiled14() = {
183    val expected =
184      STATIC_TESTS_DIR + "/XXXCompiled14.fss:20:3-22:2\n" +
185      "    Missing function body."
186    Shell.assertStaticErrors(compile("XXXCompiled14.fss"), expected)
187  }
188
189  def testXXXCompiled20() = {
190    val expected =
191      STATIC_TESTS_DIR + "/XXXCompiled20.fss:21:1-2\n" +
192      "    Unmatched delimiter \"end\"."
193    Shell.assertStaticErrors(compile("XXXCompiled20.fss"), expected)
194  }
195
196}
Note: See TracBrowser for help on using the browser.