【发布时间】:2015-04-29 07:37:47
【问题描述】:
我有两个 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
我们可以看到,一旦进入检查我们所在的目录是否是“Loops”,我们再检查里面是否有一个名为“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/运行两次。 - 它永远不会在第一个脚本中继续。
【问题讨论】:
-
尝试发布一个最小的示例,因为大多数人不愿意通读所有这些内容,因此您不太可能得到答案。
-
JID++。而且您可能会发现,在将脚本压缩成最小示例的过程中,您自己发现了问题!