-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
test(cmd/gf): add unit testing case of commented api definitions generating for command gf gen ctrl
#3575
Conversation
@gqcn 因为已经使用了标准库 AST 来做语法分析,所以这个测试用例不应该属于框架职责范畴。 |
用 AST 能保证解析正确,但不能保证生成正确。测的不是 AST,测的是生成逻辑。 |
生成逻辑有其他单测可以确定正确 |
目前2.7.1生成应该没问题吧,之前用的是正则,所以会导致注释掉的也会生成,新版用了ast,准确性没问题,不明白你说的不能保证生成正确说的是哪方面,目前来说api/hello目录下的接口文件是可以做到一个不多,一个不少,但是ctrl目录下不能保证,因为有用户自己写的逻辑,在生成这个目录下的文件的时候,如果是新增的接口,会判断是否存在,如果存在,则不生成,不存在就生成,如果删掉了一个接口,再次执行gf gen ctrl的时候,则不会删除对应的ctrl,好像是这样的逻辑 |
At present, the generation of 2.7.1 should be no problem. The previous version used regular expressions, so the commented out ones will also be generated. The new version uses ast, and the accuracy is no problem. I don’t understand what you mean by not guaranteeing that the generation is correct. , currently, the interface files in the api/hello directory can be no more than one, but there is no guarantee in the ctrl directory, because there is logic written by the user. When generating files in this directory, if It is a newly added interface. It will be judged whether it exists. If it exists, it will not be generated. If it does not exist, it will be generated. If an interface is deleted and the gf gen ctrl is executed again, the corresponding ctrl will not be deleted. It seems like this. logic |
@oldme-git @wln32 我看了下,这里加一个单例来保证正确性验证也挺好的。我顺便看了下咱们生成 |
@oldme-git @wln32 I took a look and it would be good to add a singleton here to ensure correctness verification. I took a look at the command logic for generating |
@gqcn 之前用正则的时候,有很多 |
When using regular expressions before, there were many |
这个单测可以补充覆盖率,感觉可以先合并进去,后续如果有重构计划或者改进,也可以对这块再调整。#3488 我还在review中,需要花一点时间拿真实的复杂项目测试。 |
This single test can supplement the coverage. I feel that it can be merged into it first. If there are refactoring plans or improvements in the future, this area can also be adjusted. #3488 I am still in review and need to spend some time testing it on real complex projects. |
gf gen ctrl
Updates #3569
添加测试用例