|
| 1 | +const STD = @import("std"); |
| 2 | +const UTIL = @import("./../cli/util.zig"); |
| 3 | + |
| 4 | +fn initFSTests() !void { |
| 5 | + STD.fs.cwd().access("tests/test_dir/chapter", .{}) catch { |
| 6 | + try STD.fs.cwd().makePath("tests/test_dir/chapter"); |
| 7 | + }; |
| 8 | + |
| 9 | + STD.fs.cwd().access("tests/test_dir/chapter/test.cpp", .{}) catch { |
| 10 | + var file = try STD.fs.cwd().createFile("tests/test_dir/chapter/test.cpp", .{}); |
| 11 | + defer file.close(); |
| 12 | + }; |
| 13 | +} |
| 14 | + |
| 15 | +test "iterate test directory and filter files" { |
| 16 | + try initFSTests(); |
| 17 | + |
| 18 | + var list_of_contents: STD.ArrayList([]const u8) = .empty; |
| 19 | + defer list_of_contents.deinit(STD.testing.allocator); |
| 20 | + |
| 21 | + try UTIL.iterateDirectory(STD.testing.allocator, "tests/test_dir/chapter", .{ .allow_move_contents = true, .include_filter = ".cpp", .is_print_list_of_contents = true, .move_contents_to = &list_of_contents }); |
| 22 | + |
| 23 | + try STD.testing.expect(STD.mem.eql(u8, list_of_contents.items[0], "tests/test_dir/chapter/test.cpp")); |
| 24 | +} |
| 25 | + |
| 26 | +test "directory tree" { |
| 27 | + var allocator: STD.mem.Allocator = STD.testing.allocator; |
| 28 | + |
| 29 | + const dir_tree: *UTIL.DIR_TREE = try allocator.create(UTIL.DIR_TREE); |
| 30 | + defer allocator.destroy(dir_tree); |
| 31 | + |
| 32 | + try dir_tree.init(allocator, ".patches/solutions"); |
| 33 | +} |
| 34 | + |
| 35 | +test "run sub process with default arguments" { |
| 36 | + var process_output: STD.ArrayList(u8) = .empty; |
| 37 | + defer process_output.deinit(STD.testing.allocator); |
| 38 | + |
| 39 | + try UTIL.runSubProcess(STD.testing.allocator, &process_output, .{}); |
| 40 | + |
| 41 | + try STD.testing.expect(STD.mem.eql(u8, process_output.items, "this is a sub-process\n")); |
| 42 | +} |
| 43 | + |
| 44 | +test "run hello world sub process" { |
| 45 | + var process_output: STD.ArrayList(u8) = .empty; |
| 46 | + defer process_output.deinit(STD.testing.allocator); |
| 47 | + |
| 48 | + try UTIL.runSubProcess(STD.testing.allocator, &process_output, .{ .args = "echo hello world" }); |
| 49 | + |
| 50 | + try STD.testing.expect(STD.mem.eql(u8, process_output.items, "hello world\n")); |
| 51 | +} |
0 commit comments