aboutsummaryrefslogtreecommitdiff
path: root/tests/git-pre-commit-version-check.testscript
blob: 28e4efcf0dc55e5e60c9c6747ec08d6410947940 (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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# file      : tests/git-pre-commit-version-check.testscript
# license   : MIT; see accompanying LICENSE file

.include git-common.testscript git-pre-commit-common.testscript

+bash --version >&2 2>! # For troubleshooting.

: multi-package-project
:
{
  $clone_prj;

  touch prj/TODO;
  $ga .;
  $gc;                       # Initial commit.

  echo '@@' >=prj/TODO;
  $gc;                       # No committed packages.manifest.

  cat <<EOI >=prj/packages.manifest;
    : 1
    location: libfoo/
    :
    location: libbar/
    :
    location: libbaz/
    EOI
  $ga .;

  $gc 2>>EOE;                # packages.manifest is staged.
    warning: package manifest file libfoo/manifest does not exist
    warning: package manifest file libbar/manifest does not exist
    warning: package manifest file libbaz/manifest does not exist
    EOE

  echo '@@ todo' >=prj/TODO;

  # packages.manifest is committed but there are no package manifests.
  #
  $gc 2>>EOE;
    warning: package manifest file libfoo/manifest does not exist
    warning: package manifest file libbar/manifest does not exist
    warning: package manifest file libbaz/manifest does not exist
    EOE

  mkdir prj/libfoo prj/libbar prj/libbaz;
  cat <<EOI >=prj/libfoo/manifest;
    : 1
    name: libfoo
    version: 1.2.3-a.1.z
    summary: Foo
    EOI
  cat <<EOI >=prj/libbar/manifest;
    : 1
    name: libbar
    version: 1.2.3
    summary: Bar
    EOI
  cat <<EOI >=prj/libbaz/manifest;
    : 1
    name: libbaz
    version: 0+1
    summary: Baz
    EOI
  $ga .;

  $gc;                       # Same as above plus the package manifests are
                             # staged.

  echo '@@ TODO' >=prj/TODO;

  $gc;                       # Packages are committed but the staged change
                             # goes outside the package directories.

  touch prj/libfoo/TODO prj/libbar/TODO prj/libbaz/TODO;
  $ga libfoo/TODO;

  $gc;                       # Package with an open version (snapshot) is
                             # changed.

  $ga libbar/TODO;

  $gc 2>>EOE != 0;           # Package with a final version is changed.
    error: changing released package libbar 1.2.3 without version increment
      info: use --no-verify git option to suppress
    EOE

  sed -i -e 's/^(version:).+$/\1 1.2.4-a.1.z/' prj/libbar/manifest;

  $gc;                       # Open package development circle.

  echo '@@' >=prj/libbar/TODO;

  $gc;                       # Development cycle is open.

  $ga libbaz/TODO;

  $gc 2>>EOE != 0;           # Package with a stub version is changed.
    error: changing released package libbaz 0+1 without version increment
      info: use --no-verify git option to suppress
    EOE

  sed -i -e 's/^(version:).+$/\1 0+2/' prj/libbaz/manifest;

  $gc;                       # Release the stub package revision.

  sed -i -e 's/^(version:).+$/\1 1.2.3/' prj/libfoo/manifest;

  $gc;                       # Release new version.

  echo '@@ todo' >=prj/libfoo/TODO;

  $gc 2>>EOE != 0;           # Package with a final version is changed.
    error: changing released package libfoo 1.2.3 without version increment
      info: use --no-verify git option to suppress
    EOE

  $gr libfoo/manifest &!prj/libfoo/manifest;

  $gc 2>>EOE;                # The manifest removal is staged (not a package now).
    warning: package manifest file libfoo/manifest does not exist
    EOE

  sed -i -e 's/^(version:).+$/\1 1.2.4/' prj/libbar/manifest;

  $gc 2>>EOE;                # Release new version.
    warning: package manifest file libfoo/manifest does not exist
    EOE

  echo '@@ todo' >=prj/libbar/TODO;

  $gc 2>>EOE != 0;           # Package with a final version is changed.
    warning: package manifest file libfoo/manifest does not exist
    error: changing released package libbar 1.2.4 without version increment
      info: use --no-verify git option to suppress
    EOE

  cat <<EOI >=prj/packages.manifest;
    : 1
    location: libbaz/
    EOI

  $gc;                       # The package removal from packages.manifest is
                             # staged, so it's not a package anymore.

  cat <<EOI >=prj/packages.manifest;
    : 1
    location: lib/baz/
    EOI
  mkdir prj/lib;
  mv prj/libbaz prj/lib/baz;
  $ga .;

  $gc 2>>EOE != 0;           # Package with a stub version is moved.
    error: moving released package libbaz 0+2
      info: use --no-verify git option to suppress
    EOE

  sed -i -e 's/^(version:).+$/\1 0+3/' prj/lib/baz/manifest;

  $gc                        # Release the stub package revision.
}

: single-package-project
:
{
  $clone_prj;

  cat <<EOI >=prj/manifest;
    : 1
    name: foo
    version: 1.2.3
    summary: Foo
    EOI
  touch prj/TODO;
  $ga .;

  $gc 2>|;                       # No committed manifest.

  echo '@@' >=prj/TODO;

  $gc 2>>EOE != 0;           # Package with a final version is changed.
    error: changing released package foo 1.2.3 without version increment
      info: use --no-verify git option to suppress
    EOE

  sed -i -e 's/^(version:).+$/\1 1.2.4-a.1.123/' prj/manifest;

  $gc;                       # Open package development circle.

  echo '@@ todo' >=prj/TODO;

  $gc;                       # Development cycle is open.

  sed -i -e 's/^(version:).+$/\1 1.2.4/' prj/manifest;

  $gc;                       # Release new version.

  echo '@@ TODO' >=prj/TODO;

  $gc 2>>EOE != 0;           # Package with a final version is changed.
    error: changing released package foo 1.2.4 without version increment
      info: use --no-verify git option to suppress
    EOE

  $gr manifest &!prj/manifest;

  # Make sure there is no warning.
  #
  $gc 2>:''                  # The manifest removal is staged, so it's not a
                             # package anymore.
}

: warnings
:
{
  +$clone_prj

  : no-name
  :
  {
    $clone_prj;

    cat <<EOI >=prj/manifest;
      : 1
      summary: Foo
      EOI
    $ga .;

    $gc 2>"warning: package name is missing in ./manifest"
  }

  : no-version
  :
  {
    $clone_prj;

    cat <<EOI >=prj/manifest;
      : 1
      name: libfoo
      summary: Foo
      EOI
    $ga .;

    $gc 2>"warning: package version is missing in ./manifest"
  }

  : invalid-version
  :
  {
    $clone_prj;

    cat <<EOI >=prj/manifest;
      : 1
      name: libfoo
      version: abc
      summary: Foo
      EOI
    $ga .;

    $gc 2>"warning: package version 'abc' in ./manifest is not a valid standard version"
  }
}