| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 package com.google.dart.compiler.end2end; | |
| 6 | |
| 7 import com.google.dart.compiler.CommandLineOptions; | |
| 8 import com.google.dart.compiler.CommandLineOptions.CompilerOptions; | |
| 9 import com.google.dart.compiler.CommandLineOptions.DartRunnerOptions; | |
| 10 import com.google.dart.compiler.DartCompilerListener; | |
| 11 import com.google.dart.compiler.DartCompilerListenerTest; | |
| 12 import com.google.dart.compiler.DartLibrarySourceTest; | |
| 13 import com.google.dart.compiler.DefaultCompilerConfiguration; | |
| 14 import com.google.dart.runner.DartRunner; | |
| 15 import com.google.dart.runner.RunnerError; | |
| 16 | |
| 17 import org.mozilla.javascript.RhinoException; | |
| 18 | |
| 19 import java.io.FileNotFoundException; | |
| 20 import java.io.OutputStream; | |
| 21 import java.io.PrintStream; | |
| 22 | |
| 23 /** | |
| 24 * Tests cover experimental flag --warn_no_such_type | |
| 25 */ | |
| 26 public class NonStrictResolutionTest extends End2EndTestCase { | |
| 27 | |
| 28 private final String[] compilerOptions = { "--warn_no_such_type" }; | |
| 29 | |
| 30 public void testNonStrictResolution() throws Exception { | |
| 31 runExpectError("NonStrictResolutionTest.dart", | |
| 32 "", | |
| 33 compilerOptions, | |
| 34 "no such type \"type1\"", 12, 10, | |
| 35 "no such type \"type2\"", 16, 3, | |
| 36 "no such type \"type4\"", 18, 18, | |
| 37 "no such type \"type3\"", 18, 3, | |
| 38 "no such type \"type5\"", 22, 3, | |
| 39 "no such type \"type7\"", 26, 13, | |
| 40 "no such type \"type6\"", 26, 3, | |
| 41 "no such type \"type8\"", 27, 5, | |
| 42 "no such type \"type9\"", 28, 5); | |
| 43 } | |
| 44 | |
| 45 public void testNoMethod() throws Exception { | |
| 46 runExpectError("NonStrictResolutionNegativeTest1.dart", | |
| 47 "TypeError//has no method 'foo$named'", | |
| 48 compilerOptions, | |
| 49 "A has no method named \"foo\"", 15, 17); | |
| 50 } | |
| 51 | |
| 52 public void testNewNonExistentType() throws Exception { | |
| 53 // cannot enable until we resolve how to prevent JsNameProvider.getName() as
sert. | |
| 54 // runExpectError("NonStrictResolutionNegativeTest2.dart", | |
| 55 // "ReferenceError//$_Dynamic_$Dart is not defined", | |
| 56 // compilerOptions); | |
| 57 } | |
| 58 | |
| 59 /** | |
| 60 * @param source - the source file name. | |
| 61 * @param expectRuntimeErrors - String with expected errors separated by '//' | |
| 62 * @param args - dart compiler arguments. | |
| 63 * @throws FileNotFoundException | |
| 64 */ | |
| 65 private void runExpectError(String source, String expectRuntimeErrors, String[
] args, | |
| 66 Object... expectedCompilerErrors) throws FileNotFo
undException { | |
| 67 DartLibrarySourceTest app = new DartLibrarySourceTest(getClass(), source); | |
| 68 DartCompilerListener listener = new DartCompilerListenerTest(source, expecte
dCompilerErrors); | |
| 69 CompilerOptions options = processCommandLineOptions(args); | |
| 70 DefaultCompilerConfiguration config = new DefaultCompilerConfiguration(optio
ns); | |
| 71 DartRunnerOptions verboseOptions = new CommandLineOptions.DartRunnerOptions(
); | |
| 72 verboseOptions.setVerbose(true); | |
| 73 StringStream outStream = new StringStream(System.out); | |
| 74 StringStream errStream = new StringStream(System.err); | |
| 75 try { | |
| 76 DartRunner.compileAndRunApp(app, verboseOptions, config, listener, args, | |
| 77 outStream, errStream); | |
| 78 } catch (RhinoException e) { | |
| 79 super.fail(e.getLocalizedMessage()); | |
| 80 } catch (RunnerError e) { | |
| 81 String outputStream = outStream.getSerializedStream(); | |
| 82 assertNotNull(outputStream); | |
| 83 for (String expectedError : expectRuntimeErrors.split("//")) { | |
| 84 assertNotNull(expectedError); | |
| 85 if (!outputStream.contains(expectedError)) { | |
| 86 System.err.println("Missing expected error: " + expectedError | |
| 87 + " in \"" + outputStream + "\""); | |
| 88 System.err.println(e); | |
| 89 } | |
| 90 assertTrue(outputStream.contains(expectedError)); | |
| 91 } | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 public class StringStream extends PrintStream { | |
| 96 StringBuffer sb = new StringBuffer(2048); | |
| 97 | |
| 98 public StringStream(OutputStream out) { | |
| 99 super(out); | |
| 100 } | |
| 101 | |
| 102 @Override | |
| 103 public void write(byte buffer[], int off, int len) { | |
| 104 sb.append(new String(buffer)); | |
| 105 } | |
| 106 | |
| 107 public String getSerializedStream() { | |
| 108 return sb.toString(); | |
| 109 } | |
| 110 } | |
| 111 } | |
| OLD | NEW |