You are here

function SassyBaseUnitTest::runTest in Sassy 7.2

2 calls to SassyBaseUnitTest::runTest()
SassyCompassUnitTest::testCompass in extensions/compass/sassy_compass.test
SassyUnitTest::testMain in ./sassy.test

File

./sassy.test, line 113

Class

SassyBaseUnitTest
Base class for Sassy tests.

Code

function runTest($input, $output = FALSE, $settings = array()) {
  $name = $input;
  $path = $this->css_tests_path;
  $output = $path . ($output ? $output : preg_replace('/\\..+$/', '.css', $input));
  $input = $path . $input;
  if (!file_exists($input)) {
    return $this
      ->fail('Input file not found - ' . $input);
  }
  if (!file_exists($output)) {
    return $this
      ->fail('Comparison file not found - ' . $output);
  }
  $exploded = explode('.', $input);
  try {
    $settings = $settings + array(
      'style' => 'nested',
      'cache' => FALSE,
      'syntax' => array_pop($exploded),
      'debug' => FALSE,
      'debug_info' => FALSE,
      'load_path_functions' => array(
        'sassy_load_callback',
      ),
      'functions' => sassy_get_functions(),
      'callbacks' => array(
        'debug' => array(
          $this,
          'sassParserDebug',
        ),
        'warn' => array(
          $this,
          'sassParserWarning',
        ),
      ),
    );
    $parser = new SassParser($settings);
    $result = $parser
      ->toCss($input);
  } catch (Exception $e) {
    $this
      ->fail(t('Exception occured when compiling file') . ': ' . (string) $e);
  }
  $compare = $this
    ->loadOutputFile($output);
  if ($compare === FALSE) {
    $this
      ->fail('Unable to load comparison file - ' . $compare);
  }
  $_result = $this
    ->trimResult($result);
  $_compare = $this
    ->trimResult($compare);
  if ($_result != $_compare) {
    $this
      ->fail(t('Result for ' . $name . ' did not match comparison file'));
  }
  else {
    $this
      ->pass(t($name . ' compiled correctly'));
  }

  // Log the compiled result, which is very useful for debugging.
  $this
    ->verbose(format_string('<div>Compiled output: <pre>@result</pre></div><div>Expected: <pre>@expected</pre></div>', array(
    '@result' => $result,
    '@expected' => $compare,
  )));
}