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

     1  // Copyright 2023 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 TestWarningCalls(t *testing.T) {
    12  	const code = `package main
    13  import (
    14  	"fmt"
    15  	"time"
    16  	"github.com/godbus/dbus/v5"
    17  	"go.chromium.org/tast/core/errors"
    18  )
    19  func main() {
    20  	testing.Sleep()
    21  }
    22  `
    23  	f, fs := parse(code, "testfile.go")
    24  	issues := WarningCalls(fs, f, false)
    25  	if len(issues) != 1 {
    26  		t.Errorf("Warnings should have at least 1 sleep fail")
    27  	}
    28  }
    29  func TestWarningCalls_Exceptions(t *testing.T) {
    30  	const code = `package main
    31  import (
    32  	"fmt"
    33  	"time"
    34  	"github.com/godbus/dbus/v5"
    35  	"go.chromium.org/tast/core/errors"
    36  )
    37  func main() {
    38  	testing.Sleep() // GoBigSleepLint: valid testing.sleep
    39  }
    40  `
    41  	f, fs := parse(code, "src/go.chromium.org/tast-tests/cros/local/bundles/cros/meta/local_timeout.go")
    42  	issues := WarningCalls(fs, f, false)
    43  	if len(issues) != 0 {
    44  		t.Errorf("Warnings should have 0 sleep warning fail")
    45  	}
    46  }