mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
testing: add LogFilter utility for scoped log suppression
This commit is contained in:
@@ -3457,6 +3457,9 @@ fn asUint(comptime string: anytype) std.meta.Int(
|
|||||||
|
|
||||||
const testing = @import("../testing.zig");
|
const testing = @import("../testing.zig");
|
||||||
test "WebApi: Page" {
|
test "WebApi: Page" {
|
||||||
|
const filter: testing.LogFilter = .init(.http);
|
||||||
|
defer filter.deinit();
|
||||||
|
|
||||||
try testing.htmlRunner("page", .{});
|
try testing.htmlRunner("page", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -662,6 +662,10 @@ test "cdp.page: getFrameTree" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "cdp.page: captureScreenshot" {
|
test "cdp.page: captureScreenshot" {
|
||||||
|
const LogFilter = @import("../../testing.zig").LogFilter;
|
||||||
|
const filter: LogFilter = .init(.not_implemented);
|
||||||
|
defer filter.deinit();
|
||||||
|
|
||||||
var ctx = testing.context();
|
var ctx = testing.context();
|
||||||
defer ctx.deinit();
|
defer ctx.deinit();
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -133,9 +133,8 @@ test "MCP.router - handleMessage - synchronous unit tests" {
|
|||||||
|
|
||||||
// 4. Parse error
|
// 4. Parse error
|
||||||
{
|
{
|
||||||
const old_filter = log.opts.filter_scopes;
|
const filter: testing.LogFilter = .init(.mcp);
|
||||||
log.opts.filter_scopes = &.{.mcp};
|
defer filter.deinit();
|
||||||
defer log.opts.filter_scopes = old_filter;
|
|
||||||
|
|
||||||
try handleMessage(server, aa, "invalid json");
|
try handleMessage(server, aa, "invalid json");
|
||||||
try testing.expectJson("{\"id\": null, \"error\": {\"code\": -32700}}", out_alloc.writer.buffered());
|
try testing.expectJson("{\"id\": null, \"error\": {\"code\": -32700}}", out_alloc.writer.buffered());
|
||||||
|
|||||||
@@ -610,3 +610,23 @@ fn testHTTPHandler(req: *std.http.Server.Request) !void {
|
|||||||
|
|
||||||
unreachable;
|
unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// LogFilter provides a scoped way to suppress specific log categories during tests.
|
||||||
|
/// This is useful for tests that trigger expected errors or warnings.
|
||||||
|
pub const LogFilter = struct {
|
||||||
|
old_filter: []const log.Scope,
|
||||||
|
|
||||||
|
/// Sets the log filter to only include the specified scope.
|
||||||
|
/// Returns a LogFilter that should be deinitialized to restore previous filters.
|
||||||
|
pub fn init(comptime scope: log.Scope) LogFilter {
|
||||||
|
const old_filter = log.opts.filter_scopes;
|
||||||
|
const new_filter = comptime &[_]log.Scope{scope};
|
||||||
|
log.opts.filter_scopes = new_filter;
|
||||||
|
return .{ .old_filter = old_filter };
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Restores the log filters to their previous state.
|
||||||
|
pub fn deinit(self: LogFilter) void {
|
||||||
|
log.opts.filter_scopes = self.old_filter;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user