| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 # Usage: call directly in the commandline as test/run.sh ensuring that you have | 6 # Usage: call directly in the commandline as test/run.sh ensuring that you have |
| 7 # both 'dart' and 'content_shell' in your path. Filter tests by passing a | 7 # both 'dart' and 'content_shell' in your path. Filter tests by passing a |
| 8 # pattern as an argument to this script. | 8 # pattern as an argument to this script. |
| 9 | 9 |
| 10 # TODO(sigmund): replace with a real test runner | 10 # TODO(sigmund): replace with a real test runner |
| 11 | 11 |
| 12 # bail on error | 12 # bail on error |
| 13 set -e | 13 set -e |
| 14 | 14 |
| 15 # print commands executed by this script | 15 # print commands executed by this script |
| 16 # set -x | 16 # set -x |
| 17 | 17 |
| 18 DIR=$( cd $( dirname "${BASH_SOURCE[0]}" ) && pwd ) | |
| 19 # Note: dartanalyzer and some tests needs to be run from the root directory | |
| 20 pushd $DIR/.. > /dev/null | |
| 21 | |
| 22 export DART_FLAGS="--checked" | |
| 23 | |
| 24 # Search for the first argument that doesn't look like an option ('--foo') | |
| 25 function first_non_option { | |
| 26 while [[ $# -gt 0 ]]; do | |
| 27 if [[ $1 != --* ]]; then # Note: --* is a regex | |
| 28 echo $1 | |
| 29 return | |
| 30 fi | |
| 31 shift | |
| 32 done | |
| 33 } | |
| 34 | |
| 35 TEST_PATTERN=$(first_non_option $@) | |
| 36 | |
| 37 SDK_DIR=$(cd ../../out/ReleaseIA32/dart-sdk/; pwd) | 18 SDK_DIR=$(cd ../../out/ReleaseIA32/dart-sdk/; pwd) |
| 38 package_root=$SDK_DIR/../packages | 19 package_root=$SDK_DIR/../packages |
| 39 dart="$SDK_DIR/bin/dart --package-root=$package_root" | 20 dart="$SDK_DIR/bin/dart --package-root=$package_root" |
| 40 dartanalyzer="$SDK_DIR/bin/dartanalyzer --package-root=$package_root" | 21 dartanalyzer="$SDK_DIR/bin/dartanalyzer --package-root=$package_root --hints --f
atal-warnings --fatal-type-errors" |
| 41 | 22 |
| 42 function fail { | 23 if [[ $# -eq 0 ]]; then |
| 43 return 1 | 24 # Note: dartanalyzer needs to be run from the root directory |
| 44 } | 25 root_dir=$( cd $( dirname "${BASH_SOURCE[0]}" ) && cd .. && pwd ) |
| 26 pushd $root_dir > /dev/null |
| 45 | 27 |
| 46 function show_diff { | 28 echo Analyzing linter and deploy compiler for warnings or type errors |
| 47 diff -u -N $1 $2 | \ | 29 $dartanalyzer lib/build_helper.dart |
| 48 sed -e "s/^\(+.*\)/[32m\1[0m/" |\ | |
| 49 sed -e "s/^\(-.*\)/[31m\1[0m/" | |
| 50 return 1 | |
| 51 } | |
| 52 | |
| 53 function update { | |
| 54 read -p "Would you like to update the expectations? [y/N]: " answer | |
| 55 if [[ $answer == 'y' || $answer == 'Y' ]]; then | |
| 56 cp $2 $1 | |
| 57 return 0 | |
| 58 fi | |
| 59 return 1 | |
| 60 } | |
| 61 | |
| 62 function pass { | |
| 63 echo -e "[32mOK[0m" | |
| 64 } | |
| 65 | |
| 66 function compare { | |
| 67 # use a standard diff, if they are not identical, format the diff nicely to | |
| 68 # see what's the error and prompt to see if they wish to update it. If they | |
| 69 # do, continue running more tests. | |
| 70 diff -q $1 $2 && pass || show_diff $1 $2 || update $1 $2 | |
| 71 } | |
| 72 | |
| 73 if [[ ($TEST_PATTERN == "") ]]; then | |
| 74 echo Analyzing analyzer for warnings or type errors | |
| 75 $dartanalyzer --hints --fatal-warnings --fatal-type-errors lib/dwc.dart | |
| 76 | |
| 77 echo Analyzing deploy-compiler for warnings or type errors | |
| 78 $dartanalyzer --hints --fatal-warnings --fatal-type-errors lib/deploy.dart | |
| 79 | 30 |
| 80 echo -e "\nAnalyzing runtime for warnings or type errors" | 31 echo -e "\nAnalyzing runtime for warnings or type errors" |
| 81 $dartanalyzer --hints --fatal-warnings --fatal-type-errors lib/polymer.dart | 32 $dartanalyzer lib/polymer.dart |
| 82 | 33 |
| 83 popd > /dev/null | 34 popd > /dev/null |
| 84 fi | 35 fi |
| 85 | 36 |
| 86 function compare_all { | |
| 87 # TODO(jmesserly): bash and dart regexp might not be 100% the same. Ideally we | |
| 88 # could do all the heavy lifting in Dart code, and keep this script as a thin | |
| 89 # wrapper that sets `--enable-type-checks --enable-asserts` | |
| 90 for input in $DIR/../example/component/news/test/*_test.html; do | |
| 91 if [[ ($TEST_PATTERN == "") || ($input =~ $TEST_PATTERN) ]]; then | |
| 92 FILENAME=`basename $input` | |
| 93 DIRNAME=`dirname $input` | |
| 94 if [[ `basename $DIRNAME` == 'input' ]]; then | |
| 95 DIRNAME=`dirname $DIRNAME` | |
| 96 fi | |
| 97 echo -e -n "Checking diff for $FILENAME " | |
| 98 DUMP="test/data/out/example/test/$FILENAME.txt" | |
| 99 EXPECTATION="$DIRNAME/expected/$FILENAME.txt" | |
| 100 | |
| 101 compare $EXPECTATION $DUMP | |
| 102 fi | |
| 103 done | |
| 104 echo -e "[31mSome tests failed[0m" | |
| 105 fail | |
| 106 } | |
| 107 | |
| 108 if [[ ($TEST_PATTERN == "") ]]; then | |
| 109 echo -e "\nTesting build.dart... " | |
| 110 $dart $DART_FLAGS build.dart | |
| 111 # Run it the way the editor does. Hide stdout because it is in noisy machine | |
| 112 # format. Show stderr in case something breaks. | |
| 113 # NOTE: not using --checked because the editor doesn't use it, and to workarou
nd | |
| 114 # http://dartbug.com/9637 | |
| 115 $dart build.dart --machine --clean > /dev/null | |
| 116 $dart build.dart --machine --full > /dev/null | |
| 117 fi | |
| 118 | |
| 119 echo -e "\nRunning unit tests... " | 37 echo -e "\nRunning unit tests... " |
| 120 $dart $DART_FLAGS test/run_all.dart $@ || compare_all | 38 $dart --checked test/run_all.dart $@ || compare_all |
| 121 | |
| 122 # Run Dart analyzer to check that we're generating warning clean code. | |
| 123 # It's a bit slow, so only do this for one test. | |
| 124 OUT_PATTERN="$DIR/../example/component/news/test/out/test/*$TEST_PATTERN*_bootst
rap.dart" | |
| 125 if [[ `ls $OUT_PATTERN 2>/dev/null` != "" ]]; then | |
| 126 echo -e "\nAnalyzing generated code for warnings or type errors." | |
| 127 ls $OUT_PATTERN 2>/dev/null | $dartanalyzer \ | |
| 128 --fatal-warnings --fatal-type-errors -batch | |
| 129 fi | |
| 130 | 39 |
| 131 echo -e "[32mAll tests pass[0m" | 40 echo -e "[32mAll tests pass[0m" |
| OLD | NEW |