-
Notifications
You must be signed in to change notification settings - Fork 18
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
[Suggestion] Add verbose to assert fails #395
Comments
Hey @OscBacon, import { assert, describe, test } from "matchstick-as";
import { ethereum, Address } from "@graphprotocol/graph-ts";
describe("Asserts", () => {
test("assert.equals", () => {
assert.equals(ethereum.Value.fromI32(1), ethereum.Value.fromI32(2), "Value should equal 1");
});
test("assert.I32Equals", () => {
assert.i32Equals(1, 2, "I32 should equal 1");
});
test("assert.AddressEquals", () => {
assert.addressEquals(
Address.zero(),
Address.fromString("0x0000000000000000000000000000000000000001"),
"Address should equal zero address"
);
});
}); yarn test -rv 0.6.0-beta3 asserts
___ ___ _ _ _ _ _
| \/ | | | | | | | (_) | |
| . . | __ _| |_ ___| |__ ___| |_ _ ___| | __
| |\/| |/ _` | __/ __| '_ \/ __| __| |/ __| |/ /
| | | | (_| | || (__| | | \__ \ |_| | (__| <
\_| |_/\__,_|\__\___|_| |_|___/\__|_|\___|_|\_\
Compiling...
💬 Compiling asserts...
Igniting tests 🔥
asserts
--------------------------------------------------
Asserts:
𝖷 assert.equals - 0.565ms
𝖷 assert.I32Equals - 0.107ms
𝖷 assert.AddressEquals - 0.135ms
Failed tests:
asserts
assert.equals
𝖷 Value should equal 1
🛠 Mapping aborted at ~lib/matchstick-as/assert.ts, line 38, column 7, with message: assert.equals Assertion Error
wasm backtrace:
0: 0x1aee - <unknown>!start:tests/asserts.test~anonymous|0~anonymous|0
assert.I32Equals
𝖷 I32 should equal 1
🛠 Mapping aborted at ~lib/matchstick-as/assert.ts, line 94, column 7, with message: assert.i32Equals Assertion Error
wasm backtrace:
0: 0x1b37 - <unknown>!start:tests/asserts.test~anonymous|0~anonymous|1
assert.AddressEquals
𝖷 Address should equal zero address
🛠 Mapping aborted at ~lib/matchstick-as/assert.ts, line 66, column 7, with message: assert.addressEquals Assertion Error
wasm backtrace:
0: 0x1bfd - <unknown>!start:tests/asserts.test~anonymous|0~anonymous|2
3 failed, 0 passed, 3 total |
Looks promising! |
Should be resolved by #408, can be tested with https://github.com/LimeChain/matchstick/releases/tag/0.6.0-rc.3 |
Hi, first off, great testing library!
It would be nice to have more verbose on assert fails. As of right now, I have to add log statements to find out which assert exactly failed.
For example, on a series
assert.entityCount
, this message is not helpful enough:(and the backtrace doesn't say much)
Secondly, having assert functions with a message field could help too, a la nodejs assert: https://nodejs.org/api/assert.html
If I understand correctly, AS doesn't allow for function overloading or optional arguments. One solution could be to have an
assert
namespace, and anassertMessage
namespace with the same functions, but that throw a custom message when the assert failsThe text was updated successfully, but these errors were encountered: