Skip to content

Commit

Permalink
fix enum error test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
rupurt committed Feb 9, 2024
1 parent 702d172 commit fae0bd5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
18 changes: 11 additions & 7 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,25 @@ pub fn build(b: *Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const lib = b.addStaticLibrary(.{
.name = "odbc",
const lib = b.addSharedLibrary(.{
.name = "zigodbc",
.root_source_file = .{ .path = "src/lib.zig" },
.version = .{ .major = 0, .minor = 0, .patch = 0 },
.target = target,
.optimize = optimize,
});

setupOdbcDependencies(lib);

b.installArtifact(lib);

_ = b.addModule("zig-odbc", .{
.root_source_file = .{ .path = "src/lib.zig" },
});

const test_cmd = b.step("test", "Run library tests");
const test_step = b.step("test", "Run library tests");

var tests: [test_files.len]*std.Build.Step.Compile = undefined;
var tests: [test_files.len]*std.Build.Step.Run = undefined;
inline for (test_files, 0..) |item, index| {
const current_tests = b.addTest(.{
.name = item.name,
Expand All @@ -50,10 +53,12 @@ pub fn build(b: *Build) void {

setupOdbcDependencies(current_tests);

tests[index] = current_tests;
const run_current_unit_tests = b.addRunArtifact(current_tests);

tests[index] = run_current_unit_tests;
}
for (tests) |t| {
test_cmd.dependOn(&t.step);
test_step.dependOn(&t.step);
}
}

Expand All @@ -65,6 +70,5 @@ pub fn setupOdbcDependencies(step: *std.Build.Step.Compile) void {
step.addIncludeDir("/usr/local/include");
step.addIncludeDir("/usr/local/lib");
}

step.linkSystemLibrary(odbc_library_name);
}
4 changes: 2 additions & 2 deletions src/statement.zig
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ pub const Statement = struct {
var name_length: c_short = 0;
_ = c.SQLGetCursorName(self.handle, null, 0, &name_length);

var name_buffer = try allocator.allocSentinel(u8, name_length, 0);
const name_buffer = try allocator.allocSentinel(u8, name_length, 0);
errdefer allocator.free(name_buffer);

const result = c.SQLGetCursorName(self.handle, name_buffer.ptr, @as(c_short, @intCast(name_buffer.len)), &name_length);
Expand Down Expand Up @@ -346,7 +346,7 @@ pub const Statement = struct {
if (result_type == .success_with_info) {
// SuccessWithInfo might indicate that only part of the column was retrieved, and in that case we need to
// continue fetching the rest of it. If we're getting long data, SQLGetData will return NoData
var error_buffer: [@sizeOf(odbc_error.SqlState) * 3]u8 = undefined;
const error_buffer: [@sizeOf(odbc_error.SqlState) * 3]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(error_buffer);
const errors = try self.getErrors(&fba.allocator);
for (errors) |err| if (err == .StringRightTrunc) {
Expand Down
5 changes: 1 addition & 4 deletions src/util.zig
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,9 @@ test "bitmask" {

test "enum error" {
const Base = enum { A, B, C };

const BaseError = EnumErrorSet(Base);

try std.testing.expectEqualStrings("A", @typeInfo(BaseError).ErrorSet.?[0].name);
try std.testing.expectEqualStrings("B", @typeInfo(BaseError).ErrorSet.?[1].name);
try std.testing.expectEqualStrings("C", @typeInfo(BaseError).ErrorSet.?[2].name);
try std.testing.expectEqual(BaseError, error{ A, B, C });

// Just making sure everything compiles, that BaseError is accepted in the error
// spot of the return type.
Expand Down

0 comments on commit fae0bd5

Please sign in to comment.