Skip to content

Commit 5d00af0

Browse files
authored
test(log): re-enable doc tests for FileHandler (denoland#6321)
1 parent e3dc30a commit 5d00af0

File tree

5 files changed

+47
-90
lines changed

5 files changed

+47
-90
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ codecov.SHA256SUM.sig
1919
.DS_Store
2020
.idea
2121
.vim
22+
_tmp/
23+
!_tmp/.keep

_tmp/.keep

Whitespace-only changes.

_tools/check_docs.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,21 @@ function assertSnippetsWork(
273273
function assertHasExampleTag(
274274
document: { jsDoc: JsDoc; location: Location },
275275
) {
276-
const tags = document.jsDoc.tags?.filter((tag) =>
276+
const exampleTags = document.jsDoc.tags?.filter((tag) =>
277277
tag.kind === "example"
278278
) as JsDocTagDocRequired[];
279-
if (tags === undefined || tags.length === 0) {
279+
const hasNoExampleTags = exampleTags === undefined ||
280+
exampleTags.length === 0;
281+
if (
282+
hasNoExampleTags &&
283+
!document.jsDoc.tags?.some((tag) => tag.kind === "private")
284+
) {
280285
diagnostics.push(
281286
new DocumentError("Symbol must have an @example tag", document),
282287
);
283288
return;
284289
}
285-
for (const tag of tags) {
290+
for (const tag of exampleTags) {
286291
assert(
287292
tag.doc !== undefined,
288293
"@example tag must have a title and TypeScript code snippet",

_tools/check_licence.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const EXCLUDED_DIRS = [
1313
"**/crypto/_wasm/lib",
1414
"**/.git",
1515
"**/docs/**",
16+
"**/_tmp",
1617
];
1718

1819
const ROOT = new URL("../", import.meta.url);

log/file_handler.ts

+36-87
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ export interface FileHandlerOptions extends BaseHandlerOptions {
5252
* This handler requires `--allow-write` permission on the log file.
5353
*
5454
* @example Usage
55-
* ```ts no-assert ignore
55+
* ```ts no-assert
5656
* import { FileHandler } from "@std/log/file-handler";
5757
*
58-
* const handler = new FileHandler("INFO", { filename: "./logs.txt" });
58+
* const handler = new FileHandler("INFO", { filename: "./_tmp/logs.txt" });
5959
* handler.setup();
6060
* handler.log('Hello, world!'); // Buffers the message, or writes it to the file depending on buffer state
6161
* handler.flush(); // Manually flushes the buffer
@@ -64,95 +64,44 @@ export interface FileHandlerOptions extends BaseHandlerOptions {
6464
*/
6565
export class FileHandler extends BaseHandler {
6666
/** Opened file to append logs to.
67-
* @example Usage
68-
* ```ts no-assert ignore
69-
* import { FileHandler } from "@std/log/file-handler";
7067
*
71-
* const handler = new FileHandler("INFO", { filename: "./logs.txt" });
72-
* handler.setup();
73-
* handler.log('Hello, world!'); // Buffers the message, or writes it to the file depending on buffer state
74-
* handler.flush(); // Manually flushes the buffer
75-
* handler.destroy(); // Closes the file and removes listeners
76-
* ```
77-
* **/
68+
* @private
69+
*/
7870
[fileSymbol]: Deno.FsFile | undefined;
7971
/** Buffer used to write to file.
80-
* @example Usage
81-
* ```ts no-assert ignore
82-
* import { FileHandler } from "@std/log/file-handler";
8372
*
84-
* const handler = new FileHandler("INFO", { filename: "./logs.txt" });
85-
* handler.setup();
86-
* handler.log('Hello, world!'); // Buffers the message, or writes it to the file depending on buffer state
87-
* handler.flush(); // Manually flushes the buffer
88-
* handler.destroy(); // Closes the file and removes listeners
89-
* ```
90-
* **/
73+
* @private
74+
*/
9175
[bufSymbol]: Uint8Array;
92-
/** Current position for pointer.
93-
* @example Usage
94-
* ```ts no-assert ignore
95-
* import { FileHandler } from "@std/log/file-handler";
76+
/**
77+
* Current position for pointer.
9678
*
97-
* const handler = new FileHandler("INFO", { filename: "./logs.txt" });
98-
* handler.setup();
99-
* handler.log('Hello, world!'); // Buffers the message, or writes it to the file depending on buffer state
100-
* handler.flush(); // Manually flushes the buffer
101-
* handler.destroy(); // Closes the file and removes listeners
102-
* ```
103-
* **/
79+
* @private
80+
*/
10481
[pointerSymbol] = 0;
105-
/** Filename associated with the file being logged.
106-
* @example Usage
107-
* ```ts no-assert ignore
108-
* import { FileHandler } from "@std/log/file-handler";
82+
/**
83+
* Filename associated with the file being logged.
10984
*
110-
* const handler = new FileHandler("INFO", { filename: "./logs.txt" });
111-
* handler.setup();
112-
* handler.log('Hello, world!'); // Buffers the message, or writes it to the file depending on buffer state
113-
* handler.flush(); // Manually flushes the buffer
114-
* handler.destroy(); // Closes the file and removes listeners
115-
* ```
116-
* **/
85+
* @private
86+
*/
11787
[filenameSymbol]: string;
118-
/** Current log mode.
119-
* @example Usage
120-
* ```ts no-assert ignore
121-
* import { FileHandler } from "@std/log/file-handler";
88+
/**
89+
* Current log mode.
12290
*
123-
* const handler = new FileHandler("INFO", { filename: "./logs.txt" });
124-
* handler.setup();
125-
* handler.log('Hello, world!'); // Buffers the message, or writes it to the file depending on buffer state
126-
* handler.flush(); // Manually flushes the buffer
127-
* handler.destroy(); // Closes the file and removes listeners
128-
* ```
129-
* **/
91+
* @private
92+
*/
13093
[modeSymbol]: LogMode;
131-
/** File open options.
132-
* @example Usage
133-
* ```ts no-assert ignore
134-
* import { FileHandler } from "@std/log/file-handler";
94+
/**
95+
* File open options.
13596
*
136-
* const handler = new FileHandler("INFO", { filename: "./logs.txt" });
137-
* handler.setup();
138-
* handler.log('Hello, world!'); // Buffers the message, or writes it to the file depending on buffer state
139-
* handler.flush(); // Manually flushes the buffer
140-
* handler.destroy(); // Closes the file and removes listeners
141-
* ```
142-
* **/
97+
* @private
98+
*/
14399
[openOptionsSymbol]: Deno.OpenOptions;
144-
/** Text encoder.
145-
* @example Usage
146-
* ```ts no-assert ignore
147-
* import { FileHandler } from "@std/log/file-handler";
100+
/**
101+
* Text encoder.
148102
*
149-
* const handler = new FileHandler("INFO", { filename: "./logs.txt" });
150-
* handler.setup();
151-
* handler.log('Hello, world!'); // Buffers the message, or writes it to the file depending on buffer state
152-
* handler.flush(); // Manually flushes the buffer
153-
* handler.destroy(); // Closes the file and removes listeners
154-
* ```
155-
* **/
103+
* @private
104+
*/
156105
[encoderSymbol]: TextEncoder = new TextEncoder();
157106
#unloadCallback = (() => {
158107
this.destroy();
@@ -183,10 +132,10 @@ export class FileHandler extends BaseHandler {
183132
* Sets up the file handler by opening the specified file and initializing resources.
184133
*
185134
* @example Usage
186-
* ```ts no-assert ignore
135+
* ```ts no-assert
187136
* import { FileHandler } from "@std/log/file-handler";
188137
*
189-
* const handler = new FileHandler("INFO", { filename: "./logs.txt" });
138+
* const handler = new FileHandler("INFO", { filename: "./_tmp/logs.txt" });
190139
* handler.setup(); // Opens the file and prepares the handler for logging.
191140
* handler.destroy();
192141
* ```
@@ -207,13 +156,13 @@ export class FileHandler extends BaseHandler {
207156
* @param logRecord Log record to handle.
208157
*
209158
* @example Usage
210-
* ```ts ignore
159+
* ```ts
211160
* import { FileHandler } from "@std/log/file-handler";
212161
* import { assertInstanceOf } from "@std/assert/instance-of";
213162
* import { LogLevels } from "./levels.ts";
214163
* import { LogRecord } from "./logger.ts";
215164
*
216-
* const handler = new FileHandler("INFO", { filename: "./logs.txt" });
165+
* const handler = new FileHandler("INFO", { filename: "./_tmp/logs.txt" });
217166
* handler.setup();
218167
*
219168
* // Flushes the buffer immediately and logs "CRITICAL This log is very critical indeed." into the file.
@@ -245,11 +194,11 @@ export class FileHandler extends BaseHandler {
245194
* @param msg The message to log.
246195
*
247196
* @example Usage
248-
* ```ts ignore
197+
* ```ts
249198
* import { FileHandler } from "@std/log/file-handler";
250199
* import { assertInstanceOf } from "@std/assert/instance-of";
251200
*
252-
* const handler = new FileHandler("INFO", { filename: "./logs.txt" });
201+
* const handler = new FileHandler("INFO", { filename: "./_tmp/logs.txt" });
253202
* handler.setup();
254203
* handler.log('Hello, world!');
255204
* handler.flush();
@@ -275,11 +224,11 @@ export class FileHandler extends BaseHandler {
275224
* Immediately writes the contents of the buffer to the previously opened file.
276225
*
277226
* @example Usage
278-
* ```ts ignore
227+
* ```ts
279228
* import { FileHandler } from "@std/log/file-handler";
280229
* import { assertInstanceOf } from "@std/assert/instance-of";
281230
*
282-
* const handler = new FileHandler("INFO", { filename: "./logs.txt" });
231+
* const handler = new FileHandler("INFO", { filename: "./_tmp/logs.txt" });
283232
* handler.setup();
284233
* handler.log('Hello, world!');
285234
* handler.flush(); // Writes buffered log messages to the file immediately.
@@ -308,11 +257,11 @@ export class FileHandler extends BaseHandler {
308257
* Destroys the handler, performing any cleanup that is required and closes the file handler.
309258
*
310259
* @example Usage
311-
* ```ts ignore
260+
* ```ts
312261
* import { FileHandler } from "@std/log/file-handler";
313262
* import { assertInstanceOf } from "@std/assert/instance-of";
314263
*
315-
* const handler = new FileHandler("INFO", { filename: "./logs.txt" });
264+
* const handler = new FileHandler("INFO", { filename: "./_tmp/logs.txt" });
316265
* handler.setup();
317266
* handler.destroy();
318267
*

0 commit comments

Comments
 (0)