generator_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2018 Twitch Interactive, Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License"). You may not
  4. // use this file except in compliance with the License. A copy of the License is
  5. // located at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // or in the "license" file accompanying this file. This file is distributed on
  10. // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  11. // express or implied. See the License for the specific language governing
  12. // permissions and limitations under the License.
  13. package main
  14. import (
  15. "os"
  16. "os/exec"
  17. "testing"
  18. "github.com/golang/protobuf/proto"
  19. plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
  20. )
  21. func TestGenerateParseCommandLineParamsError(t *testing.T) {
  22. if os.Getenv("BE_CRASHER") == "1" {
  23. g := &liverpc{}
  24. g.Generate(&plugin.CodeGeneratorRequest{
  25. Parameter: proto.String("invalid"),
  26. })
  27. return
  28. }
  29. cmd := exec.Command(os.Args[0], "-test.run=TestGenerateParseCommandLineParamsError")
  30. cmd.Env = append(os.Environ(), "BE_CRASHER=1")
  31. err := cmd.Run()
  32. if e, ok := err.(*exec.ExitError); ok && !e.Success() {
  33. return
  34. }
  35. t.Fatalf("process ran with err %v, want exit status 1", err)
  36. }