aboutsummaryrefslogtreecommitdiffstats
path: root/tools/syz-kconf/kconf_test.go
blob: 24bc87168562449f460b43ea8d53c26ab46f28dc (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2021 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package main

import (
	"fmt"
	"testing"
)

func TestReleaseTag(t *testing.T) {
	type Test struct {
		in  string
		out string
		err bool
	}
	tests := []Test{
		{
			in: `
VERSION = 4
PATCHLEVEL = 19
SUBLEVEL = 144
EXTRAVERSION =
`,
			out: "v4.19",
		},
		{
			in: `
VERSION = 5
PATCHLEVEL = 4
SUBLEVEL = 0
EXTRAVERSION =
`,
			out: "v5.4",
		},
		{
			in: `
VERSION = 5
PATCHLEVEL = 11
SUBLEVEL = 0
EXTRAVERSION = -rc3
`,
			out: "v5.11",
		},
		{
			in: `
PATCHLEVEL = 11
SUBLEVEL = 0
EXTRAVERSION = -rc3
`,
			err: true,
		},
	}
	for i, test := range tests {
		t.Run(fmt.Sprint(i), func(t *testing.T) {
			got, err := releaseTagImpl([]byte(test.in))
			if test.err != (err != nil) {
				t.Fatalf("expected err=%v, got %q", test.err, err)
			}
			if test.out != got {
				t.Fatalf("expected release %q, got %q", test.out, got)
			}
		})
	}
}