php - Bash Not Continuing after script call? -
i have 2 bash scripts. 1 runs fine till reaches call script, executes script fine never ever continues in original script , not sure how= fix issue.
this script, runs tests in each folder of specific directory. each sub folder contains phpunit.xml file , when enter each folder run composer install
, phpunit
.
should directory be, loader, routes or loop, enter , run script in side directory.
lets @ run-tests
script:
#!/usr/bin/env bash set -e function run_tests() { if [[ -f "composer.json" ]] && [[ -f "phpunit.xml" ]]; if [[ -d "vendor" ]]; composer update phpunit > /dev/null phpunit cd ../ else composer install phpunit > /dev/null phpunit cd ../ fi else cd ../ fi } f in *; if [[ -d $f ]]; if [[ $f != ".git" ]] && [[ $f != "bin" ]] && [[ $f != "docs" ]]; cd "$f/" if [[ $f == "loader" ]]; if [[ -d "assets" ]]; cd assets/ chmod +x asset-test ./asset-test fi fi if [[ $f == "loop" ]]; cd loop/ chmod +x loop-test ./loop-test cd ../ fi if [[ $f == "routes" ]]; cd routes/ chmod +x routes-test ./routes-test cd ../ fi run_tests fi fi done # go home. cd /vagrant/freya/ ## clean time! ## remove vendor , composer.lock folders - because. f in *; if [[ -d $f ]]; if [[ $f != ".git" ]] && [[ $f != "bin" ]] && [[ $f != "docs" ]]; cd "$f/" rm -rf vendor composer.lock cd ../ fi fi done
we can see once enter check see if directory in "loops", check if there directory called "assets" inside. assuming passes, enter directory , run next script:
#!/usr/bin/env bash set -e # run composer install if vendor doesnt exist. if [[ -d "vendor" ]]; composer update else composer install fi # move root directories , wordpress cd ../../../ # determine if trunk checked out , if have wp-test-config.php # if not need create both or 1 or other run tests. # # run phpunit twice because second time when runs. if [[ -d "trunk" ]]; cd "trunk/" if [[ -f "wp-tests-config.php" ]]; cd ../freya/loader/assets phpunit > /dev/null phpunit else cd ../freya/loader/assets cp wp-tests-config.php ../../trunk/ phpunit > /dev/null phpunit fi else sudo svn co http://develop.svn.wordpress.org/trunk/ cd freya/loader/assets cp wp-tests-config.php ../../trunk/ phpunit > /dev/null phpunit fi
the issue once script finishes, rest of first script posted never continues. dies here. need "parent" script finish, should out of loader/assets
, continue on next check. doesn't. script exists.
why?
note: in second script can assume goes first nested if statement, checks, in trunk directory wp-tests-config.php
can assume because of following output, captured running first script:
$ bin/run-tests loading composer repositories package information installing dependencies (including require-dev) nothing install or update writing lock file generating autoload files phpunit 4.6.4 sebastian bergmann , contributors. configuration read /vagrant/freya/exceptions/phpunit.xml . time: 451 ms, memory: 13.25mb ok (1 test, 1 assertion) loading composer repositories package information installing dependencies (including require-dev) nothing install or update writing lock file generating autoload files phpunit 4.6.4 sebastian bergmann , contributors. configuration read /vagrant/freya/factory/phpunit.xml ........... time: 711 ms, memory: 13.25mb ok (11 tests, 11 assertions) loading composer repositories package information installing dependencies (including require-dev) - installing freya/freya-templates (dev-master a33ecdb) cloning a33ecdb231b06dc8a7eef363edb177b8c134d55b writing lock file generating autoload files phpunit 4.6.4 sebastian bergmann , contributors. configuration read /vagrant/freya/form/phpunit.xml ............................................................... time: 647 ms, memory: 15.25mb ok (63 tests, 63 assertions) loading composer repositories package information updating dependencies (including require-dev) nothing install or update generating autoload files installing... running single site... run multisite, use -c tests/phpunit/multisite.xml not running ajax tests. execute these, use --group ajax. not running ms-files tests. execute these, use --group ms-files. not running external-http tests. execute these, use --group external-http. phpunit 4.6.4 sebastian bergmann , contributors. configuration read /vagrant/freya/loader/assets/phpunit.xml ........... time: 1.76 seconds, memory: 38.00mb ok (11 tests, 11 assertions) loading composer repositories package information updating dependencies (including require-dev) nothing install or update generating autoload files installing... running single site... run multisite, use -c tests/phpunit/multisite.xml not running ajax tests. execute these, use --group ajax. not running ms-files tests. execute these, use --group ms-files. not running external-http tests. execute these, use --group external-http. phpunit 4.6.4 sebastian bergmann , contributors. configuration read /vagrant/freya/loader/assets/phpunit.xml ........... time: 1.79 seconds, memory: 38.00mb
we can see 2 issues here:
- the
/vagrant/freya/loader/assets/
run twice. - it never continues on in first script.
it difficult debug remotely without set on machine. more helpful answers, try isolate problem first successively disabling parts of code. can see may difficult in scenario.
here few thoughts debugging:
- both scripts run
set -e
, i.e. exit on first command (including second script) terminating non-zero exit code . try addingset -x
see last commands executed. - you have lot of relative
cd
calls. trypwd
before last command identified in previous step - may in wrong directory.
Comments
Post a Comment