我正在創建一個 Golang 項目,并且在添加與功能同步的測試方面做得很好。總體思路是我在文件和 git 分支之間執行“語義差異”。對于最新功能,行為取決于是否tree-sitter-cli安裝了外部工具 ( ),以及安裝了哪些額外功能。如果未安裝外部工具(或其可選語法),我希望我的內部函數產生不同的結果。然而,這兩個結果都與我的工具 ( sdt) 本身是正確的一致。例如,這是我從另一種沒有使用 tree-sitter 分析的編程語言修改而來的測試:func TestNoSemanticDiff(t *testing.T) { // Narrow the options to these test files opts := options opts.Source = file0.name opts.Destination = file1.name report := treesitter.Diff("", opts, config) if !strings.Contains(report, "| No semantic differences detected") { t.Fatalf("Failed to recognize semantic equivalence of %s and %s", opts.Source, opts.Destination) }}各種支持語言的測試在形式上大體相同。然而,在這種情況下,如果缺少外部工具(或不包含該功能),則接收“|沒有適用于此格式的語義分析器”的“報告”也將是一個正確的值。問題是,我可以運行代碼來確定預期的值;但理想情況下,該代碼將“在測試頂部運行一次”,而不是在許多類似測試中的每一個中重新檢查。所以我理想中想要的是首先運行某種設置/腳手架,然后讓單獨的測試編寫如下:if !treeSitterInstalled { // checked once at start of test file if !strings.Contains(report, "appropriate response") { ... }} else if treeSitterNoLangSupport { // ditto, configured once if !strings.Contains(report, "this other thing") { ... }} else { if !string.Contains(report, "the stuff where it's installed") { ... }}
- 1 回答
- 0 關注
- 123 瀏覽
添加回答
舉報
0/150
提交
取消