File: outdated_spec.cr

package info (click to toggle)
shards 0.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 904 kB
  • sloc: makefile: 117
file content (285 lines) | stat: -rw-r--r-- 10,730 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
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
require "./spec_helper"

describe "outdated" do
  it "up to date" do
    with_shard({dependencies: {web: "*"}}) do
      run "shards install"

      stdout = run "shards outdated --no-color"
      stdout.should contain("I: Dependencies are up to date!")
    end
  end

  it "not latest version" do
    with_shard({dependencies: {orm: "*"}}, {orm: "0.3.1"}) do
      run "shards install"

      stdout = run "shards outdated --no-color"
      stdout.should contain("W: Outdated dependencies:")
      stdout.should contain("  * orm (installed: 0.3.1, available: 0.5.0)")
    end
  end

  it "no releases" do
    commit = git_commits("missing").first
    with_shard({dependencies: {missing: "*"}}, {missing: "0.1.0+git.commit.#{commit}"}) do
      run "shards install"

      stdout = run "shards outdated --no-color"
      stdout.should contain("I: Dependencies are up to date!")
    end
  end

  it "available version matching pessimistic operator" do
    with_shard({dependencies: {orm: "~> 0.3.0"}}, {orm: "0.3.1"}) do
      run "shards install"

      stdout = run "shards outdated --no-color"
      stdout.should contain("W: Outdated dependencies:")
      stdout.should contain("  * orm (installed: 0.3.1, available: 0.3.2, latest: 0.5.0)")
    end
  end

  it "reports new prerelease" do
    with_shard({dependencies: {unstable: "0.3.0.alpha"}}) do
      run "shards install"
    end
    with_shard({dependencies: {unstable: "~> 0.3.0.alpha"}}) do
      stdout = run "shards outdated --no-color"
      stdout.should contain("W: Outdated dependencies:")
      stdout.should contain("  * unstable (installed: 0.3.0.alpha, available: 0.3.0.beta)")
    end
  end

  it "won't report prereleases by default" do
    with_shard({dependencies: {preview: "*"}}, {preview: "0.2.0"}) do
      run "shards install"

      stdout = run "shards outdated --no-color"
      stdout.should contain("W: Outdated dependencies:")
      stdout.should contain("  * preview (installed: 0.2.0, available: 0.3.0)")
    end
  end

  it "reports prereleases when asked" do
    with_shard({dependencies: {preview: "*"}}, {preview: "0.2.0"}) do
      run "shards install"

      stdout = run "shards outdated --pre --no-color"
      stdout.should contain("W: Outdated dependencies:")
      stdout.should contain("  * preview (installed: 0.2.0, available: 0.4.0.a)")
    end
  end

  it "fails when source has changed" do
    with_shard({dependencies: {awesome: "0.1.0"}}) do
      run "shards install"
    end

    with_shard({dependencies: {awesome: {git: git_url(:forked_awesome)}}}) do
      ex = expect_raises(FailedCommand) { run "shards outdated --no-color" }
      ex.stdout.should contain("Outdated shard.lock (awesome source changed)")
    end
  end

  it "fails when requirements would require an update" do
    with_shard({dependencies: {awesome: "0.1.0"}}) do
      run "shards install"
    end

    with_shard({dependencies: {awesome: "0.2.0"}}) do
      ex = expect_raises(FailedCommand) { run "shards outdated --no-color" }
      ex.stdout.should contain("Outdated shard.lock (awesome requirements changed)")
    end
  end

  it "fails when requirements would require an update due to override" do
    metadata = {dependencies: {awesome: "0.1.0"}}

    with_shard(metadata) do
      run "shards install"
    end

    override = {dependencies: {awesome: "0.2.0"}}

    with_shard(metadata, nil, override) do
      ex = expect_raises(FailedCommand) { run "shards outdated --no-color" }
      ex.stdout.should contain("Outdated shard.lock (awesome requirements changed)")
    end
  end

  it "not latest version in override (same source)" do
    metadata = {dependencies: {awesome: "0.1.0"}}
    lock = {awesome: "0.1.0"}
    override = {dependencies: {awesome: "*"}}

    with_shard(metadata, lock, override) do
      run "shards install"

      stdout = run "shards outdated --no-color"
      stdout.should contain("W: Outdated dependencies:")
      stdout.should contain("  * awesome (installed: 0.1.0, available: 0.3.0)")
    end
  end

  it "not latest version in override (different source)" do
    metadata = {dependencies: {awesome: "0.1.0"}}
    lock = {awesome: {version: "0.1.0", git: git_url(:forked_awesome)}}
    override = {dependencies: {awesome: {git: git_url(:forked_awesome)}}}

    with_shard(metadata, lock, override) do
      run "shards install"

      stdout = run "shards outdated --no-color"
      stdout.should contain("W: Outdated dependencies:")
      stdout.should contain("  * awesome (installed: 0.1.0, available: 0.2.0)")
    end
  end

  it "up to date in override" do
    metadata = {dependencies: {awesome: "0.1.0"}}
    lock = {awesome: {version: "0.2.0", git: git_url(:forked_awesome)}}
    override = {dependencies: {awesome: {git: git_url(:forked_awesome)}}}

    with_shard(metadata, lock, override) do
      run "shards install"

      stdout = run "shards outdated --no-color"
      stdout.should contain("I: Dependencies are up to date!")
    end
  end

  describe "non-release" do
    describe "without releases" do
      it "latest any" do
        with_shard({dependencies: {missing: "*"}}, {missing: "0.1.0+git.commit.#{git_commits("missing").first}"}) do
          run "shards install"

          stdout = run "shards outdated --no-color"
          stdout.should contain("I: Dependencies are up to date!")
        end
      end

      it "latest branch" do
        with_shard({dependencies: {missing: {git: git_url("missing"), branch: "master"}}}, {missing: "0.1.0+git.commit.#{git_commits("missing").first}"}) do
          run "shards install"

          stdout = run "shards outdated --no-color"
          stdout.should contain("I: Dependencies are up to date!")
        end
      end

      it "latest commit" do
        with_shard({dependencies: {missing: {git: git_url("missing"), commit: git_commits("missing").first}}}, {missing: "0.1.0+git.commit.#{git_commits("missing").first}"}) do
          run "shards install"

          stdout = run "shards outdated --no-color"
          stdout.should contain("I: Dependencies are up to date!")
        end
      end

      it "outdated any" do
        commits = git_commits("inprogress")
        with_shard({dependencies: {inprogress: "*"}}, {inprogress: "0.1.0+git.commit.#{commits[1]}"}) do
          run "shards install"

          stdout = run "shards outdated --no-color"
          stdout.should contain("W: Outdated dependencies:")
          stdout.should contain("  * inprogress (installed: 0.1.0 at #{commits[1][0..6]}, available: 0.1.0 at #{commits.first[0..6]})")
        end
      end

      it "outdated branch" do
        commits = git_commits("inprogress")
        with_shard({dependencies: {inprogress: {git: git_url("inprogress"), branch: "master"}}}, {inprogress: "0.1.0+git.commit.#{commits[1]}"}) do
          run "shards install"

          stdout = run "shards outdated --no-color"
          stdout.should contain("W: Outdated dependencies:")
          stdout.should contain("  * inprogress (installed: 0.1.0 at #{commits[1][0..6]}, available: 0.1.0 at #{commits.first[0..6]})")
        end
      end

      it "outdated commit" do
        commits = git_commits("inprogress")
        with_shard({dependencies: {inprogress: {git: git_url("inprogress"), commit: commits[1]}}}, {inprogress: "0.1.0+git.commit.#{commits[1]}"}) do
          run "shards install"

          stdout = run "shards outdated --no-color"
          stdout.should contain("W: Outdated dependencies:")
          stdout.should contain("  * inprogress (installed: 0.1.0 at #{commits[1][0..6]}")
          # TODO: commit
          # stdout.should contain("  * inprogress (installed: 0.1.0 at #{commits[1][0..6]}, available: 0.1.0 at #{commits.first[0..6]})")
        end
      end
    end

    describe "with previous releases" do
      it "outdated any" do
        commits = git_commits("heading")
        with_shard({dependencies: {heading: "*"}}, {heading: "0.1.0+git.commit.#{commits[1]}"}) do
          run "shards install"

          stdout = run "shards outdated --no-color"
          stdout.should contain("W: Outdated dependencies:")
          stdout.should contain("  * heading (installed: 0.1.0 at #{commits[1][0..6]}, available: 0.1.0)")
          # TODO: stdout.should contain("  * heading (installed: 0.1.0 at #{commits[1][0..6]}, available: 0.1.0 at #{commits.first[0..6]})")
        end
      end

      it "latest any" do
        commits = git_commits("heading")
        with_shard({dependencies: {heading: "*"}}, {heading: "0.1.0+git.commit.#{commits.first}"}) do
          run "shards install"

          stdout = run "shards outdated --no-color"
          stdout.should contain("I: Dependencies are up to date!")
        end
      end

      it "latest branch" do
        commits = git_commits("heading")
        with_shard({dependencies: {heading: {git: git_url("heading"), branch: "master"}}}, {heading: "0.1.0+git.commit.#{commits.first}"}) do
          run "shards install"

          stdout = run "shards outdated --no-color"
          stdout.should contain("I: Dependencies are up to date!")
        end
      end
    end

    it "outdated any with new release" do
      commits = git_commits("release_hist")
      with_shard({dependencies: {release_hist: "*"}}, {release_hist: "0.1.0+git.commit.#{commits[1]}"}) do
        run "shards install"

        stdout = run "shards outdated --no-color"
        stdout.should contain("W: Outdated dependencies:")
        stdout.should contain("  * release_hist (installed: 0.1.0 at #{commits[1][0..6]}, available: 0.2.0)")
      end
    end

    it "outdated branch without new release" do
      installed_commit = git_commits("branched", "feature")[1]
      branch_head = git_commits("branched", "feature").first
      with_shard({dependencies: {branched: {git: git_url("branched"), branch: "feature"}}}, {branched: "0.1.0+git.commit.#{installed_commit}"}) do
        run "shards install"

        stdout = run "shards outdated --no-color"
        stdout.should contain("W: Outdated dependencies:")
        stdout.should contain("  * branched (installed: 0.1.0 at #{installed_commit[0..6]}, available: 0.1.0 at #{branch_head[0..6]}, latest: 0.2.0)")
      end
    end

    it "latest branch with release on HEAD" do
      branch_head = git_commits("branched", "feature").first
      with_shard({dependencies: {branched: {git: git_url("branched"), branch: "feature"}}}, {branched: "0.1.0+git.commit.#{branch_head}"}) do
        run "shards install"

        stdout = run "shards outdated --no-color"
        stdout.should contain("W: Outdated dependencies:")
        stdout.should contain("  * branched (installed: 0.1.0 at #{branch_head[0..6]}, latest: 0.2.0)")
      end
    end
  end
end