diff options
Diffstat (limited to 'rust/project_json_test.go')
-rw-r--r-- | rust/project_json_test.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/rust/project_json_test.go b/rust/project_json_test.go index 8f64f56e2..7af463528 100644 --- a/rust/project_json_test.go +++ b/rust/project_json_test.go @@ -18,6 +18,7 @@ import ( "encoding/json" "io/ioutil" "path/filepath" + "sort" "strings" "testing" @@ -115,6 +116,41 @@ func TestProjectJsonDep(t *testing.T) { validateJsonCrates(t, jsonContent) } +func TestProjectJsonFeature(t *testing.T) { + bp := ` + rust_library { + name: "liba", + srcs: ["a/src/lib.rs"], + crate_name: "a", + features: ["f1", "f2"] + } + ` + jsonContent := testProjectJson(t, bp) + crates := validateJsonCrates(t, jsonContent) + for _, c := range crates { + crate := validateCrate(t, c) + cfgs, ok := crate["cfg"].([]interface{}) + if !ok { + t.Fatalf("Unexpected type for cfgs: %v", crate) + } + expectedCfgs := []string{"feature=\"f1\"", "feature=\"f2\""} + foundCfgs := []string{} + for _, cfg := range cfgs { + cfg, ok := cfg.(string) + if !ok { + t.Fatalf("Unexpected type for cfg: %v", cfg) + } + foundCfgs = append(foundCfgs, cfg) + } + sort.Strings(foundCfgs) + for i, foundCfg := range foundCfgs { + if foundCfg != expectedCfgs[i] { + t.Errorf("Incorrect features: got %v; want %v", foundCfg, expectedCfgs[i]) + } + } + } +} + func TestProjectJsonBinary(t *testing.T) { bp := ` rust_binary { |