Skip to content
This repository was archived by the owner on Apr 20, 2021. It is now read-only.

Feature debug system context #150

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ before_script:

script:
- ./bin/atoum
- ./bin/behat -fprogress --tags='~@user'
- ./bin/behat -fprogress --tags='~@user' --tags='~@fail'

- ./bin/box build
- sed -i 's/Sanpi\\Behatch\\Extension/behatch_contexts.phar/' behat.yml
Expand Down
4 changes: 4 additions & 0 deletions i18n/en.xliff.dist
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@
<source>command should last more than :seconds seconds</source>
<target></target>
</trans-unit>
<trans-unit id="print-output">
<source>print output</source>
<target></target>
</trans-unit>
<trans-unit id="i-create-the-file-contening">
<source>(I )create the file :filename containing:</source>
<target></target>
Expand Down
4 changes: 4 additions & 0 deletions i18n/fr.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@
<source><![CDATA[output should not be:]]></source>
<target><![CDATA[la sortie ne devrait pas être égale à :]]></target>
</trans-unit>
<trans-unit id="print-output">
<source><![CDATA[print output]]></source>
<target><![CDATA[afficher la sortie]]></target>
</trans-unit>
<trans-unit id="i-create-the-file-contening">
<source><![CDATA[(I )create the file :filename containing:]]></source>
<target><![CDATA[(je )crée le fichier :filename contenant :]]></target>
Expand Down
12 changes: 12 additions & 0 deletions src/Context/SystemContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function iExecute($cmd)
{
$start = microtime(true);

$this->output = [];

exec($cmd, $this->output, $this->lastReturnCode);

$this->lastExecutionTime = microtime(true) - $start;
Expand All @@ -70,6 +72,7 @@ public function iExecuteFromProjectRoot($cmd)
*/
public function commandShouldSucceed() {
if ($this->lastReturnCode !== 0) {
$this->printOutput();
throw new \Exception(sprintf("Command should succeed %b", $this->lastReturnCode));
};
}
Expand All @@ -81,6 +84,7 @@ public function commandShouldSucceed() {
*/
public function commandShouldFail() {
if ($this->lastReturnCode === 0) {
$this->printOutput();
throw new \Exception(sprintf("Command should fail %b", $this->lastReturnCode));
};
}
Expand Down Expand Up @@ -180,6 +184,14 @@ public function outputShouldNotBe(PyStringNode $string)
}
}

/**
* @Then print output
*/
public function printOutput()
{
echo implode("\n", $this->output);
}

/**
* @Given (I )create the file :filename containing:
* @Given (I )create the file :filename contening:
Expand Down
14 changes: 14 additions & 0 deletions tests/features/fr/system.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ Fonctionnalité:
Étant donné j'exécute "false"
Alors la commande planter

@fail
Scénario:
Étant donné j'exécute "ls behat.yml.dist; false"
Alors la commande devrait réussir

@fail
Scénario:
Étant donné j'exécute "ls behat.yml.dist;"
Alors la commande planter

Scénario:
Étant donné j'exécute "sleep 1"
Alors la commande devrait durer moins de 2 secondes
Expand Down Expand Up @@ -34,6 +44,10 @@ Fonctionnalité:
How are you?
"""

Scénario: Debug
Étant donné j'exécute "echo 'Hello world\nHow are you?'"
Alors afficher la sortie

Scénario:
Étant donné j'exécute "bin/behat --help"

Expand Down
14 changes: 14 additions & 0 deletions tests/features/system.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ Feature: System feature
Given I execute "false"
Then command should fail

@fail
Scenario: Fail
Given I execute "ls behat.yml.dist; false"
Then command should succeed

@fail
Scenario: Fail
Given I execute "ls behat.yml.dist"
Then command should fail

Scenario: Testing execution time
Given I execute "sleep 1"
Then Command should last less than 2 seconds
Expand Down Expand Up @@ -33,6 +43,10 @@ Feature: System feature
How are you?
"""

Scenario: Debug
Given I execute "echo 'Hello world\nHow are you?'"
Then print output

Scenario: Testing execution from the project root
Given I execute "bin/behat --help"

Expand Down