Skip to content

Commit

Permalink
Rename read_to_string() to read() (#2518)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Dec 10, 2024
1 parent 464fdbc commit 8b35450
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
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();
}

0 comments on commit 8b35450

Please sign in to comment.