diff options
author | 2023-08-07 18:51:16 -0700 | |
---|---|---|
committer | 2023-08-07 18:51:16 -0700 | |
commit | f2f227720b3ffe1797a0a4e500e9a9a639167dc6 (patch) | |
tree | a3fab7a9c55775c8bd637161aa2551a7659a21b8 /src/api | |
parent | 0b183beb51367004795d8a431eb06bb2fa4f8250 (diff) | |
download | bun-f2f227720b3ffe1797a0a4e500e9a9a639167dc6.tar.gz bun-f2f227720b3ffe1797a0a4e500e9a9a639167dc6.tar.zst bun-f2f227720b3ffe1797a0a4e500e9a9a639167dc6.zip |
WASM test analyzer (#4043)
* wasm
* WASM test scanner
* Update Makefile
* Update Makefile
* Configurable heap limit
* slightly better error
* Update js_parser.zig
* Update path.test.js
* Update node.mjs
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/schema.d.ts | 32 | ||||
-rw-r--r-- | src/api/schema.js | 110 | ||||
-rw-r--r-- | src/api/schema.peechy | 22 | ||||
-rw-r--r-- | src/api/schema.zig | 83 |
4 files changed, 247 insertions, 0 deletions
diff --git a/src/api/schema.d.ts b/src/api/schema.d.ts index 2a86340ad..a982b910d 100644 --- a/src/api/schema.d.ts +++ b/src/api/schema.d.ts @@ -331,6 +331,16 @@ export const WebsocketCommandKindKeys: { 3: "build_with_file_path"; build_with_file_path: "build_with_file_path"; }; +export const enum TestKind { + test_fn = 1, + describe_fn = 2, +} +export const TestKindKeys: { + 1: "test_fn"; + test_fn: "test_fn"; + 2: "describe_fn"; + describe_fn: "describe_fn"; +}; export interface StackFrame { function_name: string; file: string; @@ -729,6 +739,22 @@ export interface ClientServerModuleManifest { contents: Uint8Array; } +export interface GetTestsRequest { + path: string; + contents: Uint8Array; +} + +export interface TestResponseItem { + byteOffset: int32; + label: StringPointer; + kind: TestKind; +} + +export interface GetTestsResponse { + tests: TestResponseItem[]; + contents: Uint8Array; +} + export declare function encodeStackFrame(message: StackFrame, bb: ByteBuffer): void; export declare function decodeStackFrame(buffer: ByteBuffer): StackFrame; export declare function encodeStackFramePosition(message: StackFramePosition, bb: ByteBuffer): void; @@ -847,3 +873,9 @@ export declare function encodeClientServerModule(message: ClientServerModule, bb export declare function decodeClientServerModule(buffer: ByteBuffer): ClientServerModule; export declare function encodeClientServerModuleManifest(message: ClientServerModuleManifest, bb: ByteBuffer): void; export declare function decodeClientServerModuleManifest(buffer: ByteBuffer): ClientServerModuleManifest; +export declare function encodeGetTestsRequest(message: GetTestsRequest, bb: ByteBuffer): void; +export declare function decodeGetTestsRequest(buffer: ByteBuffer): GetTestsRequest; +export declare function encodeTestResponseItem(message: TestResponseItem, bb: ByteBuffer): void; +export declare function decodeTestResponseItem(buffer: ByteBuffer): TestResponseItem; +export declare function encodeGetTestsResponse(message: GetTestsResponse, bb: ByteBuffer): void; +export declare function decodeGetTestsResponse(buffer: ByteBuffer): GetTestsResponse; diff --git a/src/api/schema.js b/src/api/schema.js index f1e68031e..b28c5669c 100644 --- a/src/api/schema.js +++ b/src/api/schema.js @@ -3315,6 +3315,108 @@ function encodeClientServerModuleManifest(message, bb) { } } +function decodeGetTestsRequest(bb) { + var result = {}; + + result["path"] = bb.readString(); + result["contents"] = bb.readByteArray(); + return result; +} + +function encodeGetTestsRequest(message, bb) { + var value = message["path"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "path"'); + } + + var value = message["contents"]; + if (value != null) { + bb.writeByteArray(value); + } else { + throw new Error('Missing required field "contents"'); + } +} +const TestKind = { + "1": 1, + "2": 2, + "test_fn": 1, + "describe_fn": 2, +}; +const TestKindKeys = { + "1": "test_fn", + "2": "describe_fn", + "test_fn": "test_fn", + "describe_fn": "describe_fn", +}; + +function decodeTestResponseItem(bb) { + var result = {}; + + result["byteOffset"] = bb.readInt32(); + result["label"] = decodeStringPointer(bb); + result["kind"] = TestKind[bb.readByte()]; + return result; +} + +function encodeTestResponseItem(message, bb) { + var value = message["byteOffset"]; + if (value != null) { + bb.writeInt32(value); + } else { + throw new Error('Missing required field "byteOffset"'); + } + + var value = message["label"]; + if (value != null) { + encodeStringPointer(value, bb); + } else { + throw new Error('Missing required field "label"'); + } + + var value = message["kind"]; + if (value != null) { + var encoded = TestKind[value]; + if (encoded === void 0) throw new Error("Invalid value " + JSON.stringify(value) + ' for enum "TestKind"'); + bb.writeByte(encoded); + } else { + throw new Error('Missing required field "kind"'); + } +} + +function decodeGetTestsResponse(bb) { + var result = {}; + + var length = bb.readVarUint(); + var values = (result["tests"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = decodeTestResponseItem(bb); + result["contents"] = bb.readByteArray(); + return result; +} + +function encodeGetTestsResponse(message, bb) { + var value = message["tests"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + encodeTestResponseItem(value, bb); + } + } else { + throw new Error('Missing required field "tests"'); + } + + var value = message["contents"]; + if (value != null) { + bb.writeByteArray(value); + } else { + throw new Error('Missing required field "contents"'); + } +} + export { Loader }; export { LoaderKeys }; export { FrameworkEntryPointType }; @@ -3461,3 +3563,11 @@ export { decodeClientServerModule }; export { encodeClientServerModule }; export { decodeClientServerModuleManifest }; export { encodeClientServerModuleManifest }; +export { decodeGetTestsRequest }; +export { encodeGetTestsRequest }; +export { TestKind }; +export { TestKindKeys }; +export { decodeTestResponseItem }; +export { encodeTestResponseItem }; +export { decodeGetTestsResponse }; +export { encodeGetTestsResponse }; diff --git a/src/api/schema.peechy b/src/api/schema.peechy index a172606f7..53800e4f3 100644 --- a/src/api/schema.peechy +++ b/src/api/schema.peechy @@ -609,3 +609,25 @@ struct ClientServerModuleManifest { StringPointer[] exportNames; byte[] contents; } + + +struct GetTestsRequest { + string path; + byte[] contents; +} + +smol TestKind { + test_fn = 1; + describe_fn = 2; +} + +struct TestResponseItem { + int32 byteOffset; + StringPointer label; + TestKind kind; +} + +struct GetTestsResponse { + TestResponseItem[] tests; + byte[] contents; +}
\ No newline at end of file diff --git a/src/api/schema.zig b/src/api/schema.zig index 94f2d22df..de46a813b 100644 --- a/src/api/schema.zig +++ b/src/api/schema.zig @@ -3140,4 +3140,87 @@ pub const Api = struct { try writer.writeArray(u8, this.contents); } }; + + pub const GetTestsRequest = struct { + /// path + path: []const u8, + + /// contents + contents: []const u8, + + pub fn decode(reader: anytype) anyerror!GetTestsRequest { + var this = std.mem.zeroes(GetTestsRequest); + + this.path = try reader.readValue([]const u8); + this.contents = try reader.readArray(u8); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.path), this.path); + try writer.writeArray(u8, this.contents); + } + }; + + pub const TestKind = enum(u8) { + _none, + /// test_fn + test_fn, + + /// describe_fn + describe_fn, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const TestResponseItem = struct { + /// byteOffset + byte_offset: i32 = 0, + + /// label + label: StringPointer, + + /// kind + kind: TestKind, + + pub fn decode(reader: anytype) anyerror!TestResponseItem { + var this = std.mem.zeroes(TestResponseItem); + + this.byte_offset = try reader.readValue(i32); + this.label = try reader.readValue(StringPointer); + this.kind = try reader.readValue(TestKind); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.byte_offset); + try writer.writeValue(@TypeOf(this.label), this.label); + try writer.writeEnum(this.kind); + } + }; + + pub const GetTestsResponse = struct { + /// tests + tests: []const TestResponseItem, + + /// contents + contents: []const u8, + + pub fn decode(reader: anytype) anyerror!GetTestsResponse { + var this = std.mem.zeroes(GetTestsResponse); + + this.tests = try reader.readArray(TestResponseItem); + this.contents = try reader.readArray(u8); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeArray(TestResponseItem, this.tests); + try writer.writeArray(u8, this.contents); + } + }; }; |