xhd2015 / xgo

All-in-one go testing library
MIT License
358 stars 19 forks source link

Feature: convenient assert syntax #49

Open xhd2015 opened 6 months ago

xhd2015 commented 6 months ago

When writing asserts, could we just naturally do the actual check without repeating any name?

Current situation:

if result!="1234"{
    t.Fatalf("expect result to be %s, actual: %s", "123", result)
}

If we can just write:

assert.Assert(result=="1234")

And xgo prints the variable name and actual value in a breaking down style upon failure:

xxx_test.go:12    result=="1234"
                    ^
                    "123"

Besides, I think maybe we need to let user write AST plugins.

WAY29 commented 6 months ago

Look like a good idea. maybe xgo can be a all in one test suite?

xhd2015 commented 6 months ago

Look like a good idea. maybe xgo can be a all in one test suite?

@WAY29 Thanks, groovy supports this assert feature, that's where the idea comes from. As for all in one, it could be completely possible if we can provide all features out of box that are required for writing tests.