-
Notifications
You must be signed in to change notification settings - Fork 88
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
refactor: add more errors and better details to the build command #69
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,8 +72,16 @@ fn main() { | |
} | ||
}; | ||
|
||
if let Err(err) = result { | ||
println!("An error occured:\n{:#?}", err); | ||
::std::process::exit(255) | ||
match result { | ||
Ok(()) => {} | ||
Err(DfxError::BuildError(err)) => { | ||
eprintln!("Build failed. Reason:"); | ||
eprintln!(" {}", err); | ||
std::process::exit(255) | ||
} | ||
Err(err) => { | ||
eprintln!("An error occured:\n{:#?}", err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also nitpick I think you can drop the ? (errors implement Display) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh weird -- we are breaking protocol 😛 |
||
std::process::exit(255) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bats | ||
|
||
load utils/_ | ||
|
||
setup() { | ||
# We want to work from a temporary directory, different for every test. | ||
cd $(mktemp -d -t dfx-e2e-XXXXXXXX) | ||
export RUST_BACKTRACE=1 | ||
|
||
dfx_new | ||
} | ||
|
||
teardown() { | ||
# Kill the node manager, the dfx and the client. Ignore errors (ie. if processes aren't | ||
# running). | ||
killall dfx nodemanager client || true | ||
} | ||
|
||
@test "build fails on invalid actorscript" { | ||
install_asset invalid_as | ||
assert_command_fail dfx build | ||
assert_match "syntax error" | ||
} | ||
|
||
@test "build succeeds on default project" { | ||
assert_command dfx build | ||
assert_match "Building hello..." | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ assert_command() { | |
assert_command_fail() { | ||
run "$@" | ||
[[ $status != 0 ]] || \ | ||
( (echo "$*"; echo $output | batslib_decorate "Output") \ | ||
( (echo "$*"; echo "$output" | batslib_decorate "Output") \ | ||
| batslib_decorate "Command succeeded (should have failed)" \ | ||
| fail) | ||
} | ||
|
@@ -34,11 +34,11 @@ assert_command_fail() { | |
# $2 - The string to match against (output). By default it will use | ||
# $output. | ||
assert_match() { | ||
regex=$1 | ||
regex="$1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe {} around? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't matter, and we don't do it if there's no need elsewhere. Separate PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah nvm it is $1. |
||
if [[ $# < 2 ]]; then | ||
text=$output | ||
text="$output" | ||
else | ||
text=$2 | ||
text="$2" | ||
fi | ||
[[ "$text" =~ "$regex" ]] || \ | ||
(batslib_print_kv_single_or_multi 10 "regex" "$regex" "actual" "$text" \ | ||
|
@@ -51,15 +51,15 @@ assert_match() { | |
# $1 - The expected value. | ||
# $2 - The actual value. | ||
assert_eq() { | ||
expected=$1 | ||
expected="$1" | ||
if [[ $# < 2 ]]; then | ||
actual=$output | ||
actual="$output" | ||
else | ||
actual=$2 | ||
actual="$2" | ||
fi | ||
|
||
[[ "$actual" == "$expected" ]] || \ | ||
(batslib_print_kv_single_or_multi 10 "expected" $expected "actual" $actual \ | ||
(batslib_print_kv_single_or_multi 10 "expected" "$expected" "actual" "$actual" \ | ||
| batslib_decorate "output does not match" \ | ||
| fail) | ||
} | ||
|
@@ -69,15 +69,15 @@ assert_eq() { | |
# $1 - The expected value. | ||
# $2 - The actual value. | ||
assert_neq() { | ||
expected=$1 | ||
expected="$1" | ||
if [[ $# < 2 ]]; then | ||
actual=$output | ||
actual="$output" | ||
else | ||
actual=$2 | ||
actual="$2" | ||
fi | ||
|
||
[[ "$actual" != "$expected" ]] || \ | ||
(batslib_print_kv_single_or_multi 10 "expected" $expected "actual" $actual \ | ||
(batslib_print_kv_single_or_multi 10 "expected" "$expected" "actual" "$actual" \ | ||
| batslib_decorate "output does not match" \ | ||
| fail) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what was this printout for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We showed the output of the command to stdout, but really there's no need. If we need to pipe it to STDOUT we should do so in the command.