Permalink
Browse files

MDL-33064 tests: remove code_test.php

This test was doing work which doesn't make sense as a unit test.
Perhaps the most sensible option would be to use a git hook. Here is
a replacement David Mudrák created:

$ cat .git/hooks/pre-commit
 #!/bin/bash

FOUND=$(git diff-index --cached -U0 HEAD -- | grep DONOTCOMMIT | wc -l)

if [[ $FOUND -gt 0 ]]; then
    echo "pre-commit hook: DONOTCOMMIT detected, commit not allowed"
    exit 1
fi
  • Loading branch information...
1 parent f05e25d commit 88de0401aeadc17c0fa0e860a1d34d11521487f8 @danpoltawski danpoltawski committed Jan 23, 2014
Showing with 0 additions and 76 deletions.
  1. +0 −76 lib/tests/code_test.php
View
@@ -1,76 +0,0 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * Code quality unit tests that are fast enough to run each time.
- *
- * @package core
- * @category phpunit
- * @copyright &copy; 2006 The Open University
- * @author T.J.Hunt@open.ac.uk
- * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-class core_code_testcase extends advanced_testcase {
- protected $badstrings;
- protected $extensions_to_ignore = array('exe', 'gif', 'ico', 'jpg', 'png', 'ttf', 'log');
- protected $ignore_folders = array();
-
- public function test_dnc() {
- global $CFG;
-
- if ($CFG->ostype === 'UNIX') {
- // Try it the faster way.
- $oldcwd = getcwd();
- chdir($CFG->dirroot);
- $output = null;
- $exclude = array();
- foreach ($this->extensions_to_ignore as $ext) {
- $exclude[] = '--exclude="*.'.$ext.'"';
- }
- $exclude = implode(' ', $exclude);
- exec('grep -r '.$exclude.' DONOT'.'COMMIT .', $output, $code);
- chdir($oldcwd);
- // Return code 0 means found, return code 1 means NOT found, 127 is grep not found.
- if ($code == 1) {
- // Executed only if no file failed the test.
- $this->assertTrue(true);
- return;
- }
- }
-
- $regexp = '/\.(' . implode('|', $this->extensions_to_ignore) . ')$/';
- $this->badstrings = array();
- $this->badstrings['DONOT' . 'COMMIT'] = 'DONOT' . 'COMMIT'; // If we put the literal string here, it fails the test!
- $this->badstrings['trailing whitespace'] = "[\t ][\r\n]";
- foreach ($this->badstrings as $description => $ignored) {
- $this->allok[$description] = true;
- }
- $this->recurseFolders($CFG->dirroot, 'search_file_for_dnc', $regexp, true);
- $this->assertTrue(true); // Executed only if no file failed the test.
- }
-
- protected function search_file_for_dnc($filepath) {
- $content = file_get_contents($filepath);
- foreach ($this->badstrings as $description => $badstring) {
- if (stripos($content, $badstring) !== false) {
- $this->fail("File $filepath contains $description.");
- }
- }
- }
-}

0 comments on commit 88de040

Please sign in to comment.