<commit_before>#!/bin/bash
set -e # bail on error

function fail {
  echo -e "[31mSome tests failed[0m"
  return 1
}

function show_diff {
  echo "Fail: actual output did not match expected"
  echo
  diff -u -r -N $1 $2 |\
    sed -e "s/^\(+.*\)/[32m\1[0m/" |\
    sed -e "s/^\(-.*\)/[31m\1[0m/"
  echo
  echo "You can update these expectations with:"
  echo "$ pushd `pwd` && cp -a actual/* expect && popd"
  fail
}

# the directory of this script 
TEST_DIR=$( cd $( dirname "${BASH_SOURCE[0]}" ) && pwd )

# Some tests require being run from the package root
cd $TEST_DIR/..

# Check minimum SDK version
./tool/sdk_version_check.dart 1.9.0-dev.4.0 || fail

# Remove packages symlinks, and old codegen output
find test/codegen -name packages -exec rm {} \;
rm -r test/codegen/actual 2> /dev/null || true
find test/dart_codegen -name packages -exec rm {} \;
rm -r test/dart_codegen/actual 2> /dev/null || true
dart -c test/all_tests.dart || fail

# validate codegen_test output
pushd test/codegen/ &> /dev/null
diff -u -r -N expect actual > /dev/null || show_diff expect actual
popd &> /dev/null

# validate dart_codegen_test output
pushd test/dart_codegen/ &> /dev/null
diff -u -r -N expect actual > /dev/null || show_diff expect actual
popd &> /dev/null

# run self host and analyzer after other tests, because they're ~seconds to run.
dart -c test/checker/self_host_test.dart || fail

# Run analyzer on bin/devc.dart, as it includes most of the code we care about
# via transitive dependencies. This seems to be the only fast way to avoid
# repeated analysis of the same code.
# TODO(jmesserly): ideally we could do test/all_tests.dart, but
# dart_runtime_test.dart creates invalid generic type instantiation AA.
echo "Running dartanalyzer to check for errors/warnings/hints..."
dartanalyzer --fatal-warnings --package-warnings bin/devc.dart | (! grep $PWD) \
    || fail

{
  fc=`find test -name "*.dart" |\
      xargs grep "/\*\S* should be \S*\*/" | wc -l`
  echo "There are" $fc "tests marked as known failures."
}

# Run formatter on all files that are part of the project. This checks that all
# files are commited first. This also ignores local files that have never been
# added to the git repo.
(files=`git ls-files "*.dart" | grep -v test/sdk/lib/`; git status -s $files | grep -q . \
  && echo "Did not run the formatter, please commit edited files first." \
  || (echo "Running dart formatter" ; pub run dart_style:format -w $files))
popd &> /dev/null

echo -e "[32mAll tests pass[0m"<commit_msg>exclude test from dartfmt formatter is currently failing on generated code files<commit_after>#!/bin/bash
set -e # bail on error

function fail {
  echo -e "[31mSome tests failed[0m"
  return 1
}

function show_diff {
  echo "Fail: actual output did not match expected"
  echo
  diff -u -r -N $1 $2 |\
    sed -e "s/^\(+.*\)/[32m\1[0m/" |\
    sed -e "s/^\(-.*\)/[31m\1[0m/"
  echo
  echo "You can update these expectations with:"
  echo "$ pushd `pwd` && cp -a actual/* expect && popd"
  fail
}

# the directory of this script 
TEST_DIR=$( cd $( dirname "${BASH_SOURCE[0]}" ) && pwd )

# Some tests require being run from the package root
cd $TEST_DIR/..

# Check minimum SDK version
./tool/sdk_version_check.dart 1.9.0-dev.4.0 || fail

# Remove packages symlinks, and old codegen output
find test/codegen -name packages -exec rm {} \;
rm -r test/codegen/actual 2> /dev/null || true
find test/dart_codegen -name packages -exec rm {} \;
rm -r test/dart_codegen/actual 2> /dev/null || true
dart -c test/all_tests.dart || fail

# validate codegen_test output
pushd test/codegen/ &> /dev/null
diff -u -r -N expect actual > /dev/null || show_diff expect actual
popd &> /dev/null

# validate dart_codegen_test output
pushd test/dart_codegen/ &> /dev/null
diff -u -r -N expect actual > /dev/null || show_diff expect actual
popd &> /dev/null

# run self host and analyzer after other tests, because they're ~seconds to run.
dart -c test/checker/self_host_test.dart || fail

# Run analyzer on bin/devc.dart, as it includes most of the code we care about
# via transitive dependencies. This seems to be the only fast way to avoid
# repeated analysis of the same code.
# TODO(jmesserly): ideally we could do test/all_tests.dart, but
# dart_runtime_test.dart creates invalid generic type instantiation AA.
echo "Running dartanalyzer to check for errors/warnings/hints..."
dartanalyzer --fatal-warnings --package-warnings bin/devc.dart | (! grep $PWD) \
    || fail

{
  fc=`find test -name "*.dart" |\
      xargs grep "/\*\S* should be \S*\*/" | wc -l`
  echo "There are" $fc "tests marked as known failures."
}

# Run formatter on all files that are part of the project. This checks that all
# files are commited first. This also ignores local files that have never been
# added to the git repo.
(files=`git ls-files "*.dart" | grep -v test/`; git status -s $files | \
  grep -q . \
  && echo "Did not run the formatter, please commit edited files first." \
  || (echo "Running dart formatter" ; pub run dart_style:format -w $files))
popd &> /dev/null

echo -e "[32mAll tests pass[0m"
{'fraction_non_alphanumeric': 0.1307074270037233, 'fraction_numerical': 0.009798157946306094, 'mean_word_length': 3.310810810810811, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3076712', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1721, 'n_words': 660}