Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/windows bin #195

Merged
merged 5 commits into from
Nov 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions bin/commonmark
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ if (isset($src)) {
$markdown = file_get_contents($src);
} else {
$stdin = fopen('php://stdin', 'r');
stream_set_blocking($stdin, false);
$markdown = stream_get_contents($stdin);

if (stream_set_blocking($stdin, false)) {
$markdown = stream_get_contents($stdin);
}

fclose($stdin);

if (empty($markdown)) {
Expand All @@ -76,6 +79,30 @@ echo $converter->convertToHtml($markdown);
*/
function getHelpText()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
return <<<WINDOWSHELP
CommonMark - Markdown done right

Usage: commonmark [OPTIONS] [FILE]

-h, --help Shows help and usage information

(Reading data from STDIN is not currently supported on Windows)

Examples:

Converting a file named document.md:

commonmark document.md

Converting a file and saving its output:

commonmark document.md > output.html

Full documentation can be found at http://commonmark.thephpleague.com/
WINDOWSHELP;
}

return <<<HELP
CommonMark - Markdown done right

Expand Down
22 changes: 19 additions & 3 deletions tests/functional/BinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public function testNoArgsOrStdin()

$this->assertEquals(1, $cmd->getExitCode());
$this->assertEmpty($cmd->getOutput());
$this->assertContains('Usage:', $cmd->getError());

if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
$this->assertContains('Usage:', $cmd->getError());
}
}

/**
Expand Down Expand Up @@ -55,7 +58,10 @@ public function testUnknownOption()
$cmd->execute();

$this->assertEquals(1, $cmd->getExitCode());
$this->assertContains('Unknown option', $cmd->getError());

if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
$this->assertContains('Unknown option', $cmd->getError());
}
}

/**
Expand All @@ -77,6 +83,10 @@ public function testFileArgument()
*/
public function testStdin()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$this->markTestSkipped('Test skipped: STDIN is not supported on Windows');
}

$cmd = new Command(sprintf('cat %s | %s ', $this->getPathToData('atx_header.md'), $this->getPathToCommonmark()));
$cmd->execute();

Expand All @@ -92,7 +102,13 @@ public function testStdin()
*/
protected function getPathToCommonmark()
{
return realpath(__DIR__ . '/../../bin/commonmark');
$path = realpath(__DIR__ . '/../../bin/commonmark');

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$path = 'php ' . $path;
}

return $path;
}

/**
Expand Down
8 changes: 7 additions & 1 deletion tests/functional/EmphasisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ class EmphasisTest extends \PHPUnit_Framework_TestCase
*/
protected function getPathToCommonmark()
{
return realpath(__DIR__ . '/../../bin/commonmark');
$path = realpath(__DIR__ . '/../../bin/commonmark');

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$path = 'php ' . $path;
}

return $path;
}

/**
Expand Down