Skip to content

Commit

Permalink
SonarConfigurationFileParser tests fail on cygwin (Windows) (#1425)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlairCooper authored Nov 8, 2020
1 parent 275e360 commit 8c0fb0f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function parse()
throw new BuildException($message);
}

$lines = explode("\n", $contents);
$lines = preg_split("/\r?\n/", $contents);
$count = count($lines);
$isMultiLine = false;
for ($i = 0; $i < $count; $i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,69 @@ public function testPropertyHasMultiLineValueIntermediateLineIsEmpty()
$this->assertArrayHasKey('foo', $properties);
$this->assertContains('This is a multi-line comment.', $properties);
}

/*
* Tests property file with Newline(LF) line termination
*
* @covers SonarConfigurationFileParser::parse
*/
public function testFileWithNL()
{
$tmpFile = tempnam(sys_get_temp_dir(), 'cfp');

$fh = fopen($tmpFile, 'w');

if (false !== $fh) {
register_shutdown_function(function () use ($tmpFile) {
unlink($tmpFile);
});

fwrite($fh, "foo:bar\nbrown:cow\n");
fclose($fh);

$parser = new SonarConfigurationFileParser($tmpFile, $this->getProject());

$properties = $parser->parse();

$this->assertArrayHasKey('foo', $properties);
$this->assertContains('bar', $properties);

$this->assertArrayHasKey('brown', $properties);
$this->assertContains('cow', $properties);
} else {
$this->fail('Failed to create temporary file');
}
}

/*
* Tests property file with CarriageReturn/LineFeed (CRLF) line termination
*
* @covers SonarConfigurationFileParser::parse
*/
public function testFileWithCRLF()
{
$tmpFile = tempnam(sys_get_temp_dir(), 'cfp');

$fh = fopen($tmpFile, 'w');
if (false !== $fh) {
register_shutdown_function(function () use ($tmpFile) {
unlink($tmpFile);
});

fwrite($fh, "rag:doll\r\nhouse:cat\r\n");
fclose($fh);

$parser = new SonarConfigurationFileParser($tmpFile, $this->getProject());

$properties = $parser->parse();

$this->assertArrayHasKey('rag', $properties);
$this->assertContains('doll', $properties);

$this->assertArrayHasKey('house', $properties);
$this->assertContains('cat', $properties);
} else {
$this->fail('Failed to create temporary file');
}
}
}

0 comments on commit 8c0fb0f

Please sign in to comment.