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
4 changes: 2 additions & 2 deletions ci/check_all_exposed_funs_tested.roc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ main! = |_args|
# Check if ripgrep is installed
_ = Cmd.exec!("rg", ["--version"])?

cwd = Env.cwd!({}) ? |err| FailedToGetCwd(err)
cwd = Env.cwd!({}) ? FailedToGetCwd
Stdout.line!("Current working directory: ${Path.display(cwd)}")?

path_to_platform_main = "platform/main.roc"
Expand Down Expand Up @@ -87,7 +87,7 @@ is_function_unused! = |module_name, function_name|
search_dirs = ["examples", "tests"]

# Check current working directory
cwd = Env.cwd!({}) ? |err| FailedToGetCwd2(err)
cwd = Env.cwd!({}) ? FailedToGetCwd2

# Check if directories exist
List.for_each_try!(
Expand Down
6 changes: 3 additions & 3 deletions examples/todos.roc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ exec_transaction! = |{ begin_stmt, rollback_stmt, end_stmt }, transaction!|
bindings: [],
},
)
? |err| FailedToBeginTransaction(err)
? FailedToBeginTransaction

end_transaction! = |res|
when res is
Expand All @@ -172,7 +172,7 @@ exec_transaction! = |{ begin_stmt, rollback_stmt, end_stmt }, transaction!|
bindings: [],
},
)
? |err| FailedToEndTransaction(err)
? FailedToEndTransaction

Ok(v)

Expand All @@ -190,7 +190,7 @@ exec_transaction! = |{ begin_stmt, rollback_stmt, end_stmt }, transaction!|
bindings: [],
},
)
? |err| FailedToRollbackTransaction(err)
? FailedToRollbackTransaction

Err(e)

Expand Down
4 changes: 2 additions & 2 deletions tests/dir-test.roc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test_dir_create! = |{}|

# Test creating a single directory
test_dir_name = "test_dir_create"
Dir.create!(test_dir_name) ? |err| DirCreateFailed(err)
Dir.create!(test_dir_name) ? DirCreateFailed

# Verify directory exists using ls
ls_output =
Expand Down Expand Up @@ -301,7 +301,7 @@ cleanup_test_dirs! = |dirs_requirement|

when dirs_requirement is
DirsNeedToExist ->
delete_result ? |err| DirDeletionFailed(err)
delete_result ? DirDeletionFailed
DirsMaybeExist ->
Ok({})?

Expand Down
6 changes: 3 additions & 3 deletions tests/file.roc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ test_file_exists! = |{}|
filename = "test_exists.txt"
File.write_utf8!("", filename)?

test_file_exists = File.exists!(filename) ? |err| FileExistsCheckFailed(err)
test_file_exists = File.exists!(filename) ? FileExistsCheckFailed

if test_file_exists then
Stdout.line!("✓ File.exists! returns true for a file that exists")?
Expand All @@ -240,7 +240,7 @@ test_file_exists! = |{}|
# Test that a file that does not exist returns false
File.delete!(filename)?

test_file_exists_after_delete = File.exists!(filename) ? |err| FileExistsCheckAfterDeleteFailed(err)
test_file_exists_after_delete = File.exists!(filename) ? FileExistsCheckAfterDeleteFailed

if test_file_exists_after_delete then
Stderr.line!("✗ File.exists! returned true for a file that does not exist")?
Expand Down Expand Up @@ -300,7 +300,7 @@ cleanup_test_files! = |files_requirement|

when files_requirement is
FilesNeedToExist ->
delete_result ? |err| FileDeletionFailed(err)
delete_result ? FileDeletionFailed
FilesMaybeExist ->
Ok({})?

Expand Down
28 changes: 14 additions & 14 deletions tests/path-test.roc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ test_file_operations! = |{}|
# Verify file exists before deletion
_ = Cmd.exec!("test", ["-e", "test_to_delete.txt"])?

Path.delete!(delete_path) ? |err| DeleteFailed(err)
Path.delete!(delete_path) ? DeleteFailed

# Verify file is gone after deletion
exists_after_res = Cmd.exec!("test", ["-e", "test_to_delete.txt"])
Expand Down Expand Up @@ -342,7 +342,7 @@ test_path_rename! = |{}|
new_path = Path.from_str("test_path_rename_new.txt")
test_file_content = "Content for rename test."

Path.write_utf8!(test_file_content, original_path) ? |err| WriteOriginalFailed(err)
Path.write_utf8!(test_file_content, original_path) ? WriteOriginalFailed

# Rename the file
when Path.rename!(original_path, new_path) is
Expand All @@ -357,12 +357,12 @@ test_path_rename! = |{}|
else
Stdout.line!("✓ Original file no longer exists")?

new_file_exists = Path.is_file!(new_path) ? |err| NewIsFileFailed(err)
new_file_exists = Path.is_file!(new_path) ? NewIsFileFailed

if new_file_exists then
Stdout.line!("✓ Renamed file exists")?

content = Path.read_utf8!(new_path) ? |err| NewFileReadFailed(err)
content = Path.read_utf8!(new_path) ? NewFileReadFailed

if content == test_file_content then
Stdout.line!("✓ Renamed file has correct content")
Expand All @@ -382,7 +382,7 @@ test_path_exists! = |{}|
filename = Path.from_str("test_path_exists.txt")
Path.write_utf8!("This file exists", filename)?

file_exists = Path.exists!(filename) ? |err| PathExistsCheckFailed(err)
file_exists = Path.exists!(filename) ? PathExistsCheckFailed

if file_exists then
Stdout.line!("✓ Path.exists! returns true for a file that exists")?
Expand All @@ -392,7 +392,7 @@ test_path_exists! = |{}|
# Test that a file that does not exist returns false
Path.delete!(filename)?

file_exists_after_delete = Path.exists!(filename) ? |err| PathExistsCheckAfterDeleteFailed(err)
file_exists_after_delete = Path.exists!(filename) ? PathExistsCheckAfterDeleteFailed

if file_exists_after_delete then
Stderr.line!("✗ Path.exists! returned true for a file that does not exist")?
Expand Down Expand Up @@ -422,23 +422,23 @@ test_is_sym_link! = |{}|
ln_dir_result = Cmd.new("ln") |> Cmd.args(["-s", "test_directory", "test_symlink_to_dir"]) |> Cmd.exec_output!()

# Test is_sym_link on regular file
regular_is_symlink = Path.is_sym_link!(regular_file) ? |err| RegularFileSymlinkCheckFailed(err)
regular_is_symlink = Path.is_sym_link!(regular_file) ? RegularFileSymlinkCheckFailed

# Test is_sym_link on directory
dir_is_symlink = Path.is_sym_link!(test_dir) ? |err| DirSymlinkCheckFailed(err)
dir_is_symlink = Path.is_sym_link!(test_dir) ? DirSymlinkCheckFailed

# Test is_sym_link on symbolic links (if creation succeeded)
file_link_is_symlink =
when ln_file_result is
Ok(_) ->
Path.is_sym_link!(link_to_file) ? |err| FileLinkSymlinkCheckFailed(err)
Path.is_sym_link!(link_to_file) ? FileLinkSymlinkCheckFailed
Err(_) ->
Bool.false

dir_link_is_symlink =
when ln_dir_result is
Ok(_) ->
Path.is_sym_link!(link_to_dir) ? |err| DirLinkSymlinkCheckFailed(err)
Path.is_sym_link!(link_to_dir) ? DirLinkSymlinkCheckFailed
Err(_) ->
Bool.false

Expand Down Expand Up @@ -480,16 +480,16 @@ test_path_type! = |{}|
ln_result = Cmd.new("ln") |> Cmd.args(["-s", "test_type_file.txt", "test_type_symlink.txt"]) |> Cmd.exec_output!()

# Test type on regular file
file_type = Path.type!(regular_file) ? |err| FileTypeCheckFailed(err)
file_type = Path.type!(regular_file) ? FileTypeCheckFailed

# Test type on directory
dir_type = Path.type!(test_dir) ? |err| DirTypeCheckFailed(err)
dir_type = Path.type!(test_dir) ? DirTypeCheckFailed

# Test type on symbolic link (if creation succeeded)
symlink_type =
when ln_result is
Ok(_) ->
Path.type!(symlink_path) ? |err| SymlinkTypeCheckFailed(err)
Path.type!(symlink_path) ? SymlinkTypeCheckFailed
Err(_) ->
IsFile

Expand Down Expand Up @@ -542,7 +542,7 @@ cleanup_test_files! = |files_requirement|

when files_requirement is
FilesNeedToExist ->
delete_result ? |err| PathDeletionFailed(err)
delete_result ? PathDeletionFailed
FilesMaybeExist ->
Ok({})?

Expand Down
22 changes: 11 additions & 11 deletions tests/sqlite-test.roc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ run_tests! = |{}|
col_nullable_f64: Sqlite.nullable_f64("col_nullable_f64"),
col_nullable_f32: Sqlite.nullable_f32("col_nullable_f32"),
},
}) ? |err| QuerManyFailed(err)
}) ? QuerManyFailed

rows_texts_str =
all_rows
Expand All @@ -68,7 +68,7 @@ run_tests! = |{}|
query: "SELECT COUNT(*) as \"count\" FROM test;",
bindings: [],
row: Sqlite.u64("count"),
}) ? |err| QueryCountFailed(err)
}) ? QueryCountFailed


Stdout.line!("Row count: ${Num.to_str(count)}")?
Expand All @@ -78,13 +78,13 @@ run_tests! = |{}|
prepared_count_query = Sqlite.prepare!({
path: db_path,
query: "SELECT COUNT(*) as \"count\" FROM test;",
}) ? |err| PrepareFailed(err)
}) ? PrepareFailed

count_prepared = Sqlite.query_prepared!({
stmt: prepared_count_query,
bindings: [],
row: Sqlite.u64("count"),
}) ? |err| QueryPreparedFailed(err)
}) ? QueryPreparedFailed


Stdout.line!("Row count (prepared): ${Num.to_str(count_prepared)}")?
Expand All @@ -94,31 +94,31 @@ run_tests! = |{}|
prepared_update = Sqlite.prepare!({
path: db_path,
query: "UPDATE test SET col_text = :col_text WHERE id = :id;",
}) ? |err| PreparedUpdateFailed(err)
}) ? PreparedUpdateFailed

Sqlite.execute_prepared!({
stmt: prepared_update,
bindings: [
{ name: ":id", value: Integer(1) },
{ name: ":col_text", value: String("Updated text 1") },
],
}) ? |err| ExecutePreparedFailed(err)
}) ? ExecutePreparedFailed

Sqlite.execute_prepared!({
stmt: prepared_update,
bindings: [
{ name: ":id", value: Integer(2) },
{ name: ":col_text", value: String("Updated text 2") },
],
}) ? |err| ExecutePrepared2Failed(err)
}) ? ExecutePrepared2Failed

# Check if the updates were successful
updated_rows = Sqlite.query_many!({
path: db_path,
query: "SELECT COL_TEXT FROM test;",
bindings: [],
rows: Sqlite.str("col_text"),
}) ? |err| QueryUpdatedRowsFailed(err)
}) ? QueryUpdatedRowsFailed

Stdout.line!("Updated rows: ${Inspect.to_str(updated_rows)}")?

Expand All @@ -129,15 +129,15 @@ run_tests! = |{}|
{ name: ":id", value: Integer(1) },
{ name: ":col_text", value: String("example text") },
],
}) ? |err| ExecutePrepared3Failed(err)
}) ? ExecutePrepared3Failed

Sqlite.execute_prepared!({
stmt: prepared_update,
bindings: [
{ name: ":id", value: Integer(2) },
{ name: ":col_text", value: String("sample text") },
],
}) ? |err| ExecutePrepared4Failed(err)
}) ? ExecutePrepared4Failed

# Test tagged_value
tagged_value_test = Sqlite.query_many!({
Expand All @@ -146,7 +146,7 @@ run_tests! = |{}|
bindings: [],
# This uses the record builder syntax: https://www.roc-lang.org/examples/RecordBuilder/README.html
rows: Sqlite.tagged_value("col_text"),
}) ? |err| QueryMany2Failed(err)
}) ? QueryMany2Failed

Stdout.line!("Tagged value test: ${Inspect.to_str(tagged_value_test)}")?

Expand Down
12 changes: 6 additions & 6 deletions tests/tcp.roc
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ test_tcp_functions! = |stream|
do_not_read_bytes = [100, 111, 32, 110, 111, 116, 32, 114, 101, 97, 100, 32, 112, 97, 115, 116, 32, 109, 101, 65] # "do not read past meA" in bytes
Tcp.write!(stream, do_not_read_bytes)?

nineteen_bytes = Tcp.read_up_to!(stream, 19) ? |err| FailedReadUpTo(err)
nineteen_bytes_as_str = Str.from_utf8(nineteen_bytes) ? |err| ReadUpToFromUtf8(err)
nineteen_bytes = Tcp.read_up_to!(stream, 19) ? FailedReadUpTo
nineteen_bytes_as_str = Str.from_utf8(nineteen_bytes) ? ReadUpToFromUtf8

Stdout.line!(
"""
Expand All @@ -77,8 +77,8 @@ test_tcp_functions! = |stream|
)?
Tcp.write_utf8!(stream, "BC")?

three_bytes = Tcp.read_exactly!(stream, 3) ? |err| FailedReadExactly(err)
three_bytes_as_str = Str.from_utf8(three_bytes) ? |err| ReadExactlyFromUtf8(err)
three_bytes = Tcp.read_exactly!(stream, 3) ? FailedReadExactly
three_bytes_as_str = Str.from_utf8(three_bytes) ? ReadExactlyFromUtf8

Stdout.line!(
"""
Expand All @@ -90,8 +90,8 @@ test_tcp_functions! = |stream|
)?
Tcp.write_utf8!(stream, "Line1\nLine2\n")?

bytes_until = Tcp.read_until!(stream, '\n') ? |err| FailedReadUntil(err)
bytes_until_as_str = Str.from_utf8(bytes_until) ? |err| ReadUntilFromUtf8(err)
bytes_until = Tcp.read_until!(stream, '\n') ? FailedReadUntil
bytes_until_as_str = Str.from_utf8(bytes_until) ? ReadUntilFromUtf8

Stdout.line!("Tcp.read_until yielded: '${bytes_until_as_str}'\n")?

Expand Down