4

请教一个问题,一个 go1.17 的库要怎么测试泛型是否正常工作?

 2 years ago
source link: https://www.v2ex.com/t/865118
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Go 编程语言

请教一个问题,一个 go1.17 的库要怎么测试泛型是否正常工作?

  Trim21 · 3 小时 58 分钟前 · 539 次点击

最近写了个 golang 的库,我没有用到泛型也不需要泛型,所以就在 go.mod 里面写了 go 1.17

但是因为用到了 unsafereflect 这些直接操作了内存,所以有必要测试一下 1.18 的泛型能不能正常工作。

但是因为我在 go.mod 里面写的版本要求是 1.17 ,所以不能使用泛型语法。 //go:build go1.18 之类的条件编译也不能解决这个问题,因为 go.mod 里面写的还是 1.17 ,所以就算泛型测试在 go1.18 下才会运行,还是不能用泛型语法。

难道只能额外加一个文件夹,额外写一个 go.mod 用 replace 指向我的库的位置,然后用在 ci 里用多个 go 版本跑我的库的测试和这个额外的文件夹里的 go1.18 测试?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK