Debian Codegraph @

test/core/test_miquire_plugin.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 require File.expand_path(__dir__+'/../helper')
4
5 require 'miquire_plugin'
6
7 Miquire::Plugin.loadpath << File.join(__dir__, "miquire/plugin")
8
9 class TC_MiquirePlugin < Test::Unit::TestCase
10 def setup
11 Plugin.clear!
12 end
13
14 def teardown
15 Delayer.run while not Delayer.empty?
16 end
17
18 must "to_hash return all spec" do
19 hash = Miquire::Plugin.to_hash
20 assert_equal :standalone, hash[:standalone][:slug]
21 end
22
23 must "get plugin slug by path (spec exist)" do
24 assert_equal(:standalone, Miquire::Plugin.get_slug(File.expand_path(File.join(__dir__, 'miquire/standalone'))))
25 assert_equal(:parent_not_found, Miquire::Plugin.get_slug(File.expand_path(File.join(__dir__, 'miquire/parent_not_found'))))
26 assert_equal(:tooold, Miquire::Plugin.get_slug(File.expand_path(File.join(__dir__, 'miquire/tooold'))))
27 end
28
29 must "get plugin slug by plugin path" do
30 assert_equal(:standalone, Miquire::Plugin.get_slug(File.expand_path(File.join(__dir__, 'miquire/standalone'))),
31 "spec がないとき slug が取得できる")
32 assert_equal(:not_exist, Miquire::Plugin.get_slug(File.expand_path(File.join(__dir__, 'miquire/not_exist'))),
33 "plugin が存在しないとき slug が取得できる")
34 assert_equal(:display_requirements, Miquire::Plugin.get_slug(File.expand_path(File.join(__dir__, 'miquire/display_requirements.rb'))),
35 "plugin が一つの.rbファイルだけの時 slug が取得できる")
36 end
37
38 must "get spec by plugin path" do
39 standalone = Miquire::Plugin.get_spec(File.expand_path(File.join(__dir__, 'miquire/plugin/standalone')))
40 not_exist = Miquire::Plugin.get_spec(File.expand_path(File.join(__dir__, 'miquire/plugin/not_exist')))
41 display_requirements = Miquire::Plugin.get_spec(File.expand_path(File.join(__dir__, 'miquire/plugin/display_requirements.rb')))
42
43 assert_kind_of(Hash, standalone,
44 "spec file がないとき plugin があれば spec を取得できる")
45 assert_equal(:standalone, standalone[:slug],
46 "spec file がないとき plugin があれば spec を取得できる")
47 assert_nil(not_exist,
48 "plugin がないときは slug を取得できない")
49 assert_kind_of(Hash, display_requirements,
50 "plugin ファイルが単一の時、 spec を取得できる")
51 assert_equal(:display_requirements, display_requirements[:slug],
52 "plugin ファイルが単一の時、 spec を取得できる")
53 end
54
55 must "get spec by plugin slug" do
56 standalone = Miquire::Plugin.get_spec_by_slug(:standalone)
57 not_exist = Miquire::Plugin.get_spec_by_slug(:not_exist)
58 display_requirements = Miquire::Plugin.get_spec_by_slug(:display_requirements)
59
60 assert_kind_of(Hash, standalone,
61 "spec file がないとき plugin があれば spec を取得できる")
62 assert_equal(:standalone, standalone[:slug],
63 "spec file がないとき plugin があれば spec を取得できる")
64 assert_nil(not_exist,
65 "plugin がないときは slug を取得できない")
66 assert_kind_of(Hash, display_requirements,
67 "plugin ファイルが単一の時、 spec を取得できる")
68 assert_equal(:display_requirements, display_requirements[:slug],
69 "plugin ファイルが単一の時、 spec を取得できる")
70 end
71
72 must "load plugin by symbol" do
73 assert(Miquire::Plugin.load(:standalone),
74 "プラグインがロードできる")
75 assert(Plugin.instance_exist?(:standalone), "プラグインがロードできる")
76 assert_equal(false, Miquire::Plugin.load(:not_exist), "存在しないプラグインはロードできない")
77 end
78
79 must "load plugin by slug" do
80 assert(Miquire::Plugin.load(Miquire::Plugin.get_spec_by_slug(:standalone)),
81 "プラグインがロードできる")
82 assert(Plugin.instance_exist?(:standalone), "プラグインがロードできる")
83 refute(Miquire::Plugin.load(Miquire::Plugin.get_spec_by_slug(:not_exist)), "存在しないプラグインはロードできない")
84 end
85
86 must "load child plugin with parent" do
87 assert(Miquire::Plugin.load(:child),
88 "依存関係のあるプラグインをロードできる")
89 assert(Plugin.instance_exist?(:child), "依存のあるプラグインをロードできる")
90 assert(Plugin.instance_exist?(:parent), "依存されているプラグインも自動でロードされる")
91 end
92
93 must "load error depended plugin not exists." do
94 assert_raise(Miquire::LoadError, "依存しているプラグインがない場合ロードに失敗する") {
95 Miquire::Plugin.load(:parent_not_found)
96 }
97 assert(!Plugin.instance_exist?(:parent_not_found), "依存しているプラグインがない場合ロードに失敗する")
98 end
99
100 must "legacy spec file raise warning" do
101 last_notification = {}
102 listener = EventListener.new(Event[:modify_activity]) { |param|
103 last_notification = param }
104 begin
105 assert(Miquire::Plugin.load(:legacyspec),
106 "古いspecファイルをもつプラグインはロードできる")
107 Delayer.run while not Delayer.empty?
108 assert_equal(:legacyspec, last_notification[:plugin], '古いspecファイルをもつプラグインは警告が出る')
109
110 last_notification = nil
111 assert(Miquire::Plugin.load(:child),
112 ".mikutter.ymlファイルをもつプラグインはロードできる")
113 Delayer.run while not Delayer.empty?
114 assert_nil(last_notification, '.mikutter.ymlファイルをもつプラグインは警告が出ない')
115
116 last_notification = nil
117 assert(Miquire::Plugin.load(:standalone),
118 "specファイルをもつプラグインはロードできる")
119 Delayer.run while not Delayer.empty?
120 assert_nil(last_notification, 'specファイルを持たないプラグインは警告が出ない')
121 ensure
122 listener.detach end
123 end
124
125 end