<commit_before>#!/usr/bin/env php
<?php

require $_SERVER['PWD'] . '/.git/hooks/utils.php';

function getSUT($file) {
	if (!preg_match('@\.php$@', $file) || preg_match('@(Config|test_app)[\\\/]@', $file)) {
		return false;
	}

	if (preg_match('@Test[\\\/]@', $file)) {
		if (substr($file, -8) !== 'Test.php') {
			return false;
		}

		if (preg_match('@.*lib[\\\/]Cake[\\\/]@', $file)) {
			$file = preg_replace('@^(.*)Test([\\\/])Case[\\\/]@', '\1lib\2Cake\2', $file); // Untested
		} else {
			$file = preg_replace('@^(.*)Test[\\\/]Case[\\\/](.*)Test.php$@', '\1\2.php', $file);
		}
	}
	return $file;
}

$files = files();
$toTest = array();
$exit = 0;

foreach ($files as $file) {
	$file = getSUT($file);

	if (!$file) {
		continue;
	}
	$toTest[$file] = true;
}

if (file_exists('app/Console/cake')) {
	$prefix = 'cd app; Console/';
} elseif (file_exists('Console/cake')) {
	$prefix = 'Console/';
} else {
	$prefix = '';
}

foreach (array_keys($toTest) as $file) {
	$output = array();
	$cmd = "{$prefix}cake test $file --stderr 2>&1";
	echo "$cmd\n";
	exec($cmd, $output, $return);

	if ($return != 0) {
		echo implode("\n", $output), "\n";
		$exit = 1;
	}
}

exit($exit);
<commit_msg>fix the test $file to also be app-less<commit_after>#!/usr/bin/env php
<?php

require $_SERVER['PWD'] . '/.git/hooks/utils.php';

function getSUT($file) {
	if (!preg_match('@\.php$@', $file) || preg_match('@(Config|test_app)[\\\/]@', $file)) {
		return false;
	}

	if (preg_match('@Test[\\\/]@', $file)) {
		if (substr($file, -8) !== 'Test.php') {
			return false;
		}

		if (preg_match('@.*lib[\\\/]Cake[\\\/]@', $file)) {
			$file = preg_replace('@^(.*)Test([\\\/])Case[\\\/]@', '\1lib\2Cake\2', $file); // Untested
		} else {
			$file = preg_replace('@^(.*)Test[\\\/]Case[\\\/](.*)Test.php$@', '\1\2.php', $file);
		}
	}
	return $file;
}

$files = files();
$toTest = array();
$exit = 0;

foreach ($files as $file) {
	$file = getSUT($file);

	if (!$file) {
		continue;
	}
	$toTest[$file] = true;
}
$toTest = array_flip($toTest);

if (file_exists('app/Console/cake')) {
	$prefix = 'cd app; Console/';
	foreach ($toTest as &$file) {
		if (substr($file, 3) === 'app') {
			$file = preg_replace('@^app[\\\/]@', '', $file);
		}
	}
	unset($file);
} elseif (file_exists('Console/cake')) {
	$prefix = 'Console/';
} else {
	$prefix = '';
}

foreach ($toTest as $file) {
	$output = array();
	$cmd = "{$prefix}cake test $file --stderr 2>&1";
	echo "$cmd\n";
	exec($cmd, $output, $return);

	if ($return != 0) {
		echo implode("\n", $output), "\n";
		$exit = 1;
	}
}

exit($exit);

{'fraction_non_alphanumeric': 0.2929213922565507, 'fraction_numerical': 0.00899491591709034, 'mean_word_length': 3.4642233856893543, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5968916', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1096, 'n_words': 211}