-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.zig
100 lines (91 loc) · 3.34 KB
/
tests.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const std = @import("std");
const testing = std.testing;
const build_opts = @import("build_options");
test "file not found error" {
const allocator = testing.allocator;
const exe_path = build_opts.cli_exe_path;
const exec_result = try std.process.Child.run(.{
.allocator = allocator,
.argv = &.{ exe_path, "hello" },
});
defer {
allocator.free(exec_result.stdout);
allocator.free(exec_result.stderr);
}
try testing.expectEqualStrings("error(zcat): File not found: hello\n", exec_result.stderr);
}
test "is dir error" {
const allocator = testing.allocator;
const exe_path = build_opts.cli_exe_path;
var tmp = testing.tmpDir(.{});
defer tmp.cleanup();
try tmp.dir.makeDir("foo");
const exec_result = try std.process.Child.run(.{
.allocator = allocator,
.argv = &.{ exe_path, "foo" },
.cwd_dir = tmp.dir,
});
defer {
allocator.free(exec_result.stdout);
allocator.free(exec_result.stderr);
}
try testing.expectEqualStrings("error(zcat): foo: Is a directory\n", exec_result.stderr);
}
test "one file ok" {
const allocator = testing.allocator;
const exe_path = build_opts.cli_exe_path;
var tmp = testing.tmpDir(.{});
defer tmp.cleanup();
const file_content = "Example of data with length < 4096 bytes";
try tmp.dir.writeFile(.{ .sub_path = "file1.txt", .data = file_content });
const exec_result = try std.process.Child.run(.{
.allocator = allocator,
.argv = &.{ exe_path, "file1.txt" },
.cwd_dir = tmp.dir,
});
defer {
allocator.free(exec_result.stdout);
allocator.free(exec_result.stderr);
}
try testing.expectEqualStrings(file_content, exec_result.stdout);
}
test "one bigger file ok" {
const allocator = testing.allocator;
const exe_path = build_opts.cli_exe_path;
var tmp = testing.tmpDir(.{});
defer tmp.cleanup();
// 4096 is our app read and write buffers size
const file_content = "Example of data with length > 4096 bytes" ** 1000;
try tmp.dir.writeFile(.{ .sub_path = "file1.txt", .data = file_content });
const exec_result = try std.process.Child.run(.{
.allocator = allocator,
.argv = &.{ exe_path, "file1.txt" },
.cwd_dir = tmp.dir,
});
defer {
allocator.free(exec_result.stdout);
allocator.free(exec_result.stderr);
}
try testing.expectEqualStrings(file_content, exec_result.stdout);
}
test "two big files ok" {
const allocator = testing.allocator;
const exe_path = build_opts.cli_exe_path;
var tmp = testing.tmpDir(.{});
defer tmp.cleanup();
// 4096 is our app read and write buffers size
const file1_content = "Example of data with length > 4096 bytes\n" ** 500;
try tmp.dir.writeFile(.{ .sub_path = "file1.txt", .data = file1_content });
const file2_content = "Some content for the second file\n" ** 500;
try tmp.dir.writeFile(.{ .sub_path = "file2.txt", .data = file2_content });
const exec_result = try std.process.Child.run(.{
.allocator = allocator,
.argv = &.{ exe_path, "file1.txt", "file2.txt" },
.cwd_dir = tmp.dir,
});
defer {
allocator.free(exec_result.stdout);
allocator.free(exec_result.stderr);
}
try testing.expectEqualStrings(file1_content ++ file2_content, exec_result.stdout);
}