Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin self-tests #178

Merged
merged 264 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
264 commits
Select commit Hold shift + click to select a range
9174c22
Merge branch 'master' into onlinetests
zorael Jun 7, 2020
9bd4a44
Fix SASL being attempted with no password
zorael Jun 7, 2020
78305dc
Tester: fix kameloso.plugins.common.delayawait import
zorael Jun 7, 2020
3b29102
More work on tester
zorael Jun 7, 2020
5917190
Merge branch 'master' into onlinetests
zorael Aug 24, 2020
47f7cd3
Add tests for Counter and Stopwatch
zorael Aug 24, 2020
75ad598
Nested awaitReply, expect functions
zorael Aug 24, 2020
5fcb4f6
Use "nickname: command" form in Counter, Stopwatch tests
zorael Aug 24, 2020
b6b9f09
Comments, whitespace
zorael Aug 24, 2020
d6bffec
Fix expect/enforce string replacement syntax error
zorael Aug 24, 2020
91bf795
Miscellaneous tester fixes and improvements
zorael Aug 24, 2020
fda0808
counter: "counter enabled" -> "counter available"
zorael Aug 24, 2020
ffe2e14
tester: Make functions out of changing colours
zorael Aug 24, 2020
7312abf
Merge branch 'master' into onlinetests
zorael Sep 14, 2020
beb952c
Fix FTBFS
zorael Sep 14, 2020
650a59a
Merge branch 'master' into onlinetests
zorael Oct 10, 2020
bf5f928
un-ref some IRCEvent parameters on handlers with Fibers
zorael Oct 10, 2020
1db01f8
fix tester compilation and use
zorael Oct 10, 2020
29903b7
Some more un-refs
zorael Oct 10, 2020
a71389d
Increase tester Fiber stack sizes
zorael Oct 10, 2020
1a56874
Further increase tester Fiber stack sizes
zorael Oct 10, 2020
c0ee2f7
Fix tester counter test
zorael Oct 10, 2020
49bce68
Attmept to increase stack size further
zorael Oct 10, 2020
ba714a8
Counter test fix 2
zorael Oct 10, 2020
463a6ad
Merge branch 'master' into onlinetests
zorael Oct 26, 2020
a124270
Merge branch 'master' into onlinetests
zorael Oct 27, 2020
e02c358
Merge branch 'master' into onlinetests
zorael Nov 23, 2020
ff192b6
Improve Tester plugin
zorael Nov 24, 2020
1949a28
Improve tester plugin further
zorael Nov 24, 2020
790f628
Merge branch 'master' into onlinetests
zorael Dec 19, 2020
130f991
tester: PrivilegeLevel -> PermissionsRequired
zorael Dec 19, 2020
73f9f82
Don't verbosely delay after SSL connect failure
zorael Dec 19, 2020
67e6d33
Don't assert(0) after SSL connect failure
zorael Dec 19, 2020
693681f
Properly delay between tester runs
zorael Dec 19, 2020
07a1183
Warn on dmd non-debug builds
zorael Dec 19, 2020
8fef1f9
Merge branch 'master' into onlinetests
zorael Dec 19, 2020
3b92165
Merge branch 'master' into onlinetests
zorael Dec 31, 2020
f860304
WHOISFiberDelegate: fail if no account and recent WHOIS
zorael Jan 1, 2021
4f9f22a
Tweak WHOISFiberDelegate onFailure texts
zorael Jan 1, 2021
8c4d944
quotes: Add missing punctuation
zorael Jan 1, 2021
31c4592
quotes: Add BotCommand alias mergequote
zorael Jan 1, 2021
5789640
quotes: plurality of number of quotes merged
zorael Jan 1, 2021
47b05a1
tester: Update quotes tests
zorael Jan 1, 2021
78b6712
oneliners: Fix "made lowercase" text to apply correctly
zorael Jan 1, 2021
5f40fb3
tester: Centralise printing success/failure
zorael Jan 1, 2021
195fd57
Merge branch 'master' into onlinetests
zorael Jan 5, 2021
defc403
Merge branch 'master' into onlinetests
zorael Jan 6, 2021
af65859
admin: Improve !hostmask usage hints
zorael Jan 6, 2021
497ca63
delay and await parameter order and default values
zorael Jan 8, 2021
0103c7a
tester: update use of await and delay
zorael Jan 8, 2021
dcc08a8
tester: don't test admin as much
zorael Jan 8, 2021
67ea29c
Merge branch 'master' into onlinetests
zorael Jan 21, 2021
e4cc347
Fix tester with new Duration delay
zorael Jan 21, 2021
ac6b0fe
Merge branch 'master' into onlinetests
zorael Jan 21, 2021
492c033
Linebreak some ctor signatures
zorael Jan 23, 2021
6fa4e0b
Revert "bool onEvent; return whether something was done"
zorael Jan 23, 2021
5c1e45c
Revert "Don't process replays/repeats/timeds/awaits if noop"
zorael Jan 23, 2021
96c03cd
Revert "twitch: Update custom onEvent to return bool"
zorael Jan 23, 2021
e6c4c7a
Merge branch 'master' into onlinetests
zorael Jan 30, 2021
0f00cd3
ExplainRepeat: strip "kameloso.plugins." prefix
zorael Jan 30, 2021
6567e9f
ExplainRepeat: strip "kameloso.plugins." when refusing too
zorael Jan 30, 2021
3a2279d
Add missing import
zorael Jan 30, 2021
3bef3c4
Merge branch 'master' into onlinetests
zorael Jan 31, 2021
a67f49b
Merge branch 'master' into onlinetests
zorael Feb 7, 2022
8f60801
Bring tester plugin up to speed
zorael Feb 7, 2022
e22813d
Tester tweaks
zorael Feb 7, 2022
5148263
Merge branch 'process2' into onlinetests
zorael Feb 12, 2022
bcb2312
tester: Don't version the plugin behind WithPlugins
zorael Feb 12, 2022
d53591c
Merge branch 'wrap' into onlinetests
zorael Feb 21, 2022
2c6d5e4
Merge branch 'master' into onlinetests
zorael Mar 10, 2022
839354d
Initialise settings in pipereader so as not to segfault
zorael Mar 10, 2022
319ec82
Update tester to work with coloured input
zorael Mar 10, 2022
af0b73c
Merge branch 'master' into onlinetests
zorael Mar 13, 2022
a9476d7
Merge branch 'master' into onlinetests
zorael Mar 13, 2022
48ecaea
Initial work on online tester
zorael May 5, 2020
bfc3f9b
Simplify Admin online tests
zorael May 5, 2020
f1c38a6
Further work on online tests
zorael May 5, 2020
22738eb
Further further work on online tests
zorael May 5, 2020
47ecc7e
Update use of awaitEvents and unlist
zorael May 5, 2020
2b5272d
Further further further work on online tests
zorael May 6, 2020
6104a7a
Tester: fix kameloso.plugins.common.delayawait import
zorael Jun 7, 2020
cc5d4bb
More work on tester
zorael Jun 7, 2020
61b42f0
Add tests for Counter and Stopwatch
zorael Aug 24, 2020
7cca2c2
Nested awaitReply, expect functions
zorael Aug 24, 2020
c8e1b15
Use "nickname: command" form in Counter, Stopwatch tests
zorael Aug 24, 2020
bb7c6d3
Comments, whitespace
zorael Aug 24, 2020
9966b38
Fix expect/enforce string replacement syntax error
zorael Aug 24, 2020
f856758
Miscellaneous tester fixes and improvements
zorael Aug 24, 2020
5e1d8dd
tester: Make functions out of changing colours
zorael Aug 24, 2020
ed25a1f
Fix FTBFS
zorael Sep 14, 2020
541b603
fix tester compilation and use
zorael Oct 10, 2020
b7215b3
Increase tester Fiber stack sizes
zorael Oct 10, 2020
a6e4d4c
Further increase tester Fiber stack sizes
zorael Oct 10, 2020
bde1ac2
Fix tester counter test
zorael Oct 10, 2020
e5383e0
Attmept to increase stack size further
zorael Oct 10, 2020
debb355
Counter test fix 2
zorael Oct 10, 2020
66aaf3a
Improve Tester plugin
zorael Nov 24, 2020
92350af
Improve tester plugin further
zorael Nov 24, 2020
82b39f2
tester: PrivilegeLevel -> PermissionsRequired
zorael Dec 19, 2020
c846d4f
Don't assert(0) after SSL connect failure
zorael Dec 19, 2020
4c86e09
Properly delay between tester runs
zorael Dec 19, 2020
e7c5ca4
Warn on dmd non-debug builds
zorael Dec 19, 2020
4d415dc
quotes: plurality of number of quotes merged
zorael Jan 1, 2021
dbc84cb
tester: Update quotes tests
zorael Jan 1, 2021
da731f7
tester: Centralise printing success/failure
zorael Jan 1, 2021
3a2165f
delay and await parameter order and default values
zorael Jan 8, 2021
0a452a2
tester: update use of await and delay
zorael Jan 8, 2021
d10f478
tester: don't test admin as much
zorael Jan 8, 2021
c171b6a
Fix tester with new Duration delay
zorael Jan 21, 2021
6c4b9c0
Bring tester plugin up to speed
zorael Feb 7, 2022
5bd572c
Tester tweaks
zorael Feb 7, 2022
55be164
tester: Don't version the plugin behind WithPlugins
zorael Feb 12, 2022
79e5ef4
Update tester to work with coloured input
zorael Mar 10, 2022
67fee88
onCommandTest: Take IRCEvent by value
zorael Mar 20, 2022
405bec6
Tester plugin refactor
zorael Mar 20, 2022
366f620
Merge branch 'onlinetests' of github.com:zorael/kameloso into onlinet…
zorael Apr 5, 2022
b4a2c67
Fix unreachable code error
zorael Apr 5, 2022
8e6f7d0
Merge branch 'master' into onlinetests
zorael Apr 17, 2022
7d6aaf5
Don't test for counter.wordAloneIncrements
zorael Apr 17, 2022
b0e66cd
Merge branch 'master' into onlinetests
zorael May 9, 2022
2b49c07
Revert "onliners: Suggest `!oneliner new` if missing oneliner"
zorael May 9, 2022
a176940
Better bold hinting of `!command [verb]`
zorael May 9, 2022
5eda9fb
oneliners: Append to end if add index too high
zorael May 9, 2022
13630a1
timer: Remove `!timer` verb "clear"
zorael May 9, 2022
c1de4e4
oneliners: Update `!oneliner add` confirmation message
zorael May 9, 2022
495276f
tester: Use a do-while to yield once
zorael May 9, 2022
42d580c
tester: Fix oneliners test, bring up to speed
zorael May 9, 2022
4777673
tester: Fix counter test, new usage text
zorael May 9, 2022
6b712c2
tester: Add timer tests
zorael May 9, 2022
62bf920
Merge branch 'master' into onlinetests
zorael Jun 11, 2022
173f1de
Merge branch 'master' into onlinetests
zorael Jun 13, 2022
417afe6
Fix half-finished merge
zorael Jun 13, 2022
46b04cc
oneliners: Reset ordered position on inserting line
zorael Jun 13, 2022
7c683ca
tester: Bring tests up to speed
zorael Jun 13, 2022
84e9d3e
tester: try-catch tests to get exception messages
zorael Jun 13, 2022
d9ca0e2
Merge branch 'master' into onlinetests
zorael Sep 20, 2022
9f60d34
Merge branch 'elevated' into onlinetests
zorael Sep 20, 2022
5c42673
tester: Remove returns in `scope(failure)` guards
zorael Sep 20, 2022
a634c10
twitch: Fix keygen warning on non-Twitch servers
zorael Sep 20, 2022
e8dcf94
tester tweaks
zorael Sep 20, 2022
4155228
admin: Avoid stack corruption in `onCommandSet`
zorael Sep 20, 2022
7c4a148
Merge branch 'master' into onlinetests
zorael Oct 23, 2022
132a413
Improve error message on `ModulePluginName` failure
zorael Oct 23, 2022
ad699bc
Fix admin classifier commands
zorael Oct 23, 2022
d68eefd
Fix oneliner management responses
zorael Oct 23, 2022
80ebfc0
Fix tester, bring it up to speed
zorael Oct 23, 2022
dce81f6
Merge branch 'master' into onlinetests
zorael Dec 24, 2022
52d3b38
Remove miscommitted things
zorael Dec 24, 2022
93acc7e
Update online tester to use module registration
zorael Dec 24, 2022
61c0924
tester: Test the Time plugin
zorael Dec 24, 2022
a8cf65b
quotes: Add some nickname validity checks
zorael Dec 24, 2022
af285d5
quotes: Fix quote-merging
zorael Dec 24, 2022
cd80d8e
quotes: Use `ptrdiff_t` for given indexes
zorael Dec 24, 2022
9d8e625
quotes: Tweak chat output
zorael Dec 24, 2022
107325d
tester: Quotes test fixes
zorael Dec 24, 2022
18ac273
Merge branch 'master' into onlinetests
zorael Dec 25, 2022
fdb24ee
quotes: overhaul
zorael Dec 25, 2022
f1d9211
tester: Update Quotes tests
zorael Dec 25, 2022
6fded5d
Merge branch 'master' into onlinetests
zorael Dec 28, 2022
1554355
Merge branch 'notes2' into onlinetests
zorael Dec 28, 2022
4322626
tester: bring Notes tests up to speed
zorael Dec 28, 2022
17d0941
Merge branch 'notes2' into onlinetests
zorael Dec 29, 2022
125f6e1
Merge branch 'master' into onlinetests
zorael Jan 1, 2023
33f4871
Bring tester up to speed
zorael Jan 1, 2023
ed62f70
Merge branch 'timers-ng2' into onlinetests
zorael Jan 5, 2023
7494761
Merge branch 'master' into onlinetests
zorael Jan 6, 2023
b334ab9
poll: Only remove a current poll if its ID matches
zorael Jan 6, 2023
1fb0345
tester: fixes
zorael Jan 6, 2023
4db3692
timer: Add an octothorpe in front of edited timer number
zorael Jan 6, 2023
8275e46
Merge branch 'master' into onlinetests
zorael Jan 7, 2023
14284a2
tester: tweaks
zorael Jan 7, 2023
c90f4ec
Merge branch 'master' into onlinetests
zorael Jan 9, 2023
b523542
printer: `randomNickColours` -> `colourfulNicknames`
zorael Jan 9, 2023
61df63d
bash: Give better error if server seems down
zorael Jan 9, 2023
a8a3b7e
tester: Gracefully handle bash.org being down
zorael Jan 9, 2023
8eabc58
CIs: ignore tester branch
zorael Jan 9, 2023
6961a99
Merge branch 'master' into onlinetests
zorael Jan 27, 2023
12d411d
tester: Update tester cases
zorael Jan 27, 2023
361f724
tester: Disable Bash tests for now
zorael Jan 27, 2023
ff120c7
Merge branch 'master' into onlinetests
zorael Jan 31, 2023
4d76c1f
chatbot: Update module level ddoc
zorael Jan 31, 2023
e7abd03
Fix tester plugin registration
zorael Jan 31, 2023
b63d6aa
Merge branch 'master' into onlinetests
zorael Jan 31, 2023
8ea465f
Rename `HandleDelegates` -> `PeekGetSet`
zorael Jan 31, 2023
8bbf7cc
Merge branch 'master' into onlinetests
zorael Feb 9, 2023
49f0a60
tester: Fixes
zorael Feb 9, 2023
9054865
Merge branch 'master' into onlinetests
zorael Feb 10, 2023
6c796a7
Merge branch 'master' into onlinetests
zorael Feb 12, 2023
e3fd72e
Merge branch 'master' into onlinetests
zorael Jun 28, 2023
a08c4bc
Merge branch 'master' into onlinetests
zorael Jun 28, 2023
f9253c7
tester: Re-enable !bash tester
zorael Jun 28, 2023
926690a
Merge branch 'master' into onlinetests
zorael Jun 28, 2023
e280da4
Merge branch 'master' into onlinetests
zorael Jul 11, 2023
1a17f49
tester: print failed test names
zorael Jul 11, 2023
586392a
tester: Fix outdated bash and automode expected responses
zorael Jul 11, 2023
acb388d
Merge branch 'master' into onlinetests
zorael Aug 19, 2023
8af21a2
Don't prepend "base64:" to pass/password if empty
zorael Aug 19, 2023
40b26d3
Revert "Reuse IRCEvent.time in messageFiber.eventToServer"
zorael Aug 20, 2023
47875aa
Make throttling correct
zorael Aug 21, 2023
4f393f6
cosmetics: variable names, comments
zorael Aug 21, 2023
6afbd12
onEventImpl: move a scopeguard to a higher scope
zorael Aug 21, 2023
f3c29b2
twitch: Return true on early initialise return
zorael Aug 21, 2023
969fcb6
tester: Fix "notes" now being "note"
zorael Aug 21, 2023
4a8ce3a
Merge branch 'master' into onlinetests
zorael Aug 21, 2023
2fb0b5a
Remove duplicate bash plugin error
zorael Aug 21, 2023
6b41ab1
Merge branch 'master' into onlinetests
zorael Dec 9, 2023
78029c4
Bring up to speed with modern lu
zorael Dec 9, 2023
ea89568
Disable testing of Bash plugin
zorael Dec 9, 2023
11a4485
Merge branch 'master' into onlinetests
zorael Dec 17, 2023
5de69ac
Fix some null dereferences under certain conditions
zorael Dec 17, 2023
1d51095
Merge branch 'master' into onlinetests
zorael Dec 17, 2023
4bfb118
Fix some null dereferences under certain conditions
zorael Dec 17, 2023
88f5faa
Merge branch 'master' into onlinetests
zorael Dec 17, 2023
23e2cde
Merge branch 'master' into onlinetests
zorael Dec 17, 2023
1e3eeaa
Merge branch 'master' into onlinetests
zorael Dec 22, 2023
ac47e56
Bring tester up to speed again
zorael Dec 22, 2023
527819d
Merge branch 'master' into onlinetests
zorael Dec 23, 2023
00d9059
Merge branch 'master' into onlinetests
zorael Dec 24, 2023
8d6ee15
Merge branch 'master' into onlinetests
zorael Jan 6, 2024
ac46825
Avoid a superfluous AA.keys() call
zorael Jan 6, 2024
9ce7a56
Merge branch 'master' into onlinetests
zorael Jan 12, 2024
69f2df2
counter: Use abs(step) in increment/decrement messages
zorael Jan 12, 2024
da2708f
oneliner: Only give !counter add notice if >= operator
zorael Jan 12, 2024
549896f
oneliner: Mention whether deleted oneliner was an alias
zorael Jan 12, 2024
aabde16
timer: Reset timer message count/timestamp on modification
zorael Jan 12, 2024
a3bc6c8
Bring tester up to date
zorael Jan 12, 2024
33a4861
Merge branch 'master' into onlinetests
zorael Jan 14, 2024
e54cdb7
Merge branch 'master' into onlinetests
zorael Jan 19, 2024
3203f14
Add a subcontext member to class DeferredAction
zorael Jan 20, 2024
7b0c5c0
Add groundwork for plugin selftests
zorael Jan 20, 2024
e02ea34
admin: Add command k:selftest
zorael Jan 20, 2024
2a68f39
admin: Add self-tests
zorael Jan 21, 2024
a4de91a
automode: Add self-tests
zorael Jan 21, 2024
258d8cb
bash: Add self-tests
zorael Jan 21, 2024
1ed2a60
chatbot: Add self-tests
zorael Jan 21, 2024
5ee80de
counter: Add self-tests
zorael Jan 21, 2024
a2ecbf1
note: Add self-tests
zorael Jan 21, 2024
1431873
oneliner: Add self-tests
zorael Jan 21, 2024
ff64fd4
poll: Add self-tests
zorael Jan 21, 2024
290009f
quote: Add self-tests
zorael Jan 21, 2024
16b0d87
sedreplace: Add self-tests
zorael Jan 21, 2024
559b1a7
stopwatch: Add self-tests
zorael Jan 21, 2024
04c28f8
time: Add self-tests
zorael Jan 21, 2024
6e5d2c5
timer: Add self-tests
zorael Jan 21, 2024
9b93794
Delete tester.d
zorael Jan 21, 2024
0077319
dub.sdl: Add configuration `selftest`
zorael Jan 21, 2024
402fed3
Catch delay caller and embed into ScheduledFiber as creator
zorael Jan 21, 2024
f692391
bash: Fix parsing of (some) multiline quotes
zorael Jan 21, 2024
2471c12
cosmetics: ddoc, comments
zorael Jan 21, 2024
dc99589
Ward against null fibers in processScheduledFibers
zorael Jan 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,35 @@ configuration "dev-lowmem" {
//"TraceHTTPRequests" \
}

configuration "selftest" {
subConfiguration "dialect" "dev"

versions \
"Selftests" \
"Debug" \
"TwitchSupport" \
"WithTwitchPlugin" \
"PrintStacktraces" \
"ExplainReplay" \
"GCStatsOnExit" \
"IncludeHeavyStuff"
}

configuration "selftest-lowmem" {
subConfiguration "dialect" "dev"
dflags "-lowmem"

versions \
"Selftests" \
"Debug" \
"TwitchSupport" \
"WithTwitchPlugin" \
"PrintStacktraces" \
"ExplainReplay" \
"GCStatsOnExit" \
"IncludeHeavyStuff"
}

configuration "unittest" {
targetName "kameloso-test"
subConfiguration "dialect" "dev"
Expand Down
80 changes: 76 additions & 4 deletions source/kameloso/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,8 @@ in ((nowInHnsecs > 0), "Tried to process queued `ScheduledFiber`s with an unset
}
}

if (scheduledFiber.fiber.state == Fiber.State.HOLD)
if (scheduledFiber.fiber &&
(scheduledFiber.fiber.state == Fiber.State.HOLD))
{
scheduledFiber.fiber.call();
}
Expand Down Expand Up @@ -2296,6 +2297,7 @@ version(WithAdminPlugin)
{
version = WantGetSettingHandler;
version = WantSetSettingHandler;
version = WantSelftestHandler;
}

version(WithHelpPlugin)
Expand Down Expand Up @@ -2387,7 +2389,7 @@ void processDeferredActions(Kameloso instance, IRCPlugin plugin)
fiber.payload[0] = globalCommandAA;
fiber.payload[1] = channelCommandAA;
fiber.call(action.creator);
continue;
continue top;
}
}

Expand Down Expand Up @@ -2492,7 +2494,7 @@ void processDeferredActions(Kameloso instance, IRCPlugin plugin)
fiber.call(action.creator);
break;
}
continue;
continue top;
}
}

Expand All @@ -2513,7 +2515,77 @@ void processDeferredActions(Kameloso instance, IRCPlugin plugin)

fiber.payload[0] = success;
fiber.call(action.creator);
continue;
continue top;
}
}

version(Selftests)
version(WantSelftestHandler)
{
import kameloso.plugins.common : Selftester;

alias SelftestPayload = Tuple!(string[], string[], string[]);

if (auto fiber = cast(CarryingFiber!(SelftestPayload))(action.fiber))
{
import kameloso.constants : BufferSize;

void selftestDg()
{
import lu.string : advancePast;
import std.algorithm.searching : canFind;
import std.array : split;

Selftester tester;
tester.fiber = cast(CarryingFiber!IRCEvent)Fiber.getThis();
tester.channelName = action.context;

string slice = action.subcontext; // mutable
tester.targetNickname = slice.advancePast(' ', Yes.inherit);
const pluginNames = slice.split(' ');

foreach (immutable i, thisPlugin; instance.plugins)
{
import kameloso.plugins.common.scheduling : await, delay, unawait;
import std.typecons : Ternary;

if (!thisPlugin.isEnabled ||
(pluginNames.length && !pluginNames.canFind(thisPlugin.name)))
{
fiber.payload[2] ~= thisPlugin.name;
continue;
}

await(thisPlugin, tester.fiber, IRCEvent.Type.CHAN);
scope(exit) unawait(thisPlugin, tester.fiber, IRCEvent.Type.CHAN);

immutable result = thisPlugin.selftest(tester);

if (result == Ternary.yes)
{
enum pattern = "Self-test of the <l>%s</> plugin succeeded.";
logger.infof(pattern, thisPlugin.name);
fiber.payload[0] ~= thisPlugin.name;
}
else if (result == Ternary.no)
{
enum pattern = "Self-test of the <l>%s</> plugin FAILED.";
logger.warningf(pattern, thisPlugin.name);
fiber.payload[1] ~= thisPlugin.name;
}
else /*if (result == Ternary.unknown)*/
{
fiber.payload[2] ~= thisPlugin.name;
//continue;
}
}

fiber.call(action.creator);
}

auto selftestFiber = new CarryingFiber!IRCEvent(&selftestDg, BufferSize.fiberStack);
selftestFiber.call(action.creator);
continue top;
}
}

Expand Down
209 changes: 209 additions & 0 deletions source/kameloso/plugins/admin/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,84 @@ void onCommandBus(AdminPlugin plugin, const ref IRCEvent event)
}


// onCommandSelftest
/++
Performs self-tests against another bot.
+/
version(Selftests)
@(IRCEventHandler()
.onEvent(IRCEvent.Type.CHAN)
.permissionsRequired(Permissions.admin)
.channelPolicy(ChannelPolicy.home)
.fiber(true)
.addCommand(
IRCEventHandler.Command()
.word("selftest")
.policy(PrefixPolicy.nickname)
.description("Performs self-tests against another bot.")
.addSyntax("$command [target nickname] [optional plugin name(s)]")
)
)
void onCommandSelftest(AdminPlugin plugin, const /*ref*/ IRCEvent event)
{
import kameloso.thread : CarryingFiber;
import std.format : format;
import std.typecons : Tuple;

alias Payload = Tuple!(string[], string[], string[]);

void selftestDg()
{
auto thisFiber = cast(CarryingFiber!Payload)Fiber.getThis();
assert(thisFiber, "Incorrectly cast fiber: " ~ typeof(thisFiber).stringof);

privmsg(plugin.state, event.channel, event.sender.nickname, "Self-tests complete.");

if (thisFiber.payload[0].length)
{
enum successPattern = "Succeeded (<b>%d<b>): %-(<b>%s<b>, %)<b>";
immutable successMessage = successPattern.format(
thisFiber.payload[0].length,
thisFiber.payload[0]);
privmsg(plugin.state, event.channel, event.sender.nickname, successMessage);
}

if (thisFiber.payload[1].length)
{
enum failurePattern = "Failed (<b>%d<b>): %-(<b>%s<b>, %)<b>";
immutable failureMessage = failurePattern.format(
thisFiber.payload[1].length,
thisFiber.payload[1]);
privmsg(plugin.state, event.channel, event.sender.nickname, failureMessage);
}

if (thisFiber.payload[2].length)
{
import lu.string : plurality;
enum skippedPattern = "<b>%d<b> %s skipped.";
immutable skippedMessage = skippedPattern.format(
thisFiber.payload[2].length,
thisFiber.payload[2].length.plurality("plugin", "plugins"));
privmsg(plugin.state, event.channel, event.sender.nickname, skippedMessage);
}
}

if (!event.content.length)
{
enum pattern = "Usage: %s%s [target nickname] [optional plugin name(s)]";
immutable message = pattern.format(
plugin.state.settings.prefix,
event.aux[0]);
chan(plugin.state, event.channel, message);
return;
}

enum message = "Running self-tests. This may take several minutes.";
privmsg(plugin.state, event.channel, event.sender.nickname, message);
defer!Payload(plugin, &selftestDg, event.channel, event.content);
}


// parseTypesFromString
/++
Modifies [AdminPlugin.eventTypesToPrint|eventTypesToPrint] based on a string
Expand Down Expand Up @@ -1925,6 +2003,137 @@ void onBusMessage(
}


// selftest
/++
Performs self-tests against another bot.
+/
version(Selftests)
auto selftest(AdminPlugin _, Selftester s)
{
import std.range : only;

// ------------ home, guest

s.send("home del #harpsteff");
s.expect("Channel #harpsteff was not listed as a home channel.");

s.send("home add #harpsteff");
s.expect("Home channel added.");

s.send("home add #harpsteff");
s.expect("We are already in that home channel.");

s.send("home del #harpsteff");
s.expect("Home channel removed.");

s.send("home del #harpsteff");
s.expect("Channel #harpsteff was not listed as a home channel.");

s.send("guest add #BLIRPBLARP");
s.expect("Guest channel added.");

s.send("guest del #BLIRPBLARP");
s.expect("Guest channel removed.");

// ------------ lists

foreach (immutable list; only("staff"))//, "operator", "elevated", "whitelist", "blacklist"))
{
immutable definiteFormSingular =
(list == "staff") ? "staff" :
(list == "operator") ? "an operator" :
(list == "elevated") ? "an elevated user" :
(list == "whitelist") ? "a whitelisted user" :
/*(list == "blacklist") ?*/ "a blacklisted user";

immutable plural =
(list == "staff") ? "staff" :
(list == "operator") ? "operators" :
(list == "elevated") ? "elevated users" :
(list == "whitelist") ? "whitelisted users" :
/*(list == "blacklist") ?*/ "blacklisted users";

s.send(list ~ " del xorael");
s.expect("xorael isn't " ~ definiteFormSingular ~ " in ${channel}.");

s.send(list ~ " add xorael");
s.expect("Added xorael as " ~ definiteFormSingular ~ " in ${channel}.");

s.send(list ~ " add xorael");
s.expect("xorael was already " ~ definiteFormSingular ~ " in ${channel}.");

s.send(list ~ " list");
s.expect("Current " ~ plural ~ " in ${channel}: xorael");

s.send(list ~ " del xorael");
s.expect("Removed xorael as " ~ definiteFormSingular ~ " in ${channel}.");

s.send(list ~ " list");
s.expect("There are no " ~ plural ~ " in ${channel}.");

s.send(list ~ " add");
s.expect("No nickname supplied.");
}

// ------------ misc

s.send("cycle #flirrp");
s.expect("I am not in that channel.");

// ------------ hostmasks

s.send("hostmask");
s.awaitReply();

enum noHostmaskMessage = "This bot is not currently configured " ~
"to use hostmasks for authentication.";

if (s.lastMessage != noHostmaskMessage)
{
s.send("hostmask add");
s.expect("Usage: !hostmask [add|del|list] ([account] [hostmask]/[hostmask])");

s.send("hostmask add kameloso HIRF#%%!SNIR@sdasdasd");
s.expect("Invalid hostmask.");

s.send("hostmask add kameloso kameloso^!*@*");
s.expect("Hostmask list updated.");

s.send("hostmask list");
// `Current hostmasks: ["kameloso^!*@*":"kameloso"]`);
s.expectInBody(`"kameloso^!*@*":"kameloso"`);

s.send("hostmask del kameloso^!*@*");
s.expect("Hostmask list updated.");

s.send("hostmask del kameloso^!*@*");
s.expect("No such hostmask on file.");
}

// ------------ misc

s.send("reload");
s.expect("Reloading plugins.");

s.send("reload admin");
s.expect("Reloading plugin \"admin\".");

s.send("join #skabalooba");
s.send("part #skabalooba");

s.send("get admin.enabled");
s.expect("admin.enabled=true");

s.send("get core.prefix");
s.expect(`core.prefix="${prefix}"`);

s.send("sudo PRIVMSG ${channel} :hello world");
s.expect("hello world");

return true;
}


mixin UserAwareness!omniscientChannelPolicy;
mixin ChannelAwareness!omniscientChannelPolicy;
mixin PluginRegistration!(AdminPlugin, -4.priority);
Expand Down
Loading