github.com/nya3jp/tast@v0.0.0-20230601000426-85c8e4d83a9b/src/go.chromium.org/tast/core/cmd/tast-lint/internal/check/check_informational_test.go (about)

     1  // Copyright 2019 The ChromiumOS Authors
     2  // Use of this source code is governed by a BSD-style license that can be
     3  // found in the LICENSE file.
     4  
     5  package check
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  func TestInformational(t *testing.T) {
    12  	const code = `package main
    13  func init() {
    14  	testing.AddTest(&testing.Test{
    15  		Func:         Keyboard,
    16  		Desc:         "Demonstrates injecting keyboard events",
    17  		Contacts:     []string{"tast-owners@google.com"},
    18  		Attr:         []string{"group:mainline", "informational"},
    19  		SoftwareDeps: []string{"chrome"},
    20  		Pre:          chrome.LoggedIn(),
    21  	})
    22  }
    23  `
    24  	const path = "/src/go.chromium.org/tast-tests/cros/local/bundles/cros/example/keyboard.go"
    25  	f, fs := parse(code, path)
    26  	issues := VerifyInformationalAttr(fs, f)
    27  	verifyIssues(t, issues, nil)
    28  }
    29  
    30  func TestInformationalDisabled(t *testing.T) {
    31  	const code = `package main
    32  func init() {
    33  	testing.AddTest(&testing.Test{
    34  	})
    35  }
    36  `
    37  	const path = "/src/go.chromium.org/tast-tests/cros/local/bundles/cros/example/pass.go"
    38  	f, fs := parse(code, path)
    39  	issues := VerifyInformationalAttr(fs, f)
    40  	verifyIssues(t, issues, nil)
    41  }
    42  
    43  func TestInformationalDisabledNil(t *testing.T) {
    44  	const code = `package main
    45  func init() {
    46  	testing.AddTest(&testing.Test{
    47  		Attr: nil,
    48  	})
    49  }
    50  `
    51  	const path = "/src/go.chromium.org/tast-tests/cros/local/bundles/cros/example/pass.go"
    52  	f, fs := parse(code, path)
    53  	issues := VerifyInformationalAttr(fs, f)
    54  	verifyIssues(t, issues, nil)
    55  }
    56  
    57  func TestInformationalDisabledEmpty(t *testing.T) {
    58  	const code = `package main
    59  func init() {
    60  	testing.AddTest(&testing.Test{
    61  		Attr: []string{},
    62  	})
    63  }
    64  `
    65  	const path = "/src/go.chromium.org/tast-tests/cros/local/bundles/cros/example/pass.go"
    66  	f, fs := parse(code, path)
    67  	issues := VerifyInformationalAttr(fs, f)
    68  	verifyIssues(t, issues, nil)
    69  }
    70  
    71  func TestInformationalCrosbolt(t *testing.T) {
    72  	const code = `package main
    73  func init() {
    74  	testing.AddTest(&testing.Test{
    75  		Contacts: []string{"tast-owners@google.com"},
    76  		Attr:     []string{"group:crosbolt"},
    77  	})
    78  }
    79  `
    80  	const path = "/src/go.chromium.org/tast-tests/cros/local/crosbolt.go"
    81  	f, fs := parse(code, path)
    82  	issues := VerifyInformationalAttr(fs, f)
    83  	verifyIssues(t, issues, nil)
    84  }
    85  
    86  func TestInformationalParams1(t *testing.T) {
    87  	const code = `package main
    88  func init() {
    89  	testing.AddTest(&testing.Test{
    90  		Attr: []string{"group:mainline"},
    91  		Params: []testing.Param{{
    92  			Name: "param1",
    93  			ExtraAttr: []string{"informational"},
    94  		}, {
    95  			Name: "param2",
    96  		}, {
    97  			Name: "param3",
    98  			ExtraAttr: nil,
    99  		}, {
   100  			Name: "param4",
   101  			ExtraAttr: []string{},
   102  		}},
   103  	})
   104  }
   105  `
   106  	const path = "/src/go.chromium.org/tast-tests/cros/local/parameterized1.go"
   107  	f, fs := parse(code, path)
   108  	issues := VerifyInformationalAttr(fs, f)
   109  	expects := []string{
   110  		"-: Newly added tests should be marked as 'informational'.",
   111  		path + ":12:4: Newly added tests should be marked as 'informational'.",
   112  		path + ":15:4: Newly added tests should be marked as 'informational'.",
   113  	}
   114  	verifyIssues(t, issues, expects)
   115  }
   116  
   117  func TestInformationalParams2(t *testing.T) {
   118  	const code = `package main
   119  func init() {
   120  	testing.AddTest(&testing.Test{
   121  		Params: []testing.Param{{
   122  			Name: "param1",
   123  			ExtraAttr: []string{"group:mainline"},
   124  		}, {
   125  			Name: "param2",
   126  			ExtraAttr: []string{"group:crosbolt"},
   127  		}, {
   128  			Name: "param3",
   129  			ExtraAttr: []string{"group:mainline", "informational"},
   130  		}},
   131  	})
   132  }
   133  `
   134  	const path = "/src/go.chromium.org/tast-tests/cros/local/parameterized2.go"
   135  	f, fs := parse(code, path)
   136  	issues := VerifyInformationalAttr(fs, f)
   137  	expects := []string{
   138  		path + ":6:4: Newly added tests should be marked as 'informational'.",
   139  	}
   140  	verifyIssues(t, issues, expects)
   141  }
   142  
   143  func TestInformationalParams3(t *testing.T) {
   144  	const code = `package main
   145  func init() {
   146  	testing.AddTest(&testing.Test{
   147  		Attr: []string{"informational"},
   148  		Params: []testing.Param{{
   149  			ExtraAttr: []string{"group:mainline"},
   150  		}},
   151  	})
   152  }
   153  `
   154  	const path = "/src/go.chromium.org/tast-tests/cros/local/parameterized3.go"
   155  	f, fs := parse(code, path)
   156  	issues := VerifyInformationalAttr(fs, f)
   157  	verifyIssues(t, issues, nil)
   158  }