Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename read_to_string to read #2518

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1842,8 +1842,8 @@ which will halt execution.
- `path_exists(path)` - Returns `true` if the path points at an existing entity
and `false` otherwise. Traverses symbolic links, and returns `false` if the
path is inaccessible or points to a broken symlink.
- `read_to_string(path)`<sup>master</sup> - Returns the content of file at
`path` as string.
- `read(path)`<sup>master</sup> - Returns the content of file at `path` as
string.

##### Error Reporting

Expand Down
4 changes: 2 additions & 2 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub(crate) fn get(name: &str) -> Option<Function> {
"path_exists" => Unary(path_exists),
"prepend" => Binary(prepend),
"quote" => Unary(quote),
"read_to_string" => Unary(read_to_string),
"read" => Unary(read),
"replace" => Ternary(replace),
"replace_regex" => Ternary(replace_regex),
"semver_matches" => Binary(semver_matches),
Expand Down Expand Up @@ -529,7 +529,7 @@ fn quote(_context: Context, s: &str) -> FunctionResult {
Ok(format!("'{}'", s.replace('\'', "'\\''")))
}

fn read_to_string(context: Context, filename: &str) -> FunctionResult {
fn read(context: Context, filename: &str) -> FunctionResult {
fs::read_to_string(context.evaluator.context.working_directory().join(filename))
.map_err(|err| format!("I/O error reading `{filename}`: {err}"))
}
Expand Down
10 changes: 5 additions & 5 deletions tests/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,21 +1260,21 @@ fn style_unknown() {
}

#[test]
fn read_to_string() {
fn read() {
Test::new()
.justfile("foo := read_to_string('bar')")
.justfile("foo := read('bar')")
.write("bar", "baz")
.args(["--evaluate", "foo"])
.stdout("baz")
.run();
}

#[test]
fn read_to_string_not_found() {
fn read_file_not_found() {
Test::new()
.justfile("foo := read_to_string('bar')")
.justfile("foo := read('bar')")
.args(["--evaluate", "foo"])
.stderr_regex(r"error: Call to function `read_to_string` failed: I/O error reading `bar`: .*")
.stderr_regex(r"error: Call to function `read` failed: I/O error reading `bar`: .*")
.status(EXIT_FAILURE)
.run();
}
Loading