Skip to content
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
45 changes: 27 additions & 18 deletions ci/expect_scripts/path-test.exp
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,40 @@ expect "Testing Path functions..." {
expect -re "Second file inode: \\\[\"\\d+\"\\\]" {
expect "Inodes are equal: Bool.true" {
expect "" {

# Cleanup phase
expect "Cleaning up test files..." {
expect "Files to clean up:" {
expect -re "-rw-r--r-- \\d+ \\w+ \\w+ \\d+ \\w+ +\\d+ \\d+:\\d+ test_path_bytes\\.txt" {
expect -re "-rw-r--r-- \\d+ \\w+ \\w+ \\d+ \\w+ +\\d+ \\d+:\\d+ test_path_hardlink\\.txt" {
expect -re "-rw-r--r-- \\d+ \\w+ \\w+ \\d+ \\w+ +\\d+ \\d+:\\d+ test_path_json\\.json" {
expect -re "-rw-r--r-- \\d+ \\w+ \\w+ \\d+ \\w+ +\\d+ \\d+:\\d+ test_path_original\\.txt" {
expect -re "-rw-r--r-- \\d+ \\w+ \\w+ \\d+ \\w+ +\\d+ \\d+:\\d+ test_path_utf8\\.txt" {
expect "" {
expect "Files remaining after cleanup: Bool.false" {
expect "" {

# Final completion message
expect "I ran all Path function tests." {
expect eof {
check_exit_and_segfault
expect "Testing Path.rename!:" {
expect "✓ Original file no longer exists" {
expect "✓ Renamed file exists" {
expect "✓ Renamed file has correct content" {
expect "" {
# Cleanup phase
expect "Cleaning up test files..." {
expect "Files to clean up:" {
expect -re "-rw-r--r-- \\d+ \\w+ \\w+ \\d+ \\w+ +\\d+ \\d+:\\d+ test_path_bytes\\.txt" {
expect -re "-rw-r--r-- \\d+ \\w+ \\w+ \\d+ \\w+ +\\d+ \\d+:\\d+ test_path_hardlink\\.txt" {
expect -re "-rw-r--r-- \\d+ \\w+ \\w+ \\d+ \\w+ +\\d+ \\d+:\\d+ test_path_json\\.json" {
expect -re "-rw-r--r-- \\d+ \\w+ \\w+ \\d+ \\w+ +\\d+ \\d+:\\d+ test_path_original\\.txt" {
expect -re "-rw-r--r-- \\d+ \\w+ \\w+ \\d+ \\w+ +\\d+ \\d+:\\d+ test_path_utf8\\.txt" {
expect "" {
expect "Files remaining after cleanup: Bool.false" {
expect "" {

# Final completion message
expect "I ran all Path function tests." {
expect eof {
check_exit_and_segfault
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions platform/Path.roc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module [
delete_empty!,
delete_all!,
hard_link!,
rename!,
]

import InternalPath
Expand Down Expand Up @@ -394,3 +395,13 @@ hard_link! = |path_original, path_link|
Host.hard_link!(InternalPath.to_bytes(path_original), InternalPath.to_bytes(path_link))
|> Result.map_err(InternalIOErr.handle_err)
|> Result.map_err(LinkErr)

## Renames a file or directory.
##
## This uses [rust's std::fs::rename](https://doc.rust-lang.org/std/fs/fn.rename.html).
rename! : Path, Path => Result {} [PathErr IOErr]
rename! = |from, to|
from_path_bytes = InternalPath.to_bytes(from)
to_path_bytes = InternalPath.to_bytes(to)
Host.file_rename!(from_path_bytes, to_path_bytes)
|> Result.map_err(|err| PathErr(InternalIOErr.handle_err(err)))
Loading