<commit_before>#!/bin/bash
#
# Copyright 2011 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Scans source directories for _test.cc files and makes sure they are mentioned
# in the appropriate gyp files.
#
# This script serves two purposes; it is the entry-point to the scan
# (0 args), and is also the script used in 'find -exec' (>0 args).

set -u

if [ $# -eq 0 ]; then
  # Get absolute path for script so we can still reference it after 'cd'.
  this_dir="$(dirname "${BASH_SOURCE[0]}")"
  script="$this_dir/check_tests_are_run.sh"
  src="$this_dir/.."

  set -e
  test_gyp="$src/net/instaweb/test.gyp"
  tps="pagespeed"
  for entry in $tps/*; do
    if [[ -d $entry ]]; then
      find $entry -name *_test.cc -exec $script {} $test_gyp \;
    fi
  done
else
  test_cc_path="$1"; shift
  test_cc_name=$(basename $test_cc_path)

  test_cc_dir=$(dirname $test_cc_path)
  found=0
  for gypfile in "$@"; do
    if grep -q $test_cc_name $gypfile; then
      found=1
    fi
  done

  if [ $found -eq 0 ]; then
    echo $test_cc_path missing from "$@"
  fi
fi<commit_msg>Rewrite check_tests_are_run.sh to be simpler.<commit_after>#!/bin/bash
#
# Scans source directories for _test.cc files to find ones that aren't mentioned
# in the test gyp file.  On success produces no output, otherwise prints the
# names of the unreferenced _test.cc files.

set -u
set -e

this_dir="$(dirname "${BASH_SOURCE[0]}")"
cd "$this_dir/.."

test_gyp="net/instaweb/test.gyp"
find net pagespeed -name *_test.cc | while read test_path; do
  if ! grep -q "$(basename "$test_path")" "$test_gyp"; then
    echo "$test_path ($(basename "$test_path")) missing from $test_gyp"
  fi
done
{'fraction_non_alphanumeric': 0.1152073732718894, 'fraction_numerical': 0.00783410138248848, 'mean_word_length': 3.75054704595186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '1852902', 'n_tokens_mistral': 737, 'n_tokens_neox': 707, 'n_words': 271}