<commit_before><?php

namespace Spec\PHPSpec\Runner\Cli;

use \PHPSpec\Runner\Cli\Parser as CliParser;

class DescribeParser extends \PHPSpec\Context
{
    function before()
    {
        $this->parser = $this->spec(new CliParser);
    }
    
    function itRemovesTheProgramNameFromArguments()
    {
        $args = array('/usr/bin/phpspec', '-h');
        $this->parser->parse($args);
        $this->parser->getArguments()->should->be(array('-h'));
    }
    
    function itExtractsTheSpecFileOutOfTheFirstArgument()
    {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '-f', 'd', '-c');
        $this->parser->parse($args);
        $this->parser->getOption('specFile')->should->be('MySpec.php');
    }
    
    function itComplainsWhenCalledWithNoArgumentsApartFromProgramName()
    {
        $parser = $this->parser;
        $this->spec( function() use ($parser) {
            $parser->parse(array('/usr/bin/phpspec'));
        })->should->throwException(
            '\PHPSpec\Runner\Cli\Error',
            'phpspec: Invalid number of arguments. Type -h for help'
        );
    }
    
    function itConvertsOneLetterValidArgumentsIntoOptions()
    {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '-c', '-h');
        $this->parser->parse($args);
        $this->parser->getOption('c')->should->beTrue();
        $this->parser->getOption('h')->should->beTrue();
    }
    
    function itSavesOneLetterValidArgumentsIntoOptionLongNameVersion()
    {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '-c', '-h');
        $this->parser->parse($args);
        $this->parser->getOption('color')->should->beTrue();
        $this->parser->getOption('colour')->should->beTrue();
        $this->parser->getOption('help')->should->beTrue();
    }
    
    function itSavesLongVersionValidArgumentsIntoOptionOneLetterVersion()
    {
        $args = array(
            '/usr/bin/phpspec',
            'MySpec.php',
            '--color',
            '--help'
        );
        $this->parser->parse($args);
        $this->parser->getOption('c')->should->beTrue();
        $this->parser->getOption('h')->should->beTrue();
    }
    
    function itConvertsUnseparatedOneLetterValidArgumentsIntoOptions()
    {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '-ch');
        $this->parser->parse($args);
        $this->parser->getOption('c')->should->beTrue();
        $this->parser->getOption('h')->should->beTrue();
    }
    
    function itConvertsSpaceSeparateFormatterOptionValueAppropriately()
    {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '-f', 'd');
        $this->parser->parse($args);
        $this->parser->getOption('f')->should->be('d');
        $this->parser->getOption('formatter')->should->be('d');
    }
    
    function itConvertsEqualSignSeparateLongFormatterOptionValueAppropriately()
    {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '--formatter', 'd');
        $this->parser->parse($args);
        $this->parser->getOption('f')->should->be('d');
        $this->parser->getOption('formatter')->should->be('d');
    }
    
    function itComplainsWhenFormatterIsNotGivenTheArgument()
    {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '-f');
        $parser = $this->parser;
        $this->spec(
            function() use ($parser, $args) {
                $parser->parse($args);
            }
        )->should->throwException(
            '\PHPSpec\Runner\Cli\Error', 'phpspec: Invalid argument for formatter'
        );
    }
    
    function itAcceptsFormatterToBePassedWithNoSpace()
    {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '-fd');
        $this->parser->parse($args);
        $this->parser->getOption('f')->should->be('d');
        $this->parser->getOption('formatter')->should->be('d');
    }
    
    function itRejectsInvalidFormatter()
    {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '-fx');
        $parser = $this->parser;
        $this->spec(
            function() use ($parser, $args) {
                $parser->parse($args);
            }
        )->should->throwException(
            '\PHPSpec\Runner\Cli\Error', 'phpspec: Invalid argument for formatter'
        );
    }
    
    function itRejectsInvalidFormatterFromLongOption()
    {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '--formatter', 'x');
        $parser = $this->parser;
        $this->spec(function() use ($parser, $args) {
            $parser->parse($args);
        })->should->throwException('\PHPSpec\Runner\Cli\Error',
            'phpspec: Invalid argument for formatter');
    }
    
    function itCanSpecifyShortOptionForExample()
    {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '-e', 'itShouldDoSomething');
        $this->parser->parse($args);
        $this->parser->getOption('e')->should->be('itShouldDoSomething');
    }

    function itCanSpecifyLongOptionForExample()
    {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '--example', 'itShouldDoSomething');
        $this->parser->parse($args);
        $this->parser->getOption('e')->should->be('itShouldDoSomething');
    }
    
    function itAcceptsBootstrapFile() {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '--bootstrap', 'bootstrap.php');
        $this->parser->parse($args);
        $this->parser->getOption('bootstrap')->should->be('bootstrap.php');
    }
    
    function itShouldComplainWhenBootstrapOptionIsSpecifiedWithoutFilename() {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '--bootstrap');
        //$this->parser->parse($args);
        $parser = $this->parser;
        //$this->parser->getOption('bootstrap')->should->be('bootstrap.php');
        $this->spec(
            function() use ($parser, $args) {
                $parser->parse($args);
            }
        )->should->throwException(
            'PHPSpec\Runner\Cli\Error', 'phpspec: Bootstrap file should be given for bootstrap option'
        );
    }
    
    function itShouldAcceptTextmateAsAValidFormatter()
    {
        $args = array('/usr/bin/phpspec', 'MySpec.php', '--formatter', 'textmate');
        $parser = $this->parser;
        
        $this->spec(
            function() use ($parser, $args) {
                $parser->parse($args);
            }
        )->shouldNot->throwException('PHPSpec\Runner\Cli\Error', 'phpspec: Invalid argument for formatter');
    }
}<commit_msg>Fix ParseSpec test to use generic executable path<commit_after><?php

namespace Spec\PHPSpec\Runner\Cli;

use \PHPSpec\Runner\Cli\Parser as CliParser;

class DescribeParser extends \PHPSpec\Context
{
    function before()
    {
        global $argv;
        $this->parser = $this->spec(new CliParser);
        $this->executable = $argv[0];
    }
    
    function itRemovesTheProgramNameFromArguments()
    {
        $args = array($this->executable, '-h');
        $this->parser->parse($args);
        $this->parser->getArguments()->should->be(array('-h'));
    }
    
    function itExtractsTheSpecFileOutOfTheFirstArgument()
    {
        $args = array($this->executable, 'MySpec.php', '-f', 'd', '-c');
        $this->parser->parse($args);
        $this->parser->getOption('specFile')->should->be('MySpec.php');
    }
    
    function itComplainsWhenCalledWithNoArgumentsApartFromProgramName()
    {
        $parser = $this->parser;
        $executable = $this->executable;
        $this->spec( function() use ($parser, $executable) {
            $parser->parse(array($executable));
        })->should->throwException(
            '\PHPSpec\Runner\Cli\Error',
            'phpspec: Invalid number of arguments. Type -h for help'
        );
    }
    
    function itConvertsOneLetterValidArgumentsIntoOptions()
    {
        $args = array($this->executable, 'MySpec.php', '-c', '-h');
        $this->parser->parse($args);
        $this->parser->getOption('c')->should->beTrue();
        $this->parser->getOption('h')->should->beTrue();
    }
    
    function itSavesOneLetterValidArgumentsIntoOptionLongNameVersion()
    {
        $args = array($this->executable, 'MySpec.php', '-c', '-h');
        $this->parser->parse($args);
        $this->parser->getOption('color')->should->beTrue();
        $this->parser->getOption('colour')->should->beTrue();
        $this->parser->getOption('help')->should->beTrue();
    }
    
    function itSavesLongVersionValidArgumentsIntoOptionOneLetterVersion()
    {
        $args = array(
            $this->executable,
            'MySpec.php',
            '--color',
            '--help'
        );
        $this->parser->parse($args);
        $this->parser->getOption('c')->should->beTrue();
        $this->parser->getOption('h')->should->beTrue();
    }
    
    function itConvertsUnseparatedOneLetterValidArgumentsIntoOptions()
    {
        $args = array($this->executable, 'MySpec.php', '-ch');
        $this->parser->parse($args);
        $this->parser->getOption('c')->should->beTrue();
        $this->parser->getOption('h')->should->beTrue();
    }
    
    function itConvertsSpaceSeparateFormatterOptionValueAppropriately()
    {
        $args = array($this->executable, 'MySpec.php', '-f', 'd');
        $this->parser->parse($args);
        $this->parser->getOption('f')->should->be('d');
        $this->parser->getOption('formatter')->should->be('d');
    }
    
    function itConvertsEqualSignSeparateLongFormatterOptionValueAppropriately()
    {
        $args = array($this->executable, 'MySpec.php', '--formatter', 'd');
        $this->parser->parse($args);
        $this->parser->getOption('f')->should->be('d');
        $this->parser->getOption('formatter')->should->be('d');
    }
    
    function itComplainsWhenFormatterIsNotGivenTheArgument()
    {
        $args = array($this->executable, 'MySpec.php', '-f');
        $parser = $this->parser;
        $this->spec(
            function() use ($parser, $args) {
                $parser->parse($args);
            }
        )->should->throwException(
            '\PHPSpec\Runner\Cli\Error', 'phpspec: Invalid argument for formatter'
        );
    }
    
    function itAcceptsFormatterToBePassedWithNoSpace()
    {
        $args = array($this->executable, 'MySpec.php', '-fd');
        $this->parser->parse($args);
        $this->parser->getOption('f')->should->be('d');
        $this->parser->getOption('formatter')->should->be('d');
    }
    
    function itRejectsInvalidFormatter()
    {
        $args = array($this->executable, 'MySpec.php', '-fx');
        $parser = $this->parser;
        $this->spec(
            function() use ($parser, $args) {
                $parser->parse($args);
            }
        )->should->throwException(
            '\PHPSpec\Runner\Cli\Error', 'phpspec: Invalid argument for formatter'
        );
    }
    
    function itRejectsInvalidFormatterFromLongOption()
    {
        $args = array($this->executable, 'MySpec.php', '--formatter', 'x');
        $parser = $this->parser;
        $this->spec(function() use ($parser, $args) {
            $parser->parse($args);
        })->should->throwException('\PHPSpec\Runner\Cli\Error',
            'phpspec: Invalid argument for formatter');
    }
    
    function itCanSpecifyShortOptionForExample()
    {
        $args = array($this->executable, 'MySpec.php', '-e', 'itShouldDoSomething');
        $this->parser->parse($args);
        $this->parser->getOption('e')->should->be('itShouldDoSomething');
    }

    function itCanSpecifyLongOptionForExample()
    {
        $args = array($this->executable, 'MySpec.php', '--example', 'itShouldDoSomething');
        $this->parser->parse($args);
        $this->parser->getOption('e')->should->be('itShouldDoSomething');
    }
    
    function itAcceptsBootstrapFile() {
        $args = array($this->executable, 'MySpec.php', '--bootstrap', 'bootstrap.php');
        $this->parser->parse($args);
        $this->parser->getOption('bootstrap')->should->be('bootstrap.php');
    }
    
    function itShouldComplainWhenBootstrapOptionIsSpecifiedWithoutFilename() {
        $args = array($this->executable, 'MySpec.php', '--bootstrap');
        //$this->parser->parse($args);
        $parser = $this->parser;
        //$this->parser->getOption('bootstrap')->should->be('bootstrap.php');
        $this->spec(
            function() use ($parser, $args) {
                $parser->parse($args);
            }
        )->should->throwException(
            'PHPSpec\Runner\Cli\Error', 'phpspec: Bootstrap file should be given for bootstrap option'
        );
    }
    
    function itShouldAcceptTextmateAsAValidFormatter()
    {
        $args = array($this->executable, 'MySpec.php', '--formatter', 'textmate');
        $parser = $this->parser;
        
        $this->spec(
            function() use ($parser, $args) {
                $parser->parse($args);
            }
        )->shouldNot->throwException('PHPSpec\Runner\Cli\Error', 'phpspec: Invalid argument for formatter');
    }
}
{'fraction_non_alphanumeric': 0.1850764714969875, 'fraction_numerical': 7.724393635099645e-05, 'mean_word_length': 2.506771397616468, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 306, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4203535', 'n_tokens_mistral': 3899, 'n_tokens_neox': 3846, 'n_words': 534}