forked from Homebrew/brew
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
formula_spec.rb
1448 lines (1148 loc) 路 39.8 KB
/
formula_spec.rb
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# typed: false
# frozen_string_literal: true
require "test/support/fixtures/testball"
require "formula"
describe Formula do
alias_matcher :follow_installed_alias, :be_follow_installed_alias
alias_matcher :have_any_version_installed, :be_any_version_installed
alias_matcher :need_migration, :be_migration_needed
alias_matcher :have_changed_installed_alias_target, :be_installed_alias_target_changed
alias_matcher :supersede_an_installed_formula, :be_supersedes_an_installed_formula
alias_matcher :have_changed_alias, :be_alias_changed
alias_matcher :have_option_defined, :be_option_defined
alias_matcher :have_test_defined, :be_test_defined
alias_matcher :pour_bottle, :be_pour_bottle
describe "::new" do
let(:klass) do
Class.new(described_class) do
url "https://brew.sh/foo-1.0.tar.gz"
end
end
let(:name) { "formula_name" }
let(:path) { Formulary.core_path(name) }
let(:spec) { :stable }
let(:alias_name) { "baz@1" }
let(:alias_path) { CoreTap.instance.alias_dir/alias_name }
let(:f) { klass.new(name, path, spec) }
let(:f_alias) { klass.new(name, path, spec, alias_path: alias_path) }
specify "formula instantiation" do
expect(f.name).to eq(name)
expect(f.specified_name).to eq(name)
expect(f.full_name).to eq(name)
expect(f.full_specified_name).to eq(name)
expect(f.path).to eq(path)
expect(f.alias_path).to be nil
expect(f.alias_name).to be nil
expect(f.full_alias_name).to be nil
expect { klass.new }.to raise_error(ArgumentError)
end
specify "formula instantiation with alias" do
expect(f_alias.name).to eq(name)
expect(f_alias.full_name).to eq(name)
expect(f_alias.path).to eq(path)
expect(f_alias.alias_path).to eq(alias_path)
expect(f_alias.alias_name).to eq(alias_name)
expect(f_alias.specified_name).to eq(alias_name)
expect(f_alias.full_alias_name).to eq(alias_name)
expect(f_alias.full_specified_name).to eq(alias_name)
expect { klass.new }.to raise_error(ArgumentError)
end
context "when in a Tap" do
let(:tap) { Tap.new("foo", "bar") }
let(:path) { (tap.path/"Formula/#{name}.rb") }
let(:full_name) { "#{tap.user}/#{tap.repo}/#{name}" }
let(:full_alias_name) { "#{tap.user}/#{tap.repo}/#{alias_name}" }
specify "formula instantiation" do
expect(f.name).to eq(name)
expect(f.specified_name).to eq(name)
expect(f.full_name).to eq(full_name)
expect(f.full_specified_name).to eq(full_name)
expect(f.path).to eq(path)
expect(f.alias_path).to be nil
expect(f.alias_name).to be nil
expect(f.full_alias_name).to be nil
expect { klass.new }.to raise_error(ArgumentError)
end
specify "formula instantiation with alias" do
expect(f_alias.name).to eq(name)
expect(f_alias.full_name).to eq(full_name)
expect(f_alias.path).to eq(path)
expect(f_alias.alias_path).to eq(alias_path)
expect(f_alias.alias_name).to eq(alias_name)
expect(f_alias.specified_name).to eq(alias_name)
expect(f_alias.full_alias_name).to eq(full_alias_name)
expect(f_alias.full_specified_name).to eq(full_alias_name)
expect { klass.new }.to raise_error(ArgumentError)
end
end
end
describe "#follow_installed_alias?" do
let(:f) do
formula do
url "foo-1.0"
end
end
it "returns true by default" do
expect(f).to follow_installed_alias
end
it "can be set to true" do
f.follow_installed_alias = true
expect(f).to follow_installed_alias
end
it "can be set to false" do
f.follow_installed_alias = false
expect(f).not_to follow_installed_alias
end
end
describe "#versioned_formula?" do
let(:f) do
formula "foo" do
url "foo-1.0"
end
end
let(:f2) do
formula "foo@2.0" do
url "foo-2.0"
end
end
it "returns true for @-versioned formulae" do
expect(f2.versioned_formula?).to be true
end
it "returns false for non-@-versioned formulae" do
expect(f.versioned_formula?).to be false
end
end
describe "#versioned_formulae" do
let(:f) do
formula "foo" do
url "foo-1.0"
end
end
let(:f2) do
formula "foo@2.0" do
url "foo-2.0"
end
end
it "returns true by default" do
FileUtils.touch f.path
FileUtils.touch f2.path
allow(Formulary).to receive(:load_formula_from_path).with(f2.name, f2.path).and_return(f2)
allow(Formulary).to receive(:factory).with(f2.name).and_return(f2)
expect(f.versioned_formulae).to eq [f2]
end
it "returns empty array for non-@-versioned formulae" do
FileUtils.touch f.path
FileUtils.touch f2.path
expect(f2.versioned_formulae).to be_empty
end
end
example "installed alias with core" do
f = formula do
url "foo-1.0"
end
build_values_with_no_installed_alias = [
BuildOptions.new(Options.new, f.options),
Tab.new(source: { "path" => f.path.to_s }),
]
build_values_with_no_installed_alias.each do |build|
f.build = build
expect(f.installed_alias_path).to be nil
expect(f.installed_alias_name).to be nil
expect(f.full_installed_alias_name).to be nil
expect(f.installed_specified_name).to eq(f.name)
expect(f.full_installed_specified_name).to eq(f.name)
end
alias_name = "bar"
alias_path = "#{CoreTap.instance.alias_dir}/#{alias_name}"
CoreTap.instance.alias_dir.mkpath
FileUtils.ln_sf f.path, alias_path
f.build = Tab.new(source: { "path" => alias_path })
expect(f.installed_alias_path).to eq(alias_path)
expect(f.installed_alias_name).to eq(alias_name)
expect(f.full_installed_alias_name).to eq(alias_name)
expect(f.installed_specified_name).to eq(alias_name)
expect(f.full_installed_specified_name).to eq(alias_name)
end
example "installed alias with tap" do
tap = Tap.new("user", "repo")
name = "foo"
path = "#{tap.path}/Formula/#{name}.rb"
f = formula name, path: path do
url "foo-1.0"
end
build_values_with_no_installed_alias = [
BuildOptions.new(Options.new, f.options),
Tab.new(source: { "path" => f.path }),
]
build_values_with_no_installed_alias.each do |build|
f.build = build
expect(f.installed_alias_path).to be nil
expect(f.installed_alias_name).to be nil
expect(f.full_installed_alias_name).to be nil
expect(f.installed_specified_name).to eq(f.name)
expect(f.full_installed_specified_name).to eq(f.full_name)
end
alias_name = "bar"
full_alias_name = "#{tap.user}/#{tap.repo}/#{alias_name}"
alias_path = "#{tap.alias_dir}/#{alias_name}"
tap.alias_dir.mkpath
FileUtils.ln_sf f.path, alias_path
f.build = Tab.new(source: { "path" => alias_path })
expect(f.installed_alias_path).to eq(alias_path)
expect(f.installed_alias_name).to eq(alias_name)
expect(f.full_installed_alias_name).to eq(full_alias_name)
expect(f.installed_specified_name).to eq(alias_name)
expect(f.full_installed_specified_name).to eq(full_alias_name)
FileUtils.rm_rf HOMEBREW_LIBRARY/"Taps/user"
end
specify "#prefix" do
f = Testball.new
expect(f.prefix).to eq(HOMEBREW_CELLAR/f.name/"0.1")
expect(f.prefix).to be_kind_of(Pathname)
end
example "revised prefix" do
f = Class.new(Testball) { revision(1) }.new
expect(f.prefix).to eq(HOMEBREW_CELLAR/f.name/"0.1_1")
end
specify "#any_version_installed?" do
f = formula do
url "foo"
version "1.0"
end
expect(f).not_to have_any_version_installed
prefix = HOMEBREW_CELLAR/f.name/"0.1"
prefix.mkpath
FileUtils.touch prefix/Tab::FILENAME
expect(f).to have_any_version_installed
end
specify "#migration_needed" do
f = Testball.new("newname")
f.instance_variable_set(:@oldname, "oldname")
f.instance_variable_set(:@tap, CoreTap.instance)
oldname_prefix = (HOMEBREW_CELLAR/"oldname/2.20")
newname_prefix = (HOMEBREW_CELLAR/"newname/2.10")
oldname_prefix.mkpath
oldname_tab = Tab.empty
oldname_tab.tabfile = oldname_prefix/Tab::FILENAME
oldname_tab.write
expect(f).not_to need_migration
oldname_tab.tabfile.unlink
oldname_tab.source["tap"] = "homebrew/core"
oldname_tab.write
expect(f).to need_migration
newname_prefix.mkpath
expect(f).not_to need_migration
end
describe "#latest_version_installed?" do
let(:f) { Testball.new }
it "returns false if the #latest_installed_prefix is not a directory" do
allow(f).to receive(:latest_installed_prefix).and_return(double(directory?: false))
expect(f).not_to be_latest_version_installed
end
it "returns false if the #latest_installed_prefix does not have children" do
allow(f).to receive(:latest_installed_prefix).and_return(double(directory?: true, children: []))
expect(f).not_to be_latest_version_installed
end
it "returns true if the #latest_installed_prefix has children" do
allow(f).to receive(:latest_installed_prefix).and_return(double(directory?: true, children: [double]))
expect(f).to be_latest_version_installed
end
end
describe "#latest_installed_prefix" do
let(:f) do
formula do
url "foo"
version "1.9"
head "foo"
end
end
let(:stable_prefix) { HOMEBREW_CELLAR/f.name/f.version }
let(:head_prefix) { HOMEBREW_CELLAR/f.name/f.head.version }
it "is the same as #prefix by default" do
expect(f.latest_installed_prefix).to eq(f.prefix)
end
it "returns the stable prefix if it is installed" do
stable_prefix.mkpath
expect(f.latest_installed_prefix).to eq(stable_prefix)
end
it "returns the head prefix if it is installed" do
head_prefix.mkpath
expect(f.latest_installed_prefix).to eq(head_prefix)
end
it "returns the stable prefix if head is outdated" do
head_prefix.mkpath
tab = Tab.empty
tab.tabfile = head_prefix/Tab::FILENAME
tab.source["versions"] = { "stable" => "1.0" }
tab.write
expect(f.latest_installed_prefix).to eq(stable_prefix)
end
it "returns the head prefix if the active specification is :head" do
f.active_spec = :head
expect(f.latest_installed_prefix).to eq(head_prefix)
end
end
describe "#latest_head_prefix" do
let(:f) { Testball.new }
it "returns the latest head prefix" do
stamps_with_revisions = [
[111111, 1],
[222222, 0],
[222222, 1],
[222222, 2],
]
stamps_with_revisions.each do |stamp, revision|
version = "HEAD-#{stamp}"
version = "#{version}_#{revision}" unless revision.zero?
prefix = f.rack/version
prefix.mkpath
tab = Tab.empty
tab.tabfile = prefix/Tab::FILENAME
tab.source_modified_time = stamp
tab.write
end
prefix = HOMEBREW_CELLAR/f.name/"HEAD-222222_2"
expect(f.latest_head_prefix).to eq(prefix)
end
end
specify "equality" do
x = Testball.new
y = Testball.new
expect(x).to eq(y)
expect(x).to eql(y)
expect(x.hash).to eq(y.hash)
end
specify "inequality" do
x = Testball.new("foo")
y = Testball.new("bar")
expect(x).not_to eq(y)
expect(x).not_to eql(y)
expect(x.hash).not_to eq(y.hash)
end
specify "comparison with non formula objects does not raise" do
expect(Object.new).not_to eq(Testball.new)
end
specify "#<=>" do
expect(Testball.new <=> Object.new).to be nil
end
describe "#installed_alias_path" do
example "alias paths with build options" do
alias_path = (CoreTap.instance.alias_dir/"another_name")
f = formula alias_path: alias_path do
url "foo-1.0"
end
f.build = BuildOptions.new(Options.new, f.options)
expect(f.alias_path).to eq(alias_path)
expect(f.installed_alias_path).to be nil
end
example "alias paths with tab with non alias source path" do
alias_path = (CoreTap.instance.alias_dir/"another_name")
source_path = (CoreTap.instance.formula_dir/"another_other_name")
f = formula alias_path: alias_path do
url "foo-1.0"
end
f.build = Tab.new(source: { "path" => source_path.to_s })
expect(f.alias_path).to eq(alias_path)
expect(f.installed_alias_path).to be nil
end
example "alias paths with tab with alias source path" do
alias_path = (CoreTap.instance.alias_dir/"another_name")
source_path = (CoreTap.instance.alias_dir/"another_other_name")
f = formula alias_path: alias_path do
url "foo-1.0"
end
f.build = Tab.new(source: { "path" => source_path.to_s })
CoreTap.instance.alias_dir.mkpath
FileUtils.ln_sf f.path, source_path
expect(f.alias_path).to eq(alias_path)
expect(f.installed_alias_path).to eq(source_path.to_s)
end
end
describe "::installed_formulae_with_no_dependents" do
let(:formula_is_dep) do
formula "foo" do
url "foo-1.1"
end
end
let(:formula_with_deps) do
formula "bar" do
url "bar-1.0"
end
end
let(:formulae) do
[
formula_with_deps,
formula_is_dep,
]
end
before do
allow(formula_with_deps).to receive(:runtime_formula_dependencies).and_return([formula_is_dep])
end
specify "without formulae parameter" do
allow(described_class).to receive(:installed).and_return(formulae)
expect(described_class.installed_formulae_with_no_dependents)
.to eq([formula_with_deps])
end
specify "with formulae parameter" do
expect(described_class.installed_formulae_with_no_dependents(formulae))
.to eq([formula_with_deps])
end
end
describe "::installed_with_alias_path" do
specify "with alias path with nil" do
expect(described_class.installed_with_alias_path(nil)).to be_empty
end
specify "with alias path with a path" do
alias_path = "#{CoreTap.instance.alias_dir}/alias"
different_alias_path = "#{CoreTap.instance.alias_dir}/another_alias"
formula_with_alias = formula "foo" do
url "foo-1.0"
end
formula_with_alias.build = Tab.empty
formula_with_alias.build.source["path"] = alias_path
formula_without_alias = formula "bar" do
url "bar-1.0"
end
formula_without_alias.build = Tab.empty
formula_without_alias.build.source["path"] = formula_without_alias.path.to_s
formula_with_different_alias = formula "baz" do
url "baz-1.0"
end
formula_with_different_alias.build = Tab.empty
formula_with_different_alias.build.source["path"] = different_alias_path
formulae = [
formula_with_alias,
formula_without_alias,
formula_with_different_alias,
]
allow(described_class).to receive(:installed).and_return(formulae)
CoreTap.instance.alias_dir.mkpath
FileUtils.ln_sf formula_with_alias.path, alias_path
expect(described_class.installed_with_alias_path(alias_path))
.to eq([formula_with_alias])
end
end
specify "spec integration" do
f = formula do
homepage "https://brew.sh"
url "https://brew.sh/test-0.1.tbz"
mirror "https://example.org/test-0.1.tbz"
sha256 TEST_SHA256
head "https://brew.sh/test.git", tag: "foo"
end
expect(f.homepage).to eq("https://brew.sh")
expect(f.version).to eq(Version.create("0.1"))
expect(f).to be_stable
expect(f.stable.version).to eq(Version.create("0.1"))
expect(f.head.version).to eq(Version.create("HEAD"))
end
specify "#active_spec=" do
f = formula do
url "foo"
version "1.0"
revision 1
end
expect(f.active_spec_sym).to eq(:stable)
expect(f.send(:active_spec)).to eq(f.stable)
expect(f.pkg_version.to_s).to eq("1.0_1")
expect { f.active_spec = :head }.to raise_error(FormulaSpecificationError)
end
specify "class specs are always initialized" do
f = formula do
url "foo-1.0"
end
expect(f.class.stable).to be_kind_of(SoftwareSpec)
expect(f.class.head).to be_kind_of(SoftwareSpec)
end
specify "incomplete instance specs are not accessible" do
f = formula do
url "foo-1.0"
end
expect(f.head).to be nil
end
it "honors attributes declared before specs" do
f = formula do
url "foo-1.0"
depends_on "foo"
end
expect(f.class.stable.deps.first.name).to eq("foo")
expect(f.class.head.deps.first.name).to eq("foo")
end
describe "#pkg_version" do
specify "simple version" do
f = formula do
url "foo-1.0.bar"
end
expect(f.pkg_version).to eq(PkgVersion.parse("1.0"))
end
specify "version with revision" do
f = formula do
url "foo-1.0.bar"
revision 1
end
expect(f.pkg_version).to eq(PkgVersion.parse("1.0_1"))
end
specify "head uses revisions" do
f = formula "test", spec: :head do
url "foo-1.0.bar"
revision 1
head "foo"
end
expect(f.pkg_version).to eq(PkgVersion.parse("HEAD_1"))
end
end
specify "#update_head_version" do
f = formula do
head "foo", using: :git
end
cached_location = f.head.downloader.cached_location
cached_location.mkpath
cached_location.cd do
FileUtils.touch "LICENSE"
system("git", "init")
system("git", "add", "--all")
system("git", "commit", "-m", "Initial commit")
end
f.update_head_version
expect(f.head.version).to eq(Version.create("HEAD-5658946"))
end
specify "#desc" do
f = formula do
desc "a formula"
url "foo-1.0"
end
expect(f.desc).to eq("a formula")
end
specify "test fixtures" do
f1 = formula do
url "foo-1.0"
end
expect(f1.test_fixtures("foo")).to eq(Pathname.new("#{HOMEBREW_LIBRARY_PATH}/test/support/fixtures/foo"))
end
specify "#livecheck" do
f = formula do
url "https://brew.sh/test-1.0.tbz"
livecheck do
skip "foo"
url "https://brew.sh/test/releases"
regex(/test-v?(\d+(?:\.\d+)+)\.t/i)
end
end
expect(f.livecheck.skip?).to be true
expect(f.livecheck.skip_msg).to eq("foo")
expect(f.livecheck.url).to eq("https://brew.sh/test/releases")
expect(f.livecheck.regex).to eq(/test-v?(\d+(?:\.\d+)+)\.t/i)
end
describe "#livecheckable?" do
specify "no livecheck block defined" do
f = formula do
url "https://brew.sh/test-1.0.tbz"
end
expect(f.livecheckable?).to be false
end
specify "livecheck block defined" do
f = formula do
url "https://brew.sh/test-1.0.tbz"
livecheck do
regex(/test-v?(\d+(?:\.\d+)+)\.t/i)
end
end
expect(f.livecheckable?).to be true
end
specify "livecheck references Formula URL" do
f = formula do
homepage "https://brew.sh/test"
url "https://brew.sh/test-1.0.tbz"
livecheck do
url :homepage
regex(/test-v?(\d+(?:\.\d+)+)\.t/i)
end
end
expect(f.livecheck.url).to eq(:homepage)
end
end
specify "dependencies" do
f1 = formula "f1" do
url "f1-1.0"
end
f2 = formula "f2" do
url "f2-1.0"
end
f3 = formula "f3" do
url "f3-1.0"
depends_on "f1" => :build
depends_on "f2"
end
f4 = formula "f4" do
url "f4-1.0"
depends_on "f1"
end
stub_formula_loader(f1)
stub_formula_loader(f2)
stub_formula_loader(f3)
stub_formula_loader(f4)
f5 = formula "f5" do
url "f5-1.0"
depends_on "f3" => :build
depends_on "f4"
end
expect(f5.deps.map(&:name)).to eq(["f3", "f4"])
expect(f5.recursive_dependencies.map(&:name)).to eq(%w[f1 f2 f3 f4])
expect(f5.runtime_dependencies.map(&:name)).to eq(["f1", "f4"])
end
describe "#runtime_dependencies" do
specify "runtime dependencies with optional deps from tap" do
tap_loader = double
allow(tap_loader).to receive(:get_formula).and_raise(RuntimeError, "tried resolving tap formula")
allow(Formulary).to receive(:loader_for).with("foo/bar/f1", from: nil).and_return(tap_loader)
stub_formula_loader(formula("f2") { url("f2-1.0") }, "baz/qux/f2")
f3 = formula "f3" do
url "f3-1.0"
depends_on "foo/bar/f1" => :optional
depends_on "baz/qux/f2"
end
expect(f3.runtime_dependencies.map(&:name)).to eq(["baz/qux/f2"])
stub_formula_loader(formula("f1") { url("f1-1.0") }, "foo/bar/f1")
f3.build = BuildOptions.new(Options.create(["--with-f1"]), f3.options)
expect(f3.runtime_dependencies.map(&:name)).to eq(["foo/bar/f1", "baz/qux/f2"])
end
it "includes non-declared direct dependencies" do
formula = Class.new(Testball).new
dependency = formula("dependency") { url "f-1.0" }
formula.brew { formula.install }
keg = Keg.for(formula.latest_installed_prefix)
keg.link
linkage_checker = double("linkage checker", undeclared_deps: [dependency.name])
allow(LinkageChecker).to receive(:new).and_return(linkage_checker)
expect(formula.runtime_dependencies.map(&:name)).to eq [dependency.name]
end
it "handles bad tab runtime_dependencies" do
formula = Class.new(Testball).new
formula.brew { formula.install }
tab = Tab.create(formula, DevelopmentTools.default_compiler, :libcxx)
tab.runtime_dependencies = ["foo"]
tab.write
keg = Keg.for(formula.latest_installed_prefix)
keg.link
expect(formula.runtime_dependencies.map(&:name)).to be_empty
end
end
specify "requirements" do
f1 = formula "f1" do
url "f1-1"
depends_on xcode: ["1.0", :optional]
end
stub_formula_loader(f1)
xcode = XcodeRequirement.new(["1.0", :optional])
expect(Set.new(f1.recursive_requirements)).to eq(Set[])
f1.build = BuildOptions.new(Options.create(["--with-xcode"]), f1.options)
expect(Set.new(f1.recursive_requirements)).to eq(Set[xcode])
f1.build = f1.stable.build
f2 = formula "f2" do
url "f2-1"
depends_on "f1"
end
expect(Set.new(f2.recursive_requirements)).to eq(Set[])
expect(Set.new(f2.recursive_requirements {})).to eq(Set[xcode])
requirements = f2.recursive_requirements do |_dependent, requirement|
Requirement.prune if requirement.is_a?(XcodeRequirement)
end
expect(Set.new(requirements)).to eq(Set[])
end
specify "#to_hash" do
f1 = formula "foo" do
url "foo-1.0"
bottle do
cellar(:any)
sha256(TEST_SHA256 => Utils::Bottles.tag)
end
end
h = f1.to_hash
expect(h).to be_a(Hash)
expect(h["name"]).to eq("foo")
expect(h["full_name"]).to eq("foo")
expect(h["tap"]).to eq("homebrew/core")
expect(h["versions"]["stable"]).to eq("1.0")
expect(h["versions"]["bottle"]).to be_truthy
end
describe "#eligible_kegs_for_cleanup" do
it "returns Kegs eligible for cleanup" do
f1 = Class.new(Testball) do
version("1.0")
end.new
f2 = Class.new(Testball) do
version("0.2")
version_scheme(1)
end.new
f3 = Class.new(Testball) do
version("0.3")
version_scheme(1)
end.new
f4 = Class.new(Testball) do
version("0.1")
version_scheme(2)
end.new
[f1, f2, f3, f4].each do |f|
f.brew { f.install }
Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write
end
expect(f1).to be_latest_version_installed
expect(f2).to be_latest_version_installed
expect(f3).to be_latest_version_installed
expect(f4).to be_latest_version_installed
expect(f3.eligible_kegs_for_cleanup.sort_by(&:version))
.to eq([f2, f1].map { |f| Keg.new(f.prefix) })
end
specify "with pinned Keg" do
f1 = Class.new(Testball) { version("0.1") }.new
f2 = Class.new(Testball) { version("0.2") }.new
f3 = Class.new(Testball) { version("0.3") }.new
f1.brew { f1.install }
f1.pin
f2.brew { f2.install }
f3.brew { f3.install }
expect(f1.prefix).to eq((HOMEBREW_PINNED_KEGS/f1.name).resolved_path)
expect(f1).to be_latest_version_installed
expect(f2).to be_latest_version_installed
expect(f3).to be_latest_version_installed
expect(f3.eligible_kegs_for_cleanup).to eq([Keg.new(f2.prefix)])
end
specify "with HEAD installed" do
f = formula do
version("0.1")
head("foo")
end
stable_prefix = f.latest_installed_prefix
stable_prefix.mkpath
[["000000_1", 1], ["111111", 2], ["111111_1", 2]].each do |pkg_version_suffix, stamp|
prefix = f.prefix("HEAD-#{pkg_version_suffix}")
prefix.mkpath
tab = Tab.empty
tab.tabfile = prefix/Tab::FILENAME
tab.source_modified_time = stamp
tab.write
end
eligible_kegs = f.installed_kegs - [Keg.new(f.prefix("HEAD-111111_1"))]
expect(f.eligible_kegs_for_cleanup).to eq(eligible_kegs)
end
end
describe "#pour_bottle?" do
it "returns false if set to false" do
f = formula "foo" do
url "foo-1.0"
def pour_bottle?
false
end
end
expect(f).not_to pour_bottle
end
it "returns true if set to true" do
f = formula "foo" do
url "foo-1.0"
def pour_bottle?
true
end
end
expect(f).to pour_bottle
end
it "returns false if set to false via DSL" do
f = formula "foo" do
url "foo-1.0"
pour_bottle? do
reason "false reason"
satisfy { (var == etc) }
end
end
expect(f).not_to pour_bottle
end
it "returns true if set to true via DSL" do
f = formula "foo" do
url "foo-1.0"
pour_bottle? do
reason "true reason"
satisfy { true }
end
end
expect(f).to pour_bottle
end
end
describe "alias changes" do
let(:f) do
formula "formula_name", alias_path: alias_path do
url "foo-1.0"
end
end
let(:new_formula) do
formula "new_formula_name", alias_path: alias_path do
url "foo-1.1"
end
end
let(:tab) { Tab.empty }
let(:alias_path) { "#{CoreTap.instance.alias_dir}/bar" }
before do
allow(described_class).to receive(:installed).and_return([f])
f.build = tab
new_formula.build = tab
end
specify "alias changes when not installed with alias" do
tab.source["path"] = Formulary.core_path(f.name).to_s
expect(f.current_installed_alias_target).to be nil