Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: tools/testing/dart/test_suite.dart

Issue 12475004: Add dart analyzer test suite 'analyze_library' that fails if we (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/testing/dart/test_options.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Classes and methods for enumerating and preparing tests. 6 * Classes and methods for enumerating and preparing tests.
7 * 7 *
8 * This library includes: 8 * This library includes:
9 * 9 *
10 * - Creating tests by listing all the Dart files in certain directories, 10 * - Creating tests by listing all the Dart files in certain directories,
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 /** 808 /**
809 * _createUrlPathFromFile takes a [file], which is either located in the dart 809 * _createUrlPathFromFile takes a [file], which is either located in the dart
810 * or in the build directory, and will return a String representing 810 * or in the build directory, and will return a String representing
811 * the relative path to either the dart or the build directory. 811 * the relative path to either the dart or the build directory.
812 * Thus, the returned [String] will be the path component of the URL 812 * Thus, the returned [String] will be the path component of the URL
813 * corresponding to [file] (the http server serves files relative to the 813 * corresponding to [file] (the http server serves files relative to the
814 * dart/build directories). 814 * dart/build directories).
815 */ 815 */
816 String _createUrlPathFromFile(Path file) { 816 String _createUrlPathFromFile(Path file) {
817 file = TestUtils.absolutePath(file); 817 file = TestUtils.absolutePath(file);
818 818
819 var relativeBuildDir = new Path(TestUtils.buildDir(configuration)); 819 var relativeBuildDir = new Path(TestUtils.buildDir(configuration));
820 var buildDir = TestUtils.absolutePath(relativeBuildDir); 820 var buildDir = TestUtils.absolutePath(relativeBuildDir);
821 var dartDir = TestUtils.absolutePath(TestUtils.dartDir()); 821 var dartDir = TestUtils.absolutePath(TestUtils.dartDir());
822 822
823 var fileString = file.toString(); 823 var fileString = file.toString();
824 if (fileString.startsWith(buildDir.toString())) { 824 if (fileString.startsWith(buildDir.toString())) {
825 var fileRelativeToBuildDir = file.relativeTo(buildDir); 825 var fileRelativeToBuildDir = file.relativeTo(buildDir);
826 return "/$PREFIX_BUILDDIR/$fileRelativeToBuildDir"; 826 return "/$PREFIX_BUILDDIR/$fileRelativeToBuildDir";
827 } else if (fileString.startsWith(dartDir.toString())) { 827 } else if (fileString.startsWith(dartDir.toString())) {
828 var fileRelativeToDartDir = file.relativeTo(dartDir); 828 var fileRelativeToDartDir = file.relativeTo(dartDir);
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 * an image, if the expectation ends in .png. 'test.dart' will compare the 1317 * an image, if the expectation ends in .png. 'test.dart' will compare the
1318 * snapshot to the expectation file. When tests fail, 'test.dart' saves the 1318 * snapshot to the expectation file. When tests fail, 'test.dart' saves the
1319 * new snapshot into a file so it can be visualized or copied over. 1319 * new snapshot into a file so it can be visualized or copied over.
1320 * Expectations can be recorded for the first time by creating an empty file 1320 * Expectations can be recorded for the first time by creating an empty file
1321 * with the right name (touch test_name_test.png), running the test, and 1321 * with the right name (touch test_name_test.png), running the test, and
1322 * executing the copy command printed by the test script. 1322 * executing the copy command printed by the test script.
1323 * 1323 *
1324 * This method is static as the map is cached and shared amongst 1324 * This method is static as the map is cached and shared amongst
1325 * configurations, so it may not use [configuration]. 1325 * configurations, so it may not use [configuration].
1326 */ 1326 */
1327 static Map readOptionsFromFile(Path filePath) { 1327 Map readOptionsFromFile(Path filePath) {
1328 if (filePath.segments().contains('co19')) { 1328 if (filePath.segments().contains('co19')) {
1329 return readOptionsFromCo19File(filePath); 1329 return readOptionsFromCo19File(filePath);
1330 } 1330 }
1331 RegExp testOptionsRegExp = new RegExp(r"// VMOptions=(.*)"); 1331 RegExp testOptionsRegExp = new RegExp(r"// VMOptions=(.*)");
1332 RegExp dartOptionsRegExp = new RegExp(r"// DartOptions=(.*)"); 1332 RegExp dartOptionsRegExp = new RegExp(r"// DartOptions=(.*)");
1333 RegExp otherScriptsRegExp = new RegExp(r"// OtherScripts=(.*)"); 1333 RegExp otherScriptsRegExp = new RegExp(r"// OtherScripts=(.*)");
1334 RegExp packageRootRegExp = new RegExp(r"// PackageRoot=(.*)"); 1334 RegExp packageRootRegExp = new RegExp(r"// PackageRoot=(.*)");
1335 RegExp multiHtmlTestRegExp = 1335 RegExp multiHtmlTestRegExp =
1336 new RegExp(r"useHtmlIndividualConfiguration()"); 1336 new RegExp(r"useHtmlIndividualConfiguration()");
1337 RegExp staticTypeRegExp = 1337 RegExp staticTypeRegExp =
1338 new RegExp(r"/// ([0-9][0-9]:){0,1}\s*static type warning"); 1338 new RegExp(r"/// ([0-9][0-9]:){0,1}\s*static type warning");
1339 RegExp compileTimeRegExp = 1339 RegExp compileTimeRegExp =
1340 new RegExp(r"/// ([0-9][0-9]:){0,1}\s*compile-time error"); 1340 new RegExp(r"/// ([0-9][0-9]:){0,1}\s*compile-time error");
1341 RegExp staticCleanRegExp = new RegExp(r"// @static-clean"); 1341 RegExp staticCleanRegExp = new RegExp(r"// @static-clean");
1342 RegExp leadingHashRegExp = new RegExp(r"^#", multiLine: true);
1343 RegExp isolateStubsRegExp = new RegExp(r"// IsolateStubs=(.*)"); 1342 RegExp isolateStubsRegExp = new RegExp(r"// IsolateStubs=(.*)");
1344 // TODO(gram) Clean these up once the old directives are not supported. 1343 // TODO(gram) Clean these up once the old directives are not supported.
1345 RegExp domImportRegExp = 1344 RegExp domImportRegExp =
1346 new RegExp(r"^[#]?import.*dart:html", multiLine: true); 1345 new RegExp(r"^[#]?import.*dart:html", multiLine: true);
1347 RegExp libraryDefinitionRegExp = 1346 RegExp libraryDefinitionRegExp =
1348 new RegExp(r"^[#]?library[\( ]", multiLine: true); 1347 new RegExp(r"^[#]?library[\( ]", multiLine: true);
1349 RegExp sourceOrImportRegExp = 1348 RegExp sourceOrImportRegExp =
1350 new RegExp("^(#source|#import|part)[ \t]+[\('\"]", multiLine: true); 1349 new RegExp("^(#source|#import|part)[ \t]+[\('\"]", multiLine: true);
1351 1350
1352 var bytes = new File.fromPath(filePath).readAsBytesSync(); 1351 var bytes = new File.fromPath(filePath).readAsBytesSync();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 } 1396 }
1398 1397
1399 List<String> otherScripts = new List<String>(); 1398 List<String> otherScripts = new List<String>();
1400 matches = otherScriptsRegExp.allMatches(contents); 1399 matches = otherScriptsRegExp.allMatches(contents);
1401 for (var match in matches) { 1400 for (var match in matches) {
1402 otherScripts.addAll(match[1].split(' ').where((e) => e != '').toList()); 1401 otherScripts.addAll(match[1].split(' ').where((e) => e != '').toList());
1403 } 1402 }
1404 1403
1405 bool isMultitest = multiTestRegExp.hasMatch(contents); 1404 bool isMultitest = multiTestRegExp.hasMatch(contents);
1406 bool isMultiHtmlTest = multiHtmlTestRegExp.hasMatch(contents); 1405 bool isMultiHtmlTest = multiHtmlTestRegExp.hasMatch(contents);
1407 bool containsLeadingHash = leadingHashRegExp.hasMatch(contents);
1408 Match isolateMatch = isolateStubsRegExp.firstMatch(contents); 1406 Match isolateMatch = isolateStubsRegExp.firstMatch(contents);
1409 String isolateStubs = isolateMatch != null ? isolateMatch[1] : ''; 1407 String isolateStubs = isolateMatch != null ? isolateMatch[1] : '';
1410 bool containsDomImport = domImportRegExp.hasMatch(contents); 1408 bool containsDomImport = domImportRegExp.hasMatch(contents);
1411 bool isLibraryDefinition = libraryDefinitionRegExp.hasMatch(contents); 1409 bool isLibraryDefinition = libraryDefinitionRegExp.hasMatch(contents);
1412 bool containsSourceOrImport = sourceOrImportRegExp.hasMatch(contents); 1410 bool containsSourceOrImport = sourceOrImportRegExp.hasMatch(contents);
1413 int numStaticTypeAnnotations = 0; 1411 int numStaticTypeAnnotations = 0;
1414 for (var i in staticTypeRegExp.allMatches(contents)) { 1412 for (var i in staticTypeRegExp.allMatches(contents)) {
1415 numStaticTypeAnnotations++; 1413 numStaticTypeAnnotations++;
1416 } 1414 }
1417 int numCompileTimeAnnotations = 0; 1415 int numCompileTimeAnnotations = 0;
(...skipping 18 matching lines...) Expand all
1436 return { "vmOptions": result, 1434 return { "vmOptions": result,
1437 "dartOptions": dartOptions, 1435 "dartOptions": dartOptions,
1438 "packageRoot": packageRoot, 1436 "packageRoot": packageRoot,
1439 "hasCompileError": false, 1437 "hasCompileError": false,
1440 "hasRuntimeError": false, 1438 "hasRuntimeError": false,
1441 "isStaticClean" : isStaticClean, 1439 "isStaticClean" : isStaticClean,
1442 "otherScripts": otherScripts, 1440 "otherScripts": otherScripts,
1443 "isMultitest": isMultitest, 1441 "isMultitest": isMultitest,
1444 "isMultiHtmlTest": isMultiHtmlTest, 1442 "isMultiHtmlTest": isMultiHtmlTest,
1445 "subtestNames": subtestNames, 1443 "subtestNames": subtestNames,
1446 "containsLeadingHash": containsLeadingHash,
1447 "isolateStubs": isolateStubs, 1444 "isolateStubs": isolateStubs,
1448 "containsDomImport": containsDomImport, 1445 "containsDomImport": containsDomImport,
1449 "isLibraryDefinition": isLibraryDefinition, 1446 "isLibraryDefinition": isLibraryDefinition,
1450 "containsSourceOrImport": containsSourceOrImport, 1447 "containsSourceOrImport": containsSourceOrImport,
1451 "numStaticTypeAnnotations": numStaticTypeAnnotations, 1448 "numStaticTypeAnnotations": numStaticTypeAnnotations,
1452 "numCompileTimeAnnotations": numCompileTimeAnnotations }; 1449 "numCompileTimeAnnotations": numCompileTimeAnnotations };
1453 } 1450 }
1454 1451
1455 List<List<String>> getVmOptions(Map optionsFromFile) { 1452 List<List<String>> getVmOptions(Map optionsFromFile) {
1456 var COMPILERS = const ['none', 'dart2dart']; 1453 var COMPILERS = const ['none', 'dart2dart'];
(...skipping 16 matching lines...) Expand all
1473 * co19 is developed based on a contract which defines certain test 1470 * co19 is developed based on a contract which defines certain test
1474 * tags. These tags may appear unused, but should not be removed 1471 * tags. These tags may appear unused, but should not be removed
1475 * without consulting with the co19 team. 1472 * without consulting with the co19 team.
1476 * 1473 *
1477 * Also, [readOptionsFromFile] recognizes a number of additional 1474 * Also, [readOptionsFromFile] recognizes a number of additional
1478 * tags that are not appropriate for use in general tests of 1475 * tags that are not appropriate for use in general tests of
1479 * conformance to the Dart language. Any Dart implementation must 1476 * conformance to the Dart language. Any Dart implementation must
1480 * pass the co19 test suite as is, and not require extra flags, 1477 * pass the co19 test suite as is, and not require extra flags,
1481 * environment variables, configuration files, etc. 1478 * environment variables, configuration files, etc.
1482 */ 1479 */
1483 static Map readOptionsFromCo19File(Path filePath) { 1480 Map readOptionsFromCo19File(Path filePath) {
1484 String contents = decodeUtf8(new File.fromPath(filePath).readAsBytesSync()); 1481 String contents = decodeUtf8(new File.fromPath(filePath).readAsBytesSync());
1485 1482
1486 bool hasCompileError = contents.contains("@compile-error"); 1483 bool hasCompileError = contents.contains("@compile-error");
1487 bool hasRuntimeError = contents.contains("@runtime-error"); 1484 bool hasRuntimeError = contents.contains("@runtime-error");
1488 bool hasDynamicTypeError = contents.contains("@dynamic-type-error"); 1485 bool hasDynamicTypeError = contents.contains("@dynamic-type-error");
1489 bool hasStaticWarning = contents.contains("@static-warning"); 1486 bool hasStaticWarning = contents.contains("@static-warning");
1490 bool isMultitest = multiTestRegExp.hasMatch(contents); 1487 bool isMultitest = multiTestRegExp.hasMatch(contents);
1491 1488
1492 if (hasDynamicTypeError) { 1489 if (hasDynamicTypeError) {
1493 // TODO(ahe): Remove this warning when co19 no longer uses this tag. 1490 // TODO(ahe): Remove this warning when co19 no longer uses this tag.
(...skipping 13 matching lines...) Expand all
1507 "vmOptions": <List>[[]], 1504 "vmOptions": <List>[[]],
1508 "dartOptions": null, 1505 "dartOptions": null,
1509 "packageRoot": null, 1506 "packageRoot": null,
1510 "hasCompileError": hasCompileError, 1507 "hasCompileError": hasCompileError,
1511 "hasRuntimeError": hasRuntimeError, 1508 "hasRuntimeError": hasRuntimeError,
1512 "isStaticClean" : !hasStaticWarning, 1509 "isStaticClean" : !hasStaticWarning,
1513 "otherScripts": <String>[], 1510 "otherScripts": <String>[],
1514 "isMultitest": isMultitest, 1511 "isMultitest": isMultitest,
1515 "isMultiHtmlTest": false, 1512 "isMultiHtmlTest": false,
1516 "subtestNames": <String>[], 1513 "subtestNames": <String>[],
1517 "containsLeadingHash": false,
1518 "isolateStubs": '', 1514 "isolateStubs": '',
1519 "containsDomImport": false, 1515 "containsDomImport": false,
1520 "isLibraryDefinition": false, 1516 "isLibraryDefinition": false,
1521 "containsSourceOrImport": false, 1517 "containsSourceOrImport": false,
1522 "numStaticTypeAnnotations": 0, 1518 "numStaticTypeAnnotations": 0,
1523 "numCompileTimeAnnotations": 0, 1519 "numCompileTimeAnnotations": 0,
1524 }; 1520 };
1525 } 1521 }
1526 } 1522 }
1527 1523
1528 1524
1525 /// A DartcCompilationTestSuite will run dartc on all of the tests.
1526 ///
1527 /// Usually, the result of a dartc run is determined by the output of
1528 /// dartc in connection with annotations in the test file.
1529 ///
1530 /// If you want each file that you are running as a test to have no
1531 /// static warnings or errors you can create a DartcCompilationTestSuite
1532 /// with the optional allStaticClean constructor parameter set to true.
1529 class DartcCompilationTestSuite extends StandardTestSuite { 1533 class DartcCompilationTestSuite extends StandardTestSuite {
1530 List<String> _testDirs; 1534 List<String> _testDirs;
1535 bool allStaticClean;
1531 1536
1532 DartcCompilationTestSuite(Map configuration, 1537 DartcCompilationTestSuite(Map configuration,
1533 String suiteName, 1538 String suiteName,
1534 String directoryPath, 1539 String directoryPath,
1535 List<String> this._testDirs, 1540 List<String> this._testDirs,
1536 List<String> expectations) 1541 List<String> expectations,
1542 {bool this.allStaticClean: false})
ricow1 2013/03/06 14:23:25 we don't have to have this as a constructor parame
Mads Ager (google) 2013/03/06 14:26:42 That is true. I like having it as a constructor pa
1537 : super(configuration, 1543 : super(configuration,
1538 suiteName, 1544 suiteName,
1539 new Path(directoryPath), 1545 new Path(directoryPath),
1540 expectations); 1546 expectations);
1541 1547
1542 List<String> additionalOptions(Path filePath) { 1548 List<String> additionalOptions(Path filePath) {
1543 return ['--fatal-warnings', '--fatal-type-errors']; 1549 return ['--fatal-warnings', '--fatal-type-errors'];
1544 } 1550 }
1545 1551
1546 Future enqueueTests() { 1552 Future enqueueTests() {
1547 var group = new FutureGroup(); 1553 var group = new FutureGroup();
1548 1554
1549 for (String testDir in _testDirs) { 1555 for (String testDir in _testDirs) {
1550 Directory dir = new Directory.fromPath(suiteDir.append(testDir)); 1556 Directory dir = new Directory.fromPath(suiteDir.append(testDir));
1551 if (dir.existsSync()) { 1557 if (dir.existsSync()) {
1552 enqueueDirectory(dir, group); 1558 enqueueDirectory(dir, group);
1553 } 1559 }
1554 } 1560 }
1555 1561
1556 return group.future; 1562 return group.future;
1557 } 1563 }
1564
1565 Map readOptionsFromFile(Path p) {
1566 Map options = super.readOptionsFromFile(p);
1567 if (allStaticClean) {
1568 options['isStaticClean'] = true;
1569 }
1570 return options;
1571 }
1558 } 1572 }
1559 1573
1560 1574
1561 class JUnitTestSuite extends TestSuite { 1575 class JUnitTestSuite extends TestSuite {
1562 String directoryPath; 1576 String directoryPath;
1563 String statusFilePath; 1577 String statusFilePath;
1564 final String dartDir; 1578 final String dartDir;
1565 String classPath; 1579 String classPath;
1566 List<String> testClasses; 1580 List<String> testClasses;
1567 TestCaseEvent doTest; 1581 TestCaseEvent doTest;
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 * $pass tests are expected to pass 1952 * $pass tests are expected to pass
1939 * $failOk tests are expected to fail that we won't fix 1953 * $failOk tests are expected to fail that we won't fix
1940 * $fail tests are expected to fail that we should fix 1954 * $fail tests are expected to fail that we should fix
1941 * $crash tests are expected to crash that we should fix 1955 * $crash tests are expected to crash that we should fix
1942 * $timeout tests are allowed to timeout 1956 * $timeout tests are allowed to timeout
1943 * $compileErrorSkip tests are skipped on browsers due to compile-time error 1957 * $compileErrorSkip tests are skipped on browsers due to compile-time error
1944 """; 1958 """;
1945 print(report); 1959 print(report);
1946 } 1960 }
1947 } 1961 }
OLDNEW
« no previous file with comments | « tools/testing/dart/test_options.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698