mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
File arguments added to `std.Build.Step.Run` with e.g. `addFileArg` are not necessarily passed as absolute paths. It used to be the case that they were as a consequence of an unnecessary path conversion done by the frontend, but this no longer happens, at least not always, so these tests were sometimes failing when run locally. Therefore, the standalone tests must handle cwd-relative CLI paths correctly.
42 lines
1009 B
Zig
42 lines
1009 B
Zig
//! Verifies that a file exists in a directory.
|
|
//!
|
|
//! Usage:
|
|
//!
|
|
//! ```
|
|
//! exists_in <dir> <path>
|
|
//! ```
|
|
//!
|
|
//! Where `<dir>/<path>` is the full path to the file.
|
|
//! `<dir>` must be an absolute path.
|
|
|
|
const std = @import("std");
|
|
|
|
pub fn main() !void {
|
|
var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
|
const arena = arena_state.allocator();
|
|
defer arena_state.deinit();
|
|
|
|
try run(arena);
|
|
}
|
|
|
|
fn run(allocator: std.mem.Allocator) !void {
|
|
var args = try std.process.argsWithAllocator(allocator);
|
|
defer args.deinit();
|
|
_ = args.next() orelse unreachable; // skip binary name
|
|
|
|
const dir_path = args.next() orelse {
|
|
std.log.err("missing <dir> argument", .{});
|
|
return error.BadUsage;
|
|
};
|
|
|
|
const relpath = args.next() orelse {
|
|
std.log.err("missing <path> argument", .{});
|
|
return error.BadUsage;
|
|
};
|
|
|
|
var dir = try std.fs.cwd().openDir(dir_path, .{});
|
|
defer dir.close();
|
|
|
|
_ = try dir.statFile(relpath);
|
|
}
|