You've already forked qlg.tsgz.moe
addons
app_download_files
extend
hyhproject
mobile
oss
static
thinkphp
upload
vendor
5ini99
composer
oss-sdk
swoole
.github
benchmark
examples
include
src
tests
include
swoole_async
swoole_atomic
swoole_buffer
swoole_channel
swoole_client_async
swoole_client_coro
swoole_client_sync
swoole_coroutine
swoole_coroutine_channel
swoole_coroutine_util
swoole_event
swoole_function
swoole_http2_client
swoole_http2_client_coro
swoole_http_cilent_coro
swoole_http_client
swoole_http_server
swoole_https_client
swoole_lock
swoole_memory_pool
swoole_mysql
swoole_mysql_coro
swoole_process
swoole_redis
swoole_redis_coro
swoole_redis_server
swoole_serialize
swoole_server
swoole_server_port
swoole_socket_coro
swoole_table
swoole_timer
swoole_websocket_server
CONTRIBUTION
README.md
clean
coro_test.sh
new.sh
run-tests
start.sh
template.phpt
test-all-version.sh
test.sql
thirdparty
tools
travis
.gitignore
.gitmodules
.travis.yml
CMakeLists.txt
CREDITS
LICENSE
README.md
Version2.md
build.sh
clear.sh
config.m4
make.sh
package.xml
php7_wrapper.h
php_swoole.h
swoole.c
swoole_async.c
swoole_atomic.c
swoole_buffer.c
swoole_channel.c
swoole_channel_coro.cc
swoole_client.c
swoole_client_coro.c
swoole_config.h
swoole_coroutine.cc
swoole_coroutine.h
swoole_coroutine_util.c
swoole_event.c
swoole_http.h
swoole_http_client.c
swoole_http_client.h
swoole_http_client_coro.c
swoole_http_server.c
swoole_http_v2_client.c
swoole_http_v2_client.h
swoole_http_v2_client_coro.c
swoole_http_v2_server.c
swoole_lock.c
swoole_memory_pool.c
swoole_mmap.c
swoole_msgqueue.c
swoole_mysql.c
swoole_mysql.h
swoole_mysql_coro.c
swoole_postgresql_coro.c
swoole_postgresql_coro.h
swoole_process.c
swoole_process_pool.c
swoole_redis.c
swoole_redis_coro.c
swoole_redis_server.c
swoole_ringqueue.c
swoole_runtime.cc
swoole_serialize.c
swoole_serialize.h
swoole_server.c
swoole_server_port.c
swoole_socket_coro.c
swoole_table.c
swoole_timer.c
swoole_trace.c
swoole_websocket_server.c
wechat
.htaccess
autoload.php
wxtmp
.gitignore
.htaccess
.user.ini
404.html
H5B854518.wgt
admin.php
app-release.apk
app_download.html
cash.lock
demo.php
get_startup.php
get_version.php
get_version_new.php
hyhproject.tar.gz
index.html
index.php
reg.lock
robots.txt
113 lines
3.3 KiB
Bash
Executable File
113 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
define('SWOOLE_COLOR_RED', 1);
|
|
define('SWOOLE_COLOR_GREEN', 2);
|
|
define('SWOOLE_COLOR_YELLOW', 3);
|
|
define('SWOOLE_COLOR_BLUE', 4);
|
|
define('SWOOLE_COLOR_MAGENTA', 5);
|
|
define('SWOOLE_COLOR_CYAN', 6);
|
|
define('SWOOLE_COLOR_WHITE', 7);
|
|
function swoole_color(string $content, int $color): string
|
|
{
|
|
return "\033[3{$color}m{$content}\033[0m";
|
|
}
|
|
|
|
function fgetsin(string $tip = '', bool $accept_empty = true): string
|
|
{
|
|
do {
|
|
if ($tip) {
|
|
echo "$tip: ";
|
|
}
|
|
$in = trim(fgets(STDIN));
|
|
} while (!$accept_empty && $in === '');
|
|
|
|
return $in;
|
|
}
|
|
|
|
function yes(string $content = ''): bool
|
|
{
|
|
echo $content;
|
|
return fgetsin() === 'y';
|
|
}
|
|
|
|
if (empty($argv[1])) {
|
|
error_filename:
|
|
exit(
|
|
swoole_color("Please enter the correct file name or path! e.g.:", SWOOLE_COLOR_RED) .
|
|
swoole_color("\n\"./new.sh ./swoole_coroutine\"\n", SWOOLE_COLOR_MAGENTA)
|
|
);
|
|
}
|
|
|
|
$filename = $argv[1];
|
|
if (!pathinfo($filename, PATHINFO_EXTENSION)) {
|
|
$path = ['dirname' => $filename];
|
|
} else {
|
|
$path = pathinfo($filename);
|
|
}
|
|
$path['dirname'] = trim($path['dirname'], './'); // i know arg2 is a list but it's no problem
|
|
|
|
$replacement = [];
|
|
$tip = swoole_color("[Test name]: ", SWOOLE_COLOR_BLUE);
|
|
$replacement['test_name'] = fgetsin($tip, false);
|
|
$tip = swoole_color("[Test intro]: ", SWOOLE_COLOR_BLUE);
|
|
$replacement['test_intro'] = fgetsin($tip);
|
|
|
|
if (empty($path['filename'])) {
|
|
$path['filename'] = $replacement['test_name']; // use test name to be filename
|
|
}
|
|
$filename = "{$path['dirname']}/{$path['filename']}.phpt";
|
|
|
|
//if dir not exist, create it
|
|
if (!is_dir(__DIR__ . "/{$path['dirname']}")) {
|
|
echo swoole_color(
|
|
"The dir [{$path['dirname']}] is not exist, if you want to create it? [y/n]: ",
|
|
SWOOLE_COLOR_YELLOW
|
|
);
|
|
if (yes()) {
|
|
mkdir($path['dirname'], 0755, true);
|
|
} else {
|
|
exit(swoole_color('Can\'t generate the test file in nonexistent dir!', SWOOLE_COLOR_RED));
|
|
}
|
|
} elseif (file_exists($filename)) {
|
|
echo swoole_color("The file [{$path['filename']}] is exist, if you want to overwrite it? [y/n]: ", SWOOLE_COLOR_YELLOW);
|
|
if (!yes()) {
|
|
exit(swoole_color('You should rename your test filename.', SWOOLE_COLOR_RED));
|
|
}
|
|
}
|
|
|
|
//calc dir deep
|
|
$deep = 0;
|
|
$temp = $filename;
|
|
while (($temp = dirname($temp)) !== '.') {
|
|
$deep++;
|
|
}
|
|
if ($deep < 1) {
|
|
goto error_filename;
|
|
}
|
|
|
|
$template = file_get_contents(__DIR__ . '/template.phpt');
|
|
$replacement['dir_deep'] = str_repeat('/..', $deep);
|
|
foreach ($replacement as $key => $value) {
|
|
$template = str_replace("{{{$key}}}", $value, $template);
|
|
}
|
|
|
|
if (file_put_contents($filename, $template)) {
|
|
echo swoole_color("Generate the test file successfully!\n", SWOOLE_COLOR_GREEN) .
|
|
"[" . __DIR__ . "/$filename]";
|
|
@shell_exec('/usr/bin/env git add ' . __DIR__ . "/$filename");
|
|
if (\stripos(PHP_OS, 'Darwin') !== false) {
|
|
//MacOS
|
|
$pstorm = '/usr/local/bin/pstorm';
|
|
if (file_exists($pstorm) || (
|
|
file_exists('/Applications/PhpStorm.app') &&
|
|
file_put_contents($pstorm, file_get_contents(__DIR__ . '/include/macos/phpstorm.py')) &&
|
|
chmod($pstorm, 0744)
|
|
)
|
|
) {
|
|
@shell_exec("/usr/local/bin/phpstorm {$filename}");
|
|
}
|
|
}
|
|
} else {
|
|
exit("\nGenerate the test file failed!");
|
|
}
|