chsrc/test/cli.pl

91 lines
2.9 KiB
Perl
Raw Normal View History

2024-06-05 13:09:08 +08:00
#!/usr/bin/env perl
# ---------------------------------------------------------------
2024-09-04 19:19:21 +08:00
# Test File : cli.pl
# Test Authors : Aoran Zeng <ccmywish@qq.com>
# Created On : <2024-06-05>
# Last Modified : <2024-09-04>
2024-06-05 13:09:08 +08:00
#
# 测试 chsrc 可执行文件
# ---------------------------------------------------------------
use v5.38;
use Test::More;
2024-09-04 19:47:06 +08:00
my $version_str = qr|chsrc .*\nCopyright .*\nLicense GPLv3\+: GNU GPL version 3 or later|;
2024-09-04 19:19:21 +08:00
like `./chsrc -v`, $version_str, 'chsrc -v';
like `./chsrc --version`, $version_str, 'chsrc --version';
like `./chsrc version`, $version_str, 'chsrc version';
2024-06-05 13:09:08 +08:00
2024-09-04 19:19:21 +08:00
my $help_str = qr/^(help|list|get|set)/m;
like `./chsrc -h`, $help_str, 'chsrc -h';
like `./chsrc --help`, $help_str, 'chsrc --help';
like `./chsrc help`, $help_str, 'chsrc help';
like `./chsrc`, $help_str, 'chsrc';
2024-06-05 13:09:08 +08:00
=begin
测试 chsrc list
=cut
2024-09-04 19:47:06 +08:00
my $list_str = qr/mirrorz\s*MirrorZ\s*.*\ntuna\s*TUNA/;
2024-09-04 19:19:21 +08:00
like `./chsrc ls`, $list_str, 'chsrc ls';
like `./chsrc list mirrors`, $list_str, 'chsrc list mirrors';
like `./chsrc list os`, qr/debian\s*ubuntu/, 'chsrc list os';
like `./chsrc list ware`, qr/brew\s*homebrew/, 'chsrc list ware';
2024-06-05 13:09:08 +08:00
=begin
测试 chsrc get
=cut
2024-09-04 19:19:21 +08:00
my $get_null = qr/chsrc: 请您提供想要查看源的目标名/;
like `./chsrc get -no-color 2>&1`, $get_null, 'chsrc get -no-color';
my $fake_target_name = qr/暂不支持的换源目标/;
like `./chsrc get fake_target_name 2>&1`, $fake_target_name, 'chsrc get fake_target_name';
2024-09-04 19:48:19 +08:00
if ($ARGV[0] eq 'fastcheck') {
say "Fast checking, done testing.";
done_testing;
exit 0;
}
2024-09-04 19:47:06 +08:00
my $has_ruby = system 'ruby1 -v';
if ($has_ruby == 0) {
say "Ruby exists. Go on testing.";
} else {
say "No Ruby. End testing.";
done_testing;
exit 0;
}
2024-09-04 19:19:21 +08:00
my $get_ruby = qr/gem sources/;
like `./chsrc get ruby`, $get_ruby, 'chsrc get ruby';
2024-06-05 13:09:08 +08:00
=begin
2024-09-04 19:19:21 +08:00
测试 chsrc measure
2024-06-05 13:09:08 +08:00
=cut
2024-09-04 19:19:21 +08:00
my $measure_ruby = qr/ - Ruby China/;
like `./chsrc measure ruby`, $measure_ruby, 'chsrc measure ruby';
2024-06-05 13:09:08 +08:00
=begin
2024-06-05 15:12:55 +08:00
测试 chsrc set 以及 chsrc reset
2024-06-05 13:09:08 +08:00
=cut
2024-09-04 19:47:06 +08:00
my $set_ruby_abcd = qr/镜像站.*不存在/;
my $set_ruby_first = qr/全自动换源完成, 感谢镜像提供方/;
my $set_ruby = qr/全自动换源完成, 感谢镜像提供方/;
my $reset_ruby = qr/将重置为上游默认源.*Upstream/s;
my $set_ruby_rubychina = qr/Ruby China 社区/;
my $set_ruby_locally = qr/bundle config --local/;
like `./chsrc set ruby abcd 2>&1`, $set_ruby_abcd, 'chsrc set ruby abcd';
like `./chsrc set ruby first`, $set_ruby_first, 'chsrc set ruby first';
like `./chsrc set ruby`, $set_ruby, 'chsrc set ruby';
like `./chsrc reset ruby`, $reset_ruby, 'chsrc reset ruby';
like `./chsrc set ruby rubychina`, $set_ruby_rubychina, 'chsrc set ruby rubychina';
like `./chsrc set -local ruby first`, $set_ruby_locally, 'chsrc set -local ruby first';
2024-06-05 13:09:08 +08:00
2024-09-04 19:19:21 +08:00
2024-06-05 13:09:08 +08:00
done_testing;