File: main_test.go

package info (click to toggle)
golang-github-integrii-flaggy 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 292 kB
  • sloc: makefile: 3
file content (53 lines) | stat: -rw-r--r-- 1,021 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package flaggy_test

import (
	"os"
	"testing"

	"github.com/integrii/flaggy"
)

func TestMain(m *testing.M) {
	flaggy.PanicInsteadOfExit = true
	os.Exit(m.Run())
}

func TestSetDescription(t *testing.T) {
	desc := "Test Description"
	flaggy.SetDescription(desc)
	if flaggy.DefaultParser.Description != desc {
		t.Fatal("set description does not match")
	}
}

func TestSetVersion(t *testing.T) {
	ver := "Test Version"
	flaggy.SetVersion(ver)
	if flaggy.DefaultParser.Version != ver {
		t.Fatal("set version does not match")
	}
}

func TestParserWithNoArgs(t *testing.T) {
	os.Args = []string{}
	flaggy.ResetParser()
}

func TestSetName(t *testing.T) {
	name := "Test Name"
	flaggy.SetName(name)
	if flaggy.DefaultParser.Name != name {
		t.Fatal("set name does not match")
	}
}

func TestShowHelpAndExit(t *testing.T) {
	flaggy.PanicInsteadOfExit = true
	defer func() {
		r := recover()
		if r == nil {
			t.Fatal("Expected panic on show help and exit call")
		}
	}()
	flaggy.ShowHelpAndExit("test show help and exit")
}