OLD | NEW |
(Empty) | |
| 1 #!/bin/bash |
| 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 |
| 4 # BSD-style license that can be found in the LICENSE file. |
| 5 |
| 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 |
| 8 # pattern as an argument to this script. |
| 9 |
| 10 # TODO(sigmund): replace with a real test runner |
| 11 |
| 12 # bail on error |
| 13 set -e |
| 14 |
| 15 # print commands executed by this script |
| 16 # set -x |
| 17 |
| 18 DIR=$( cd $( dirname "${BASH_SOURCE[0]}" ) && pwd ) |
| 19 export DART_FLAGS="--checked" |
| 20 TEST_PATTERN=$1 |
| 21 |
| 22 function fail { |
| 23 return 1 |
| 24 } |
| 25 |
| 26 function show_diff { |
| 27 diff -u -N $1 $2 | \ |
| 28 sed -e "s/^\(+.*\)/[32m\1[0m/" |\ |
| 29 sed -e "s/^\(-.*\)/[31m\1[0m/" |
| 30 return 1 |
| 31 } |
| 32 |
| 33 function update { |
| 34 read -p "Would you like to update the expectations? [y/N]: " answer |
| 35 if [[ $answer == 'y' || $answer == 'Y' ]]; then |
| 36 cp $2 $1 |
| 37 return 0 |
| 38 fi |
| 39 return 1 |
| 40 } |
| 41 |
| 42 function pass { |
| 43 echo -e "[32mOK[0m" |
| 44 } |
| 45 |
| 46 function compare { |
| 47 # use a standard diff, if they are not identical, format the diff nicely to |
| 48 # see what's the error and prompt to see if they wish to update it. If they |
| 49 # do, continue running more tests. |
| 50 diff -q $1 $2 && pass || show_diff $1 $2 || update $1 $2 |
| 51 } |
| 52 |
| 53 if [[ ($TEST_PATTERN == "") ]]; then |
| 54 # Note: dartanalyzer needs to be run from the root directory for proper path |
| 55 # canonicalization. |
| 56 pushd $DIR/.. > /dev/null |
| 57 |
| 58 echo Analyzing compiler for warnings or type errors |
| 59 dartanalyzer --hints --fatal-warnings --fatal-type-errors bin/dwc.dart |
| 60 |
| 61 echo -e "\nAnalyzing runtime for warnings or type errors" |
| 62 dartanalyzer --hints --fatal-warnings --fatal-type-errors lib/polymer.dart |
| 63 |
| 64 popd > /dev/null |
| 65 fi |
| 66 |
| 67 function compare_all { |
| 68 # TODO(jmesserly): bash and dart regexp might not be 100% the same. Ideally we |
| 69 # could do all the heavy lifting in Dart code, and keep this script as a thin |
| 70 # wrapper that sets `--enable-type-checks --enable-asserts` |
| 71 for input in $DIR/../example/component/news/test/*_test.html \ |
| 72 $DIR/../../../samples/third_party/todomvc/test/*_test.html; do |
| 73 if [[ ($TEST_PATTERN == "") || ($input =~ $TEST_PATTERN) ]]; then |
| 74 FILENAME=`basename $input` |
| 75 DIRNAME=`dirname $input` |
| 76 if [[ `basename $DIRNAME` == 'input' ]]; then |
| 77 DIRNAME=`dirname $DIRNAME` |
| 78 fi |
| 79 echo -e -n "Checking diff for $FILENAME " |
| 80 DUMP="$DIRNAME/out/$FILENAME.txt" |
| 81 EXPECTATION="$DIRNAME/expected/$FILENAME.txt" |
| 82 |
| 83 compare $EXPECTATION $DUMP |
| 84 fi |
| 85 done |
| 86 echo -e "[31mSome tests failed[0m" |
| 87 fail |
| 88 } |
| 89 |
| 90 if [[ -e $DIR/data/input/example ]]; then |
| 91 echo "WARNING: detected old data/input/example symlink." |
| 92 echo "Removing it and rerunning pub install to fix broken example symlinks." |
| 93 echo "See http://dartbug.com/9418 for more information." |
| 94 echo "You should only see this message once." |
| 95 if [[ -e $DIR/packages ]]; then |
| 96 find . -name packages -type l | xargs rm |
| 97 fi |
| 98 rm $DIR/data/input/example |
| 99 pushd $DIR/.. |
| 100 pub install |
| 101 popd |
| 102 fi |
| 103 |
| 104 # TODO(jmesserly): dart:io fails if we run the Dart scripts with an absolute |
| 105 # path. So use pushd/popd to change the working directory. |
| 106 if [[ ($TEST_PATTERN == "") ]]; then |
| 107 pushd $DIR/.. > /dev/null |
| 108 echo -e "\nTesting build.dart... " |
| 109 dart $DART_FLAGS build.dart |
| 110 # Run it the way the editor does. Hide stdout because it is in noisy machine |
| 111 # format. Show stderr in case something breaks. |
| 112 # NOTE: not using --checked because the editor doesn't use it, and to workarou
nd |
| 113 # http://dartbug.com/9637 |
| 114 dart build.dart --machine --clean > /dev/null |
| 115 dart build.dart --machine --full > /dev/null |
| 116 dart build.dart --machine --changed ../../samples/third_party/todomvc/web/inde
x.html > /dev/null |
| 117 popd > /dev/null |
| 118 fi |
| 119 |
| 120 pushd $DIR > /dev/null |
| 121 echo -e "\nRunning unit tests... " |
| 122 dart $DART_FLAGS run_all.dart $@ || compare_all |
| 123 popd > /dev/null |
| 124 |
| 125 # Run Dart analyzer to check that we're generating warning clean code. |
| 126 # It's a bit slow, so only do this for TodoMVC and html5_utils tests. |
| 127 OUT_PATTERN="$DIR/../../../third_party/samples/todomvc/test/out/test/*$TEST_PATT
ERN*_bootstrap.dart" |
| 128 if [[ `ls $OUT_PATTERN 2>/dev/null` != "" ]]; then |
| 129 echo -e "\nAnalyzing generated code for warnings or type errors." |
| 130 ls $OUT_PATTERN 2>/dev/null | dartanalyzer --package-root=packages \ |
| 131 --fatal-warnings --fatal-type-errors -batch |
| 132 fi |
| 133 |
| 134 echo -e "[32mAll tests pass[0m" |
OLD | NEW |