我有两个bash脚本。一个运行完全正常,直到它到达另一个脚本的调用,然后它执行该脚本正常,但从来没有继续在原始脚本中,我不知道如何=解决问题。
此脚本在特定目录的每个文件夹中运行测试。每个子文件夹都包含一个phpunit.xml文件,当我们输入每个文件夹时,我们运行composer install
和phpunit
。
如果目录是,Loader,Routes或Loop,我们将输入这些并在该目录旁边运行脚本。
让我们看一下run-tests
脚本:
#!/usr/bin/env bash
set -e
function run_tests() {
if [[ -f "composer.json" ]] && [[ -f "phpunit.xml" ]]; then
if [[ -d "vendor" ]]; then
composer update
phpunit > /dev/null
phpunit
cd ../
else
composer install
phpunit > /dev/null
phpunit
cd ../
fi
else
cd ../
fi
}
for f in *; do
if [[ -d $f ]]; then
if [[ $f != ".git" ]] && [[ $f != "bin" ]] && [[ $f != "docs" ]]; then
cd "$f/"
if [[ $f == "Loader" ]]; then
if [[ -d "Assets" ]]; then
cd Assets/
chmod +x asset-test
./asset-test
fi
fi
if [[ $f == "Loop" ]]; then
cd Loop/
chmod +x loop-test
./loop-test
cd ../
fi
if [[ $f == "Routes" ]]; then
cd Routes/
chmod +x routes-test
./routes-test
cd ../
fi
run_tests
fi
fi
done
# Go Home.
cd /vagrant/Freya/
## Clean up time!
## Remove all vendor and composer.lock folders - just because.
for f in *; do
if [[ -d $f ]]; then
if [[ $f != ".git" ]] && [[ $f != "bin" ]] && [[ $f != "docs" ]]; then
cd "$f/"
rm -rf vendor composer.lock
cd ../
fi
fi
done
我们可以看到,一旦它进入检查以查看我们所在的目录是否为“循环”,我们就会检查里面是否有一个名为“Assets”的目录。假设这个通过,我们然后进入该目录并运行下一个脚本:
#!/usr/bin/env bash
set -e
# Run Composer Install if vendor doesnt exist.
if [[ -d "vendor" ]]; then
composer update
else
composer install
fi
# Move up to the root directories and then get wordpress
cd ../../../
# Determine if the trunk is checked out and if we have a wp-test-config.php
# If not we need to create both or one or the other then run the tests.
#
# We run phpunit twice because the second time is when it actually runs.
if [[ -d "trunk" ]]; then
cd "trunk/"
if [[ -f "wp-tests-config.php" ]]; then
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
问题是一旦这个脚本完成,我发布的第一个脚本的其余部分永远不会继续。就像它在这里死了一样。我需要的是“父”脚本完成,它应该退出Loader/Assets
并继续下一次检查。但事实并非如此。该脚本存在。
为什么吗
注意:在第二个脚本中,我们可以假设它进入第一个嵌套的if语句,它在中心目录中检查wp-tests-config.php
我们可以假设这是因为以下输出,从运行第一个脚本中捕获:
$ bin/run-tests
Loading composer repositories with package information
Installing dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.
Configuration read from /vagrant/Freya/Exceptions/phpunit.xml
.
Time: 451 ms, Memory: 13.25Mb
OK (1 test, 1 assertion)
Loading composer repositories with package information
Installing dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.
Configuration read from /vagrant/Freya/Factory/phpunit.xml
...........
Time: 711 ms, Memory: 13.25Mb
OK (11 tests, 11 assertions)
Loading composer repositories with 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 by Sebastian Bergmann and contributors.
Configuration read from /vagrant/Freya/Form/phpunit.xml
...............................................................
Time: 647 ms, Memory: 15.25Mb
OK (63 tests, 63 assertions)
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.
Configuration read from /vagrant/Freya/Loader/Assets/phpunit.xml
...........
Time: 1.76 seconds, Memory: 38.00Mb
OK (11 tests, 11 assertions)
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.
Configuration read from /vagrant/Freya/Loader/Assets/phpunit.xml
...........
Time: 1.79 seconds, Memory: 38.00Mb
我们可以在这里看到两个问题:
/vagrant/Freya/Loader/Assets/
会运行两次。答案 0 :(得分:2)
如果没有在您的计算机上设置所有内容,则很难远程调试。有关更有用的答案,您可以尝试通过连续禁用部分代码来隔离问题。我可以看到,在你的场景中这可能很难。
以下是调试的一些想法:
set -e
运行,即它们将在第一个命令(包括第二个脚本)上退出,并以非零退出代码终止。尝试添加set -x
以查看最后执行的命令。cd
来电。在上一步中确定的最后一个命令之前尝试pwd
- 您可能只是在错误的目录中。