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

Fix std.math.cast, std.ChildProcess, tests on Windows and enable Windows in CI #496

Merged
merged 5 commits into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ jobs:
- name: Build
run: zig build

# ZLS Tests currently fail on windows? Once they are passing and kept up to date, this can be enabled everywhere
- name: Run Tests
if: ${{ matrix.os == 'ubuntu-latest' }}
run: zig build test

- name: Build artifacts
Expand Down
2 changes: 2 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ pub fn build(b: *std.build.Builder) !void {

var unit_tests = b.addTest("src/unit_tests.zig");
unit_tests.setBuildMode(.Debug);
unit_tests.setTarget(target);
test_step.dependOn(&unit_tests.step);

var session_tests = b.addTest("tests/sessions.zig");
session_tests.addPackage(.{ .name = "header", .source = .{ .path = "src/header.zig" } });
session_tests.setBuildMode(.Debug);
session_tests.setTarget(target);
test_step.dependOn(&session_tests.step);
}
5 changes: 2 additions & 3 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1454,8 +1454,7 @@ fn formattingHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
return try respondGeneric(id, null_result_response);
};

var process = try std.ChildProcess.init(&[_][]const u8{ zig_exe_path, "fmt", "--stdin" }, allocator);
defer process.deinit();
var process = std.ChildProcess.init(&[_][]const u8{ zig_exe_path, "fmt", "--stdin" }, allocator);
process.stdin_behavior = .Pipe;
process.stdout_behavior = .Pipe;

Expand Down Expand Up @@ -1656,7 +1655,7 @@ pub fn main() anyerror!void {
// Check arguments.
var args_it = try std.process.ArgIterator.initWithAllocator(allocator);
defer args_it.deinit();
if(!args_it.skip()) @panic("Could not find self argument");
if (!args_it.skip()) @panic("Could not find self argument");

var config_path: ?[]const u8 = null;
var next_arg_config_path = false;
Expand Down
4 changes: 2 additions & 2 deletions src/requests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ fn fromDynamicTreeInternal(arena: *std.heap.ArenaAllocator, value: std.json.Valu
if (value != .Integer) return error.MalformedJson;
out.* = std.meta.intToEnum(
T,
std.math.cast(TagType, value.Integer) catch return error.MalformedJson,
std.math.cast(TagType, value.Integer) orelse return error.MalformedJson,
) catch return error.MalformedJson;
} else if (comptime std.meta.trait.is(.Int)(T)) {
if (value != .Integer) return error.MalformedJson;
out.* = std.math.cast(T, value.Integer) catch return error.MalformedJson;
out.* = std.math.cast(T, value.Integer) orelse return error.MalformedJson;
} else switch (T) {
bool => {
if (value != .Bool) return error.MalformedJson;
Expand Down
39 changes: 21 additions & 18 deletions tests/sessions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const initialize_msg_offs =
;

const Server = struct {
process: *std.ChildProcess,
process: std.ChildProcess,
request_id: u32 = 1,

fn start(initialization: []const u8, expect: ?[]const u8) !Server {
Expand Down Expand Up @@ -103,12 +103,11 @@ const Server = struct {
// FIXME this shutdown request fails with a broken pipe on stdin on the CI
self.request("shutdown", "{}", null) catch @panic("Could not send shutdown request");
// waitNoError(self.process) catch @panic("Server error");
self.process.deinit();
}
};

fn startZls() !*std.ChildProcess {
var process = try std.ChildProcess.init(&[_][]const u8{"zig-out/bin/zls" ++ suffix}, allocator);
fn startZls() !std.ChildProcess {
var process = std.ChildProcess.init(&[_][]const u8{"zig-out/bin/zls" ++ suffix}, allocator);
process.stdin_behavior = .Pipe;
process.stdout_behavior = .Pipe;
process.stderr_behavior = .Inherit;
Expand Down Expand Up @@ -155,10 +154,10 @@ test "Open file, ask for semantic tokens" {
defer server.shutdown();

try server.request("textDocument/didOpen",
\\{"textDocument":{"uri":"file://./tests/test.zig","languageId":"zig","version":420,"text":"const std = @import(\"std\");"}}
\\{"textDocument":{"uri":"file:///test.zig","languageId":"zig","version":420,"text":"const std = @import(\"std\");"}}
, null);
try server.request("textDocument/semanticTokens/full",
\\{"textDocument":{"uri":"file://./tests/test.zig"}}
\\{"textDocument":{"uri":"file:///test.zig"}}
,
\\{"data":[0,0,5,7,0,0,6,3,0,33,0,4,1,11,0,0,2,7,12,0,0,8,5,9,0]}
);
Expand Down Expand Up @@ -218,19 +217,23 @@ test "Self-referential definition" {
\\{"isIncomplete":false,"items":[{"label":"h","kind":21,"textEdit":null,"filterText":null,"insertText":"h","insertTextFormat":1,"detail":"const h = h(0)","documentation":null}]}
);
}
test "Missing return type" {
var server = try Server.start(initialize_msg, null);
defer server.shutdown();

try server.request("textDocument/didOpen",
\\{"textDocument":{"uri":"file:///test.zig","languageId":"zig","version":420,"text":"fn w() {}\nc"}}
, null);
try server.request("textDocument/completion",
\\{"textDocument":{"uri":"file:///test.zig"}, "position":{"line":1,"character":1}}
,
\\{"isIncomplete":false,"items":[{"label":"w","kind":3,"textEdit":null,"filterText":null,"insertText":"w","insertTextFormat":1,"detail":"fn","documentation":null}]}
);
}
// This test as written depends on the configuration in the *host* machines zls.json, if `enable_snippets` is true then
// the insert text is "w()" if it is false it is "w"
//
// test "Missing return type" {
// var server = try Server.start(initialize_msg, null);
// defer server.shutdown();

// try server.request("textDocument/didOpen",
// \\{"textDocument":{"uri":"file:///test.zig","languageId":"zig","version":420,"text":"fn w() {}\nc"}}
// , null);
// try server.request("textDocument/completion",
// \\{"textDocument":{"uri":"file:///test.zig"}, "position":{"line":1,"character":1}}
// ,
// \\{"isIncomplete":false,"items":[{"label":"w","kind":3,"textEdit":null,"filterText":null,"insertText":"w","insertTextFormat":1,"detail":"fn","documentation":null}]}
// );
// }

test "Pointer and optional deref" {
var server = try Server.start(initialize_msg, null);
Expand Down