diff options
| author | 2022-08-15 21:53:02 +0200 | |
|---|---|---|
| committer | 2022-09-18 20:11:36 +0200 | |
| commit | 91d1afe0f6aae9e0d20f6380b85c4ff840cef120 (patch) | |
| tree | 9aded3b0b8066c5d7d2b6fdf07b521730e60b936 /sqlite.zig | |
| parent | move setFunctionArgument to helpers.setTypeFromValue (diff) | |
| download | zig-sqlite-91d1afe0f6aae9e0d20f6380b85c4ff840cef120.tar.gz zig-sqlite-91d1afe0f6aae9e0d20f6380b85c4ff840cef120.tar.xz zig-sqlite-91d1afe0f6aae9e0d20f6380b85c4ff840cef120.zip | |
move test helpers
Diffstat (limited to 'sqlite.zig')
| -rw-r--r-- | sqlite.zig | 45 |
1 files changed, 1 insertions, 44 deletions
| @@ -19,6 +19,7 @@ pub const DetailedError = errors.DetailedError; | |||
| 19 | const getLastDetailedErrorFromDb = errors.getLastDetailedErrorFromDb; | 19 | const getLastDetailedErrorFromDb = errors.getLastDetailedErrorFromDb; |
| 20 | const getDetailedErrorFromResultCode = errors.getDetailedErrorFromResultCode; | 20 | const getDetailedErrorFromResultCode = errors.getDetailedErrorFromResultCode; |
| 21 | 21 | ||
| 22 | const getTestDb = @import("test.zig").getTestDb; | ||
| 22 | const helpers = @import("helpers.zig"); | 23 | const helpers = @import("helpers.zig"); |
| 23 | 24 | ||
| 24 | const logger = std.log.scoped(.sqlite); | 25 | const logger = std.log.scoped(.sqlite); |
| @@ -3301,50 +3302,6 @@ test "sqlite: two nested savepoints with outer failure" { | |||
| 3301 | try testing.expectEqual(@as(usize, 0), rows.len); | 3302 | try testing.expectEqual(@as(usize, 0), rows.len); |
| 3302 | } | 3303 | } |
| 3303 | 3304 | ||
| 3304 | fn getTestDb() !Db { | ||
| 3305 | var buf: [1024]u8 = undefined; | ||
| 3306 | var fba = std.heap.FixedBufferAllocator.init(&buf); | ||
| 3307 | |||
| 3308 | var mode = dbMode(fba.allocator()); | ||
| 3309 | |||
| 3310 | return try Db.init(.{ | ||
| 3311 | .open_flags = .{ | ||
| 3312 | .write = true, | ||
| 3313 | .create = true, | ||
| 3314 | }, | ||
| 3315 | .mode = mode, | ||
| 3316 | }); | ||
| 3317 | } | ||
| 3318 | |||
| 3319 | fn tmpDbPath(allocator: mem.Allocator) ![:0]const u8 { | ||
| 3320 | const tmp_dir = testing.tmpDir(.{}); | ||
| 3321 | |||
| 3322 | const path = try std.fs.path.join(allocator, &[_][]const u8{ | ||
| 3323 | "zig-cache", | ||
| 3324 | "tmp", | ||
| 3325 | &tmp_dir.sub_path, | ||
| 3326 | "zig-sqlite.db", | ||
| 3327 | }); | ||
| 3328 | defer allocator.free(path); | ||
| 3329 | |||
| 3330 | return allocator.dupeZ(u8, path); | ||
| 3331 | } | ||
| 3332 | |||
| 3333 | fn dbMode(allocator: mem.Allocator) Db.Mode { | ||
| 3334 | return if (build_options.in_memory) blk: { | ||
| 3335 | break :blk .{ .Memory = {} }; | ||
| 3336 | } else blk: { | ||
| 3337 | if (build_options.dbfile) |dbfile| { | ||
| 3338 | return .{ .File = allocator.dupeZ(u8, dbfile) catch unreachable }; | ||
| 3339 | } | ||
| 3340 | |||
| 3341 | const path = tmpDbPath(allocator) catch unreachable; | ||
| 3342 | |||
| 3343 | std.fs.cwd().deleteFile(path) catch {}; | ||
| 3344 | break :blk .{ .File = path }; | ||
| 3345 | }; | ||
| 3346 | } | ||
| 3347 | |||
| 3348 | const MyData = struct { | 3305 | const MyData = struct { |
| 3349 | data: [16]u8, | 3306 | data: [16]u8, |
| 3350 | 3307 | ||