-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmark_time_in_files_test.go
129 lines (116 loc) · 3 KB
/
mark_time_in_files_test.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// -----------------------------------------------------------------------------
// CMDX Utilities Suite cmdx/[mark_time_in_files_test.go]
// (c) balarabe@protonmail.com License: GPLv3
// -----------------------------------------------------------------------------
package main
// # Command Handler
// Test_mtif_markTimeInFiles_(t *testing.T)
//
// # Support (File Scope)
// Test_mtif_getTimeLogPath(t *testing.T)
// Test_mtif_processDir_(t *testing.T)
// Test_mtif_processFile_(t *testing.T)
// Test_mtif_replaceVersion_(t *testing.T)
// to test all items in mark_time_in_files.go use:
// go test --run Test_mtif_
//
// to generate a test coverage report for the whole module use:
// go test -coverprofile cover.out
// go tool cover -html=cover.out
import (
"testing"
"time"
"github.com/balacode/zr"
)
// -----------------------------------------------------------------------------
// # Command Handler
// go test --run Test_mtif_markTimeInFiles_
func Test_mtif_markTimeInFiles_(t *testing.T) {
zr.TBegin(t)
// markTimeInFiles(cmd Command, args []string)
//
test := func(
// in:
cmd Command, args []string,
) {
markTimeInFiles(cmd, args)
}
test(Command{}, []string{})
}
// -----------------------------------------------------------------------------
// # Support (File Scope)
// go test --run Test_mtif_getTimeLogPath
func Test_mtif_getTimeLogPath(t *testing.T) {
zr.TBegin(t)
// getTimeLogPath(path)
//
// these paths and filenames don't need to physically exist
// the function only processes strings, which are all specified here
oldPaths := TimeLogPaths
TimeLogPaths = []string{
`X:\tests`,
`X:\tests\sub`,
`X:\tests\sub\p1`,
`X:\tests\sub\p2`,
`X:\tests\sub\p3`,
`X:\tests\other`,
}
fn := getTimeLogPath
zr.TEqual(t, fn(`X:\tests\sub\p2\main.go`),
`X:\tests\sub\p2`,
)
zr.TEqual(t, fn(`X:\tests\file.txt`),
`X:\tests`,
)
TimeLogPaths = oldPaths
}
// go test --run Test_mtif_processDir_
func Test_mtif_processDir_(t *testing.T) {
zr.TBegin(t)
// processDir(dir string, changeTime bool)
//
test := func(
// in:
dir string, changeTime bool,
) {
processDir(dir, changeTime)
}
test("", false)
}
// go test --run Test_mtif_processFile_
func Test_mtif_processFile_(t *testing.T) {
zr.TBegin(t)
// processFile(path, name string, modTime time.Time) error
//
test := func(
// in:
path, name string, modTime time.Time,
// out expected:
err error,
) {
errT := processFile(path, name, modTime)
zr.TEqual(t, errT, (err))
}
test("", "", time.Time{},
// out:
nil)
}
// go test --run Test_mtif_replaceVersion_
func Test_mtif_replaceVersion_(t *testing.T) {
zr.TBegin(t)
// replaceVersion(s, path, filename string, modTime time.Time) string
//
test := func(
// in:
s, path, filename string, modTime time.Time,
// out expected:
ret string,
) {
retT := replaceVersion(s, path, filename, modTime)
zr.TEqual(t, retT, (ret))
}
test("", "", "", time.Time{},
// out:
"")
}
// end