Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix win eol #479

Merged
merged 3 commits into from

3 participants

@hans-d

On linux EOL is LF, on Windows it is normally CRLF, but the latter may depend also
on the git config core.autocrlf setting. As some tests use heredoc style (<<<) to
specify multiline expectations, this EOL issue may cause tests to fail only because
of a difference in EOL's used.

in assertEqual, assertNotEqual, assertPattern and assertNotPattern this function is
called to get rid of any EOL differences.

@hans-d hans-d suppressEolIssues
On linux EOL is LF, on Windows it is normally CRLF, but the latter may depend also
on the git config core.autocrlf setting. As some tests use heredoc style (<<<) to
specify multiline expectations, this EOL issue may cause tests to fail only because
of a difference in EOL's used.

in assertEqual, assertNotEqual, assertPattern and assertNotPattern this function is
called to get rid of any EOL differences.
b760352
test/Unit.php
@@ -246,6 +262,9 @@ public function fail($message = false) {
* @param string|boolean $message
*/
public function assertEqual($expected, $result, $message = false) {
+ if (is_string($expected) && is_string($result)) {
@gwoo Owner
gwoo added a note

I would move these is_string checks to the suppressEolIssues method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
test/Unit.php
@@ -238,6 +238,22 @@ public function fail($message = false) {
}
/**
+ * Fixes some issues regarding the used EOL character(s).
+ *
+ * On linux EOL is LF, on Windows it is normally CRLF, but the latter may depend also
+ * on the git config core.autocrlf setting. As some tests use heredoc style (<<<) to
+ * specify multiline expectations, this EOL issue may cause tests to fail only because
+ * of a difference in EOL's used.
+ *
+ * in assertEqual, assertNotEqual, assertPattern and assertNotPattern this function is
+ * called to get rid of any EOL differences.
+ */
+ protected function _suppressEolIssues(&$expected, &$result) {
@gwoo Owner
gwoo added a note

I think we settled on _normalizeLineEndings. Also, I would probably have this return array('expected', 'result') so the usage would be list($expected, $result) = $this->_normailizeLineEndings($expected, $result);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@nateabele nateabele merged commit 00fe3a3 into UnionOfRAD:dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 23, 2012
  1. @hans-d

    suppressEolIssues

    hans-d authored
    On linux EOL is LF, on Windows it is normally CRLF, but the latter may depend also
    on the git config core.autocrlf setting. As some tests use heredoc style (<<<) to
    specify multiline expectations, this EOL issue may cause tests to fail only because
    of a difference in EOL's used.
    
    in assertEqual, assertNotEqual, assertPattern and assertNotPattern this function is
    called to get rid of any EOL differences.
  2. @hans-d
  3. @hans-d
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 0 deletions.
  1. +23 −0 test/Unit.php
View
23 test/Unit.php
@@ -238,6 +238,25 @@ public function fail($message = false) {
}
/**
+ * Fixes some issues regarding the used EOL character(s).
+ *
+ * On linux EOL is LF, on Windows it is normally CRLF, but the latter may depend also
+ * on the git config core.autocrlf setting. As some tests use heredoc style (<<<) to
+ * specify multiline expectations, this EOL issue may cause tests to fail only because
+ * of a difference in EOL's used.
+ *
+ * in assertEqual, assertNotEqual, assertPattern and assertNotPattern this function is
+ * called to get rid of any EOL differences.
+ */
+ protected function _normalizeLineEndings($expected, $result) {
+ if (is_string($expected) && is_string($result)) {
+ $expected = preg_replace('/\r\n/', "\n", $expected);
+ $result = preg_replace('/\r\n/', "\n", $result);
+ }
+ return array($expected, $result);
+ }
+
+ /**
* Checks that the actual result is equal, but not neccessarily identical, to the expected
* result.
*
@@ -246,6 +265,7 @@ public function fail($message = false) {
* @param string|boolean $message
*/
public function assertEqual($expected, $result, $message = false) {
+ list($expected, $result) = $this->_normalizeLineEndings($expected, $result);
$data = ($expected != $result) ? $this->_compare('equal', $expected, $result) : null;
$this->assert($expected == $result, $message, $data);
}
@@ -258,6 +278,7 @@ public function assertEqual($expected, $result, $message = false) {
* @param string|boolean $message
*/
public function assertNotEqual($expected, $result, $message = false) {
+ list($expected, $result) = $this->_normalizeLineEndings($expected, $result);
$this->assert($result != $expected, $message, compact('expected', 'result'));
}
@@ -340,6 +361,7 @@ public function assertNull($result, $message = '{:message}') {
* @param string $message
*/
public function assertNoPattern($expected, $result, $message = '{:message}') {
+ list($expected, $result) = $this->_normalizeLineEndings($expected, $result);
$this->assert(!preg_match($expected, $result), $message, compact('expected', 'result'));
}
@@ -351,6 +373,7 @@ public function assertNoPattern($expected, $result, $message = '{:message}') {
* @param string $message
*/
public function assertPattern($expected, $result, $message = '{:message}') {
+ list($expected, $result) = $this->_normalizeLineEndings($expected, $result);
$this->assert(!!preg_match($expected, $result), $message, compact('expected', 'result'));
}
Something went wrong with that request. Please try again.