预先提交脚本不使用-c开关

时间:2016-03-10 15:32:41

标签: git shell unit-testing vagrant pre-commit-hook

我正在运行以下预提交脚本,存储为.git/hooks/pre-commit

#!/bin/bash

echo "RUNNING UNIT TESTS PRIOR TO COMMIT..."
cd vagrant
RESULT=eval vagrant ssh -c "php /var/www/html/vendor/bin/phpunit -c /var/www/html/app/tests /var/www/html/app/tests"

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

if [ $? -eq 0 ]
then
  printf "${GREEN}Tests Passed!${NC}"
  exit 0
else
  printf "${RED}Tests failed!${NC}"
  exit 1
fi

测试在git commit -m "test message"时运行,具有以下内容(假设我有一个失败的单元测试)

*****@CSL***:~/close-call/closecall/app$ git commit -m "TEST COMMIT"
RUNNING UNIT TESTS PRIOR TO COMMIT...
PHPUnit 5.0.10 by Sebastian Bergmann and contributors.

E..............................                                   31 / 31 (100%)

Time: 551 ms, Memory: 6.00Mb

There was 1 error:

1) CloseCall\CategoryCollectionTest::test_IsCalled
Argument 1 passed to CloseCall\CategoryCollection::__construct() must be an instance of CloseCall\DataAccess\CategoryCollection, instance of Mock_CategoryCollection_61b28cbf given, called in /var/www/html/app/tests/library/CloseCall/CategoryCollectionTest.php on line 32 and defined

/var/www/html/app/library/CloseCall/CategoryCollection.php:8
/var/www/html/app/tests/library/CloseCall/CategoryCollectionTest.php:32
/var/www/html/app/tests/library/CloseCall/CategoryCollectionTest.php:26

FAILURES!
Tests: 31, Assertions: 59, Errors: 1.
Tests Passed![develop 6bb5b2c] TEST COMMIT

但是,它总是传递if [ $? -eq 0]条件,应检查返回的错误代码是否等于0.如果有任何测试,则不应该<0>等于0失败。

知道为什么即使我的测试失败,它给我的错误代码为0($?)?

0 个答案:

没有答案