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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
|
# frozen_string_literal: true
require 'benchmark'
require 'rubygems/test_case'
require 'date'
require 'pathname'
require 'stringio'
require 'rubygems/ext'
require 'rubygems/specification'
require 'rubygems/installer'
require 'rubygems/platform'
class TestGemSpecification < Gem::TestCase
LEGACY_YAML_SPEC = <<-EOF.freeze
--- !ruby/object:Gem::Specification
rubygems_version: "1.0"
name: keyedlist
version: !ruby/object:Gem::Version
version: 0.4.0
date: 2004-03-28 15:37:49.828000 +02:00
platform:
summary: A Hash which automatically computes keys.
require_paths:
- lib
files:
- lib/keyedlist.rb
autorequire: keyedlist
author: Florian Gross
email: flgr@ccan.de
has_rdoc: true
EOF
LEGACY_RUBY_SPEC = <<-EOF.freeze
Gem::Specification.new do |s|
s.name = %q{keyedlist}
s.version = %q{0.4.0}
s.has_rdoc = true
s.summary = %q{A Hash which automatically computes keys.}
s.files = [%q{lib/keyedlist.rb}]
s.require_paths = [%q{lib}]
s.autorequire = %q{keyedlist}
s.author = %q{Florian Gross}
s.email = %q{flgr@ccan.de}
end
EOF
def make_spec_c1
@c1 = util_spec 'a', '1' do |s|
s.executable = 'exec'
s.extensions << 'ext/a/extconf.rb'
s.test_file = 'test/suite.rb'
s.requirements << 'A working computer'
s.license = 'MIT'
s.add_dependency 'rake', '> 0.4'
s.add_dependency 'jabber4r', '> 0.0.0'
s.add_dependency 'pqa', ['> 0.4', '<= 0.6']
s.mark_version
s.files = %w[lib/code.rb]
end
end
def ext_spec(platform: Gem::Platform::RUBY)
@ext = util_spec 'ext', '1' do |s|
s.executable = 'exec'
s.test_file = 'test/suite.rb'
s.extensions = %w[ext/extconf.rb]
s.license = 'MIT'
s.platform = platform
s.mark_version
s.files = %w[lib/code.rb]
s.installed_by_version = v('2.2')
end
end
def assert_date(date)
assert_kind_of Time, date
assert_equal [0, 0, 0], [date.hour, date.min, date.sec]
assert_operator (Gem::Specification::TODAY..Time.now), :cover?, date
end
def setup
super
# Setting `@default_source_date_epoch` to `nil` effectively resets the
# value used for `Gem.source_date_epoch` whenever `$SOURCE_DATE_EPOCH`
# is not set.
Gem.instance_variable_set(:'@default_source_date_epoch', nil)
@a1 = util_spec 'a', '1' do |s|
s.executable = 'exec'
s.test_file = 'test/suite.rb'
s.requirements << 'A working computer'
s.license = 'MIT'
s.mark_version
s.files = %w[lib/code.rb]
end
@a2 = util_spec 'a', '2' do |s|
s.files = %w[lib/code.rb]
end
@a3 = util_spec 'a', '3' do |s|
s.metadata['allowed_push_host'] = "https://privategemserver.com"
end
@current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
load 'rubygems/syck_hack.rb'
end
def test_self_find_active_stub_by_path
spec = util_spec('a', '1', nil, 'lib/foo.rb')
spec.activated = true
# There used to be a bug (introduced in a9c1aaf) when Gem::Specification
# objects are present in the @stubs collection. This test verifies that
# this scenario works correctly.
Gem::Specification.all = [spec]
assert_equal spec, Gem::Specification.find_active_stub_by_path('foo')
end
def test_self_activate
foo = util_spec 'foo', '1'
assert_activate %w[foo-1], foo
end
def test_self_activate_ambiguous_direct
save_loaded_features do
a1 = util_spec "a", "1", "b" => "> 0"
b1 = util_spec("b", "1", { "c" => ">= 1" }, "lib/d#{$$}.rb")
b2 = util_spec("b", "2", { "c" => ">= 2" }, "lib/d#{$$}.rb")
c1 = util_spec "c", "1"
c2 = util_spec "c", "2"
Gem::Specification.reset
install_specs c1, c2, b1, b2, a1
a1.activate
assert_equal %w[a-1], loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
require "d#{$$}"
assert_equal %w[a-1 b-2 c-2], loaded_spec_names
assert_equal [], unresolved_names
end
end
def test_find_in_unresolved_tree_is_not_exponentiental
save_loaded_features do
num_of_pkg = 7
num_of_version_per_pkg = 3
packages = (0..num_of_pkg).map do |pkgi|
(0..num_of_version_per_pkg).map do |pkg_version|
deps = Hash[((pkgi + 1)..num_of_pkg).map do |deppkgi|
["pkg#{deppkgi}", ">= 0"]
end]
util_spec "pkg#{pkgi}", pkg_version.to_s, deps
end
end
base = util_spec "pkg_base", "1", {"pkg0" => ">= 0"}
Gem::Specification.reset
install_specs(*packages.flatten.reverse)
install_specs base
base.activate
tms = Benchmark.measure do
assert_raises(LoadError) { require 'no_such_file_foo' }
end
assert_operator tms.total, :<=, 10
end
end
def test_self_activate_ambiguous_indirect
save_loaded_features do
a1 = util_spec "a", "1", "b" => "> 0"
b1 = util_spec "b", "1", "c" => ">= 1"
b2 = util_spec "b", "2", "c" => ">= 2"
c1 = util_spec "c", "1", nil, "lib/d#{$$}.rb"
c2 = util_spec "c", "2", nil, "lib/d#{$$}.rb"
install_specs c1, c2, b1, b2, a1
a1.activate
assert_equal %w[a-1], loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
require "d#{$$}"
assert_equal %w[a-1 b-2 c-2], loaded_spec_names
assert_equal [], unresolved_names
end
end
def test_self_activate_ambiguous_indirect_conflict
save_loaded_features do
a1 = util_spec "a", "1", "b" => "> 0"
a2 = util_spec "a", "2", "b" => "> 0"
b1 = util_spec "b", "1", "c" => ">= 1"
b2 = util_spec "b", "2", "c" => ">= 2"
c1 = util_spec "c", "1", nil, "lib/d#{$$}.rb"
c2 = util_spec("c", "2", { "a" => "1" }, "lib/d#{$$}.rb") # conflicts with a-2
install_specs c1, b1, a1, a2, c2, b2
a2.activate
assert_equal %w[a-2], loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
require "d#{$$}"
assert_equal %w[a-2 b-1 c-1], loaded_spec_names
assert_equal [], unresolved_names
end
end
def test_self_activate_ambiguous_unrelated
save_loaded_features do
a1 = util_spec "a", "1", "b" => "> 0"
b1 = util_spec "b", "1", "c" => ">= 1"
b2 = util_spec "b", "2", "c" => ">= 2"
c1 = util_spec "c", "1"
c2 = util_spec "c", "2"
d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb"
install_specs d1, c1, c2, b1, b2, a1
a1.activate
assert_equal %w[a-1], loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
require "d#{$$}"
assert_equal %w[a-1 d-1], loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
end
end
def test_require_should_prefer_latest_gem_level1
save_loaded_features do
a1 = util_spec "a", "1", "b" => "> 0"
b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
b2 = util_spec "b", "2", "c" => ">= 0"
c1 = util_spec "c", "1", nil, "lib/c#{$$}.rb" # 1st level
c2 = util_spec "c", "2", nil, "lib/c#{$$}.rb"
install_specs c1, c2, b1, b2, a1
a1.activate
require "c#{$$}"
assert_equal %w[a-1 b-2 c-2], loaded_spec_names
end
end
def test_require_should_prefer_latest_gem_level2
save_loaded_features do
a1 = util_spec "a", "1", "b" => "> 0"
b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
b2 = util_spec "b", "2", "c" => ">= 0"
c1 = util_spec "c", "1", "d" => ">= 0" # 1st level
c2 = util_spec "c", "2", "d" => ">= 0"
d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
install_specs d1, d2, c1, c2, b1, b2, a1
a1.activate
require "d#{$$}"
assert_equal %w[a-1 b-2 c-2 d-2], loaded_spec_names
end
end
def test_require_finds_in_2nd_level_indirect
save_loaded_features do
a1 = util_spec "a", "1", "b" => "> 0"
b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
b2 = util_spec "b", "2", "c" => ">= 0"
c1 = util_spec "c", "1", "d" => "<= 2" # 1st level
c2 = util_spec "c", "2", "d" => "<= 2"
d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
install_specs d1, d2, d3, c1, c2, b1, b2, a1
a1.activate
require "d#{$$}"
assert_equal %w[a-1 b-2 c-2 d-2], loaded_spec_names
end
end
def test_require_should_prefer_reachable_gems
save_loaded_features do
a1 = util_spec "a", "1", "b" => "> 0"
b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
b2 = util_spec "b", "2", "c" => ">= 0"
c1 = util_spec "c", "1", "d" => "<= 2" # 1st level
c2 = util_spec "c", "2", "d" => "<= 2"
d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
e = util_spec "anti_d", "1", nil, "lib/d#{$$}.rb"
install_specs d1, d2, d3, e, c1, c2, b1, b2, a1
a1.activate
require "d#{$$}"
assert_equal %w[a-1 b-2 c-2 d-2], loaded_spec_names
end
end
def test_require_should_not_conflict
save_loaded_features do
base = util_spec "0", "1", "A" => ">= 1"
a1 = util_spec "A", "1", {"c" => ">= 2", "b" => "> 0"}, "lib/a.rb"
a2 = util_spec "A", "2", {"c" => ">= 2", "b" => "> 0"}, "lib/a.rb"
b1 = util_spec "b", "1", {"c" => "= 1"}, "lib/d#{$$}.rb"
b2 = util_spec "b", "2", {"c" => "= 2"}, "lib/d#{$$}.rb"
c1 = util_spec "c", "1", {}, "lib/c.rb"
c2 = util_spec "c", "2", {}, "lib/c.rb"
c3 = util_spec "c", "3", {}, "lib/c.rb"
install_specs c1, c2, c3, b1, b2, a1, a2, base
base.activate
assert_equal %w[0-1], loaded_spec_names
assert_equal ["A (>= 1)"], unresolved_names
require "d#{$$}"
assert_equal %w[0-1 A-2 b-2 c-2], loaded_spec_names
assert_equal [], unresolved_names
end
end
def test_inner_clonflict_in_indirect_gems
save_loaded_features do
a1 = util_spec "a", "1", "b" => "> 0"
b1 = util_spec "b", "1", "c" => ">= 1" # unresolved
b2 = util_spec "b", "2", "c" => ">= 1", "d" => "< 3"
c1 = util_spec "c", "1", "d" => "<= 2" # 1st level
c2 = util_spec "c", "2", "d" => "<= 2"
c3 = util_spec "c", "3", "d" => "<= 3"
d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
install_specs d1, d2, d3, c1, c2, c3, b1, b2, a1
a1.activate
require "d#{$$}"
assert_includes [%w[a-1 b-2 c-3 d-2],%w[a-1 b-2 d-2]], loaded_spec_names
end
end
def test_inner_clonflict_in_indirect_gems_reversed
save_loaded_features do
a1 = util_spec "a", "1", "b" => "> 0"
b1 = util_spec "b", "1", "xc" => ">= 1" # unresolved
b2 = util_spec "b", "2", "xc" => ">= 1", "d" => "< 3"
c1 = util_spec "xc", "1", "d" => "<= 3" # 1st level
c2 = util_spec "xc", "2", "d" => "<= 2"
c3 = util_spec "xc", "3", "d" => "<= 3"
d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
install_specs d1, d2, d3, c1, c2, c3, b1, b2, a1
a1.activate
require "d#{$$}"
assert_includes [%w[a-1 b-2 d-2 xc-3], %w[a-1 b-2 d-2]], loaded_spec_names
end
end
##
# [A] depends on
# [C] = 1.0 depends on
# [B] = 2.0
# [B] ~> 1.0 (satisfied by 1.0)
def test_self_activate_checks_dependencies
a = util_spec 'a', '1.0'
a.add_dependency 'c', '= 1.0'
a.add_dependency 'b', '~> 1.0'
b1 = util_spec 'b', '1.0'
b2 = util_spec 'b', '2.0'
c = util_spec 'c', '1.0', 'b' => '= 2.0'
install_specs b1, b2, c, a
e = assert_raises Gem::LoadError do
assert_activate nil, a, c, "b"
end
expected = "can't satisfy 'b (~> 1.0)', already activated 'b-2.0'"
assert_equal expected, e.message
end
##
# [A] depends on
# [B] ~> 1.0 (satisfied by 1.0)
# [C] = 1.0 depends on
# [B] = 2.0
def test_self_activate_divergent
a = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0'
b1 = util_spec 'b', '1.0'
b2 = util_spec 'b', '2.0'
c = util_spec 'c', '1.0', 'b' => '= 2.0'
install_specs b1, b2, c, a
e = assert_raises Gem::ConflictError do
assert_activate nil, a, c, "b"
end
assert_match(/Unable to activate c-1.0,/, e.message)
assert_match(/because b-1.0 conflicts with b .= 2.0/, e.message)
end
##
# DOC
def test_self_activate_old_required
e1, = util_spec 'e', '1', 'd' => '= 1'
@d1 = util_spec 'd', '1'
@d2 = util_spec 'd', '2'
install_specs @d1, @d2, e1
assert_activate %w[d-1 e-1], e1, "d"
end
##
# DOC
def test_self_activate_platform_alternate
@x1_m = util_spec 'x', '1' do |s|
s.platform = Gem::Platform.new %w[cpu my_platform 1]
end
@x1_o = util_spec 'x', '1' do |s|
s.platform = Gem::Platform.new %w[cpu other_platform 1]
end
@w1 = util_spec 'w', '1', 'x' => nil
util_set_arch 'cpu-my_platform1'
install_specs @x1_m, @x1_o, @w1
assert_activate %w[x-1-cpu-my_platform-1 w-1], @w1, @x1_m
end
##
# DOC
def test_self_activate_platform_bump
@y1 = util_spec 'y', '1'
@y1_1_p = util_spec 'y', '1.1' do |s|
s.platform = Gem::Platform.new %w[cpu my_platform 1]
end
@z1 = util_spec 'z', '1', 'y' => nil
install_specs @y1, @y1_1_p, @z1
assert_activate %w[y-1 z-1], @z1, @y1
end
##
# [C] depends on
# [A] = 1.a
# [B] = 1.0 depends on
# [A] >= 0 (satisfied by 1.a)
def test_self_activate_prerelease
@c1_pre = util_spec 'c', '1.a', "a" => "1.a", "b" => "1"
@a1_pre = util_spec 'a', '1.a'
@b1 = util_spec 'b', '1' do |s|
s.add_dependency 'a'
s.add_development_dependency 'aa'
end
install_specs @a1_pre, @b1, @c1_pre
assert_activate %w[a-1.a b-1 c-1.a], @c1_pre, @a1_pre, @b1
end
def test_self_activate_via_require
a1 = util_spec "a", "1", "b" => "= 1"
b1 = util_spec "b", "1", nil, "lib/b/c.rb"
b2 = util_spec "b", "2", nil, "lib/b/c.rb"
install_specs b1, b2, a1
a1.activate
save_loaded_features do
require "b/c"
end
assert_equal %w[a-1 b-1], loaded_spec_names
end
def test_self_activate_via_require_wtf
save_loaded_features do
a1 = util_spec "a", "1", "b" => "> 0", "d" => "> 0" # this
b1 = util_spec "b", "1", { "c" => ">= 1" }, "lib/b#{$$}.rb"
b2 = util_spec "b", "2", { "c" => ">= 2" }, "lib/b#{$$}.rb" # this
c1 = util_spec "c", "1"
c2 = util_spec "c", "2" # this
d1 = util_spec "d", "1", { "c" => "< 2" }, "lib/d#{$$}.rb"
d2 = util_spec "d", "2", { "c" => "< 2" }, "lib/d#{$$}.rb" # this
install_specs c1, c2, b1, b2, d1, d2, a1
a1.activate
assert_equal %w[a-1], loaded_spec_names
assert_equal ["b (> 0)", "d (> 0)"], unresolved_names
require "b#{$$}"
e = assert_raises Gem::LoadError do
require "d#{$$}"
end
assert_equal "unable to find a version of 'd' to activate", e.message
assert_equal %w[a-1 b-2 c-2], loaded_spec_names
assert_equal ["d (> 0)"], unresolved_names
end
end
def test_self_activate_deep_unambiguous
a1 = util_spec "a", "1", "b" => "= 1"
b1 = util_spec "b", "1", "c" => "= 1"
b2 = util_spec "b", "2", "c" => "= 2"
c1 = util_spec "c", "1"
c2 = util_spec "c", "2"
install_specs c1, c2, b1, b2, a1
a1.activate
assert_equal %w[a-1 b-1 c-1], loaded_spec_names
end
def test_self_activate_loaded
foo = util_spec 'foo', '1'
assert foo.activate
refute foo.activate
end
##
# [A] depends on
# [B] >= 1.0 (satisfied by 2.0)
# [C] depends on nothing
def test_self_activate_unrelated
a = util_spec 'a', '1.0', 'b' => '>= 1.0'
b = util_spec 'b', '1.0'
c = util_spec 'c', '1.0'
install_specs b, c, a
assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
end
##
# [A] depends on
# [B] >= 1.0 (satisfied by 2.0)
# [C] = 1.0 depends on
# [B] ~> 1.0
#
# and should resolve using b-1.0
# TODO: move these to specification
def test_self_activate_over
a = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '= 1.0'
install_specs util_spec 'b', '1.0'
install_specs util_spec 'b', '1.1'
install_specs util_spec 'b', '2.0'
install_specs util_spec 'c', '1.0', 'b' => '~> 1.0'
install_specs a
a.activate
assert_equal %w[a-1.0 c-1.0], loaded_spec_names
assert_equal ["b (>= 1.0, ~> 1.0)"], unresolved_names
end
##
# [A] depends on
# [B] ~> 1.0 (satisfied by 1.1)
# [C] = 1.0 depends on
# [B] = 1.0
#
# and should resolve using b-1.0
#
# TODO: this is not under, but over... under would require depth
# first resolve through a dependency that is later pruned.
def test_self_activate_under
a = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0'
b1 = util_spec 'b', '1.0'
b1_1 = util_spec 'b', '1.1'
c = util_spec 'c', '1.0', 'b' => '= 1.0'
install_specs b1, b1_1, c, a
assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
end
##
# [A1] depends on
# [B] > 0 (satisfied by 2.0)
# [B1] depends on
# [C] > 0 (satisfied by 1.0)
# [B2] depends on nothing!
# [C1] depends on nothing
def test_self_activate_dropped
a1 = util_spec 'a', '1', 'b' => nil
b1 = util_spec 'b', '1', 'c' => nil
b2 = util_spec 'b', '2'
c1 = util_spec 'c', '1'
install_specs c1, b1, b2, a1
assert_activate %w[b-2 a-1], a1, "b"
end
##
# [A] depends on
# [B] >= 1.0 (satisfied by 1.1) depends on
# [Z]
# [C] >= 1.0 depends on
# [B] = 1.0
#
# and should backtrack to resolve using b-1.0, pruning Z from the
# resolve.
def test_self_activate_raggi_the_edgecase_generator
a = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '>= 1.0'
b1 = util_spec 'b', '1.0'
b1_0 = util_spec 'b', '1.1', 'z' => '>= 1.0'
c = util_spec 'c', '1.0', 'b' => '= 1.0'
z = util_spec 'z', '1'
install_specs z, b1, b1_0, c, z
assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
end
def test_self_activate_conflict
install_specs util_spec 'b', '1.0'
install_specs util_spec 'b', '2.0'
gem "b", "= 1.0"
assert_raises Gem::LoadError do
gem "b", "= 2.0"
end
end
def test_self_all_equals
a = util_spec "foo", "1", nil, "lib/foo.rb"
install_specs a
Gem::Specification.all = [a]
assert_equal a, Gem::Specification.find_inactive_by_path('foo')
end
def test_self_attribute_names
expected_value = %w[
authors
autorequire
bindir
cert_chain
date
dependencies
description
email
executables
extensions
extra_rdoc_files
files
homepage
licenses
metadata
name
platform
post_install_message
rdoc_options
require_paths
required_ruby_version
required_rubygems_version
requirements
rubygems_version
signing_key
specification_version
summary
test_files
version
]
actual_value = Gem::Specification.attribute_names.map {|a| a.to_s }.sort
assert_equal expected_value, actual_value
end
def test_self__load_future
spec = Gem::Specification.new
spec.name = 'a'
spec.version = '1'
spec.specification_version = @current_version + 1
load_spec = Marshal.load Marshal.dump(spec)
assert_equal 'a', load_spec.name
assert_equal Gem::Version.new(1), load_spec.version
assert_equal @current_version, load_spec.specification_version
end
def test_self_from_yaml
@a1.instance_variable_set :@specification_version, nil
spec = Gem::Specification.from_yaml @a1.to_yaml
assert_equal Gem::Specification::NONEXISTENT_SPECIFICATION_VERSION,
spec.specification_version
end
def test_self_from_yaml_syck_date_bug
# This is equivalent to (and totally valid) psych 1.0 output and
# causes parse errors on syck.
yaml = @a1.to_yaml
yaml.sub!(/^date:.*/, "date: 2011-04-26 00:00:00.000000000Z")
spec = with_syck do
Gem::Specification.from_yaml yaml
end
assert_kind_of Time, @a1.date
assert_kind_of Time, spec.date
end
def test_self_from_yaml_syck_default_key_bug
# This is equivalent to (and totally valid) psych 1.0 output and
# causes parse errors on syck.
yaml = <<-YAML
--- !ruby/object:Gem::Specification
name: posix-spawn
version: !ruby/object:Gem::Version
version: 0.3.6
prerelease:
dependencies:
- !ruby/object:Gem::Dependency
name: rake-compiler
requirement: &70243867725240 !ruby/object:Gem::Requirement
none: false
requirements:
- - =
- !ruby/object:Gem::Version
version: 0.7.6
type: :development
prerelease: false
version_requirements: *70243867725240
platform: ruby
files: []
test_files: []
bindir:
YAML
spec = with_syck do
Gem::Specification.from_yaml yaml
end
op = spec.dependencies.first.requirement.requirements.first.first
refute_kind_of YAML::Syck::DefaultKey, op
refute_match %r{DefaultKey}, spec.to_ruby
end
def test_self_from_yaml_cleans_up_defaultkey
yaml = <<-YAML
--- !ruby/object:Gem::Specification
name: posix-spawn
version: !ruby/object:Gem::Version
version: 0.3.6
prerelease:
dependencies:
- !ruby/object:Gem::Dependency
name: rake-compiler
requirement: &70243867725240 !ruby/object:Gem::Requirement
none: false
requirements:
- - !ruby/object:YAML::Syck::DefaultKey {}
- !ruby/object:Gem::Version
version: 0.7.6
type: :development
prerelease: false
version_requirements: *70243867725240
platform: ruby
files: []
test_files: []
bindir:
YAML
spec = Gem::Specification.from_yaml yaml
op = spec.dependencies.first.requirement.requirements.first.first
refute_kind_of YAML::Syck::DefaultKey, op
refute_match %r{DefaultKey}, spec.to_ruby
end
def test_self_from_yaml_cleans_up_defaultkey_from_newer_192
yaml = <<-YAML
--- !ruby/object:Gem::Specification
name: posix-spawn
version: !ruby/object:Gem::Version
version: 0.3.6
prerelease:
dependencies:
- !ruby/object:Gem::Dependency
name: rake-compiler
requirement: &70243867725240 !ruby/object:Gem::Requirement
none: false
requirements:
- - !ruby/object:Syck::DefaultKey {}
- !ruby/object:Gem::Version
version: 0.7.6
type: :development
prerelease: false
version_requirements: *70243867725240
platform: ruby
files: []
test_files: []
bindir:
YAML
spec = Gem::Specification.from_yaml yaml
op = spec.dependencies.first.requirement.requirements.first.first
refute_kind_of YAML::Syck::DefaultKey, op
refute_match %r{DefaultKey}, spec.to_ruby
end
def test_self_from_yaml_cleans_up_Date_objects
yaml = <<-YAML
--- !ruby/object:Gem::Specification
rubygems_version: 0.8.1
specification_version: 1
name: diff-lcs
version: !ruby/object:Gem::Version
version: 1.1.2
date: 2004-10-20
summary: Provides a list of changes that represent the difference between two sequenced collections.
require_paths:
- lib
author: Austin Ziegler
email: diff-lcs@halostatue.ca
homepage: http://rubyforge.org/projects/ruwiki/
description: "Test"
bindir: bin
has_rdoc: true
required_ruby_version: !ruby/object:Gem::Version::Requirement
requirements:
-
- ">="
- !ruby/object:Gem::Version
version: 1.8.1
version:
platform: ruby
files:
- tests/00test.rb
rdoc_options:
- "--title"
- "Diff::LCS -- A Diff Algorithm"
- "--main"
- README
- "--line-numbers"
extra_rdoc_files:
- README
- ChangeLog
- Install
executables:
- ldiff
- htmldiff
extensions: []
requirements: []
dependencies: []
YAML
spec = Gem::Specification.from_yaml yaml
assert_kind_of Time, spec.date
end
def test_self_load
full_path = @a2.spec_file
write_file full_path do |io|
io.write @a2.to_ruby_for_cache
end
spec = Gem::Specification.load full_path
@a2.files.clear
assert_equal @a2, spec
end
def test_self_load_relative
File.open 'a-2.gemspec', 'w' do |io|
io.write @a2.to_ruby_for_cache
end
spec = Gem::Specification.load 'a-2.gemspec'
@a2.files.clear
assert_equal @a2, spec
assert_equal File.join(@tempdir, 'a-2.gemspec'), spec.loaded_from
end
if RUBY_ENGINE == 'ruby' and RUBY_VERSION < '2.7'
def test_self_load_tainted
full_path = @a2.spec_file
write_file full_path do |io|
io.write @a2.to_ruby_for_cache
end
full_path.taint
loader = Thread.new { $SAFE = 1; Gem::Specification.load full_path }
spec = loader.value
@a2.files.clear
assert_equal @a2, spec
ensure
$SAFE = 0
end
end
def test_self_load_escape_curly
@a2.name = 'a};raise "improper escaping";%q{'
full_path = @a2.spec_file
begin
write_file full_path do |io|
io.write @a2.to_ruby_for_cache
end
rescue Errno::EINVAL
skip "cannot create '#{full_path}' on this platform"
end
spec = Gem::Specification.load full_path
@a2.files.clear
assert_equal @a2, spec
end
def test_self_load_escape_interpolation
@a2.name = 'a#{raise %<improper escaping>}'
full_path = @a2.spec_file
begin
write_file full_path do |io|
io.write @a2.to_ruby_for_cache
end
rescue Errno::EINVAL
skip "cannot create '#{full_path}' on this platform"
end
spec = Gem::Specification.load full_path
@a2.files.clear
assert_equal @a2, spec
end
def test_self_load_escape_quote
@a2.name = 'a";raise "improper escaping";"'
full_path = @a2.spec_file
begin
write_file full_path do |io|
io.write @a2.to_ruby_for_cache
end
rescue Errno::EINVAL
skip "cannot create '#{full_path}' on this platform"
end
spec = Gem::Specification.load full_path
@a2.files.clear
assert_equal @a2, spec
end
def test_self_load_utf8_with_ascii_encoding
int_enc = Encoding.default_internal
silence_warnings { Encoding.default_internal = 'US-ASCII' }
spec2 = @a2.dup
bin = "\u5678".dup
spec2.authors = [bin]
full_path = spec2.spec_file
write_file full_path do |io|
io.write spec2.to_ruby_for_cache.force_encoding('BINARY').sub("\\u{5678}", bin.force_encoding('BINARY'))
end
spec = Gem::Specification.load full_path
spec2.files.clear
assert_equal spec2, spec
ensure
silence_warnings { Encoding.default_internal = int_enc }
end
def test_self_load_legacy_ruby
spec = Gem::Deprecate.skip_during do
eval LEGACY_RUBY_SPEC
end
assert_equal 'keyedlist', spec.name
assert_equal '0.4.0', spec.version.to_s
assert_kind_of Time, spec.date
assert spec.required_ruby_version.satisfied_by?(Gem::Version.new('1'))
assert_equal false, spec.has_unit_tests?
end
def test_self_normalize_yaml_input_with_183_yaml
input = "!ruby/object:Gem::Specification "
assert_equal "--- #{input}", Gem::Specification.normalize_yaml_input(input)
end
def test_self_normalize_yaml_input_with_non_183_yaml
input = "--- !ruby/object:Gem::Specification "
assert_equal input, Gem::Specification.normalize_yaml_input(input)
end
def test_self_normalize_yaml_input_with_183_io
input = "!ruby/object:Gem::Specification "
assert_equal "--- #{input}",
Gem::Specification.normalize_yaml_input(StringIO.new(input))
end
def test_self_normalize_yaml_input_with_non_183_io
input = "--- !ruby/object:Gem::Specification "
assert_equal input,
Gem::Specification.normalize_yaml_input(StringIO.new(input))
end
def test_self_normalize_yaml_input_with_192_yaml
input = "--- !ruby/object:Gem::Specification \nblah: !!null \n"
expected = "--- !ruby/object:Gem::Specification \nblah: \n"
assert_equal expected, Gem::Specification.normalize_yaml_input(input)
end
def test_self_outdated
spec_fetcher do |fetcher|
fetcher.download 'a', 4
fetcher.spec 'a', 3
end
assert_equal %w[a], Gem::Specification.outdated
end
def test_self_outdated_and_latest_remotes
specs = spec_fetcher do |fetcher|
fetcher.download 'a', 4
fetcher.download 'b', 3
fetcher.spec 'a', '3.a'
fetcher.spec 'b', 2
end
expected = [
[specs['a-3.a'], v(4)],
[specs['b-2'], v(3)],
]
assert_equal expected, Gem::Specification.outdated_and_latest_version.to_a
end
def test_self_remove_spec
install_specs @a1
assert_includes Gem::Specification.all_names, 'a-1'
assert_includes Gem::Specification.stubs.map {|s| s.full_name }, 'a-1'
uninstall_gem @a1
Gem::Specification.reset
refute_includes Gem::Specification.all_names, 'a-1'
refute_includes Gem::Specification.stubs.map {|s| s.full_name }, 'a-1'
end
def test_self_remove_spec_removed
File.open @a1.spec_file, 'w' do |io|
io.write @a1.to_ruby
end
Gem::Specification.reset
FileUtils.rm @a1.spec_file # bug #698
Gem::Specification.reset
refute_includes Gem::Specification.all_names, 'a-1'
refute_includes Gem::Specification.stubs.map {|s| s.full_name }, 'a-1'
end
def test_self_stubs_for_lazy_loading
Gem.loaded_specs.clear
Gem::Specification.class_variable_set(:@@stubs, nil)
dir_standard_specs = File.join Gem.dir, 'specifications'
save_gemspec('a-1', '1', dir_standard_specs){|s| s.name = 'a' }
save_gemspec('b-1', '1', dir_standard_specs){|s| s.name = 'b' }
assert_equal ['a-1'], Gem::Specification.stubs_for('a').map {|s| s.full_name }
assert_equal 1, Gem::Specification.class_variable_get(:@@stubs_by_name).length
assert_equal ['b-1'], Gem::Specification.stubs_for('b').map {|s| s.full_name }
assert_equal 2, Gem::Specification.class_variable_get(:@@stubs_by_name).length
assert_equal(
Gem::Specification.stubs_for('a').map {|s| s.object_id },
Gem::Specification.stubs_for('a').map {|s| s.object_id }
)
Gem.loaded_specs.delete 'a'
Gem.loaded_specs.delete 'b'
Gem::Specification.class_variable_set(:@@stubs, nil)
end
def test_self_stubs_for_no_lazy_loading_after_all_specs_setup
Gem::Specification.all = [util_spec('a', '1')]
save_gemspec('b-1', '1', File.join(Gem.dir, 'specifications')){|s| s.name = 'b' }
assert_equal [], Gem::Specification.stubs_for('b').map {|s| s.full_name }
end
def test_self_stubs_for_mult_platforms
# gems for two different platforms are installed with --user-install
# the correct one should be returned in the array
orig_platform = Gem.platforms.dup
# create user spec
user_spec_dir = File.join Gem.user_dir, 'specifications'
FileUtils.mkdir_p(user_spec_dir) unless Dir.exist? user_spec_dir
# dirs doesn't include user ?
Gem::Specification.dirs << user_spec_dir
gem = 'mingw'
v = '1.1.1'
platforms = ['x86-mingw32', 'x64-mingw32']
#create specs
platforms.each do |plat|
spec = Gem::Specification.new(gem, v) {|s| s.platform = plat }
File.open File.join(user_spec_dir, "#{gem}-#{v}-#{plat}.gemspec"), 'w' do |io|
io.write spec.to_ruby
end
end
platforms.each do |plat|
cur_plat = Gem::Platform.new plat
Gem.platforms = ['ruby', cur_plat]
Gem::Specification.class_variable_set :@@stubs, nil
Gem::Specification.stubs if plat == platforms.last # test loading via stubs
t = Gem::Specification.stubs_for 'mingw'
assert_equal 1, t.length
assert_equal cur_plat, t.first.platform
end
Gem.platforms = orig_platform
end
def test_self_stubs_returns_only_specified_named_specs
dir_standard_specs = File.join Gem.dir, 'specifications'
save_gemspec('a-1', '1', dir_standard_specs){|s| s.name = 'a' }
save_gemspec('a-2', '2', dir_standard_specs){|s| s.name = 'a' }
save_gemspec('a-a', '3', dir_standard_specs){|s| s.name = 'a-a' }
assert_equal ['a-1', 'a-2'], Gem::Specification.stubs_for('a').map(&:full_name).sort
end
def test_handles_private_null_type
path = File.expand_path "../data/null-type.gemspec.rz", __FILE__
data = Marshal.load Gem::Util.inflate(Gem.read_binary(path))
assert_nil data.signing_key
end
def test_initialize
spec = Gem::Specification.new do |s|
s.name = "blah"
s.version = "1.3.5"
end
assert_equal "blah", spec.name
assert_equal "1.3.5", spec.version.to_s
assert_equal Gem::Platform::RUBY, spec.platform
assert_nil spec.summary
assert_equal [], spec.files
assert_equal [], spec.test_files
assert_equal [], spec.rdoc_options
assert_equal [], spec.extra_rdoc_files
assert_equal [], spec.executables
assert_equal [], spec.extensions
assert_equal [], spec.requirements
assert_equal [], spec.dependencies
assert_equal 'bin', spec.bindir
assert_equal '>= 0', spec.required_ruby_version.to_s
assert_equal '>= 0', spec.required_rubygems_version.to_s
end
def test_initialize_future
version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + 1
spec = Gem::Specification.new do |s|
s.name = "blah"
s.version = "1.3.5"
s.specification_version = version
s.new_unknown_attribute = "a value"
end
assert_equal "blah", spec.name
assert_equal "1.3.5", spec.version.to_s
end
def test_initialize_copy
spec = Gem::Specification.new do |s|
s.name = "blah"
s.version = "1.3.5"
s.summary = 'summary'
s.description = 'description'
s.authors = 'author a', 'author b'
s.licenses = 'BSD-2-Clause'
s.files = 'lib/file.rb'
s.test_files = 'test/file.rb'
s.rdoc_options = '--foo'
s.extra_rdoc_files = 'README.txt'
s.executables = 'exec'
s.extensions = 'ext/extconf.rb'
s.requirements = 'requirement'
s.add_dependency 'some_gem'
end
dup_spec = spec.dup
assert_equal "blah", spec.name
assert_same spec.name, dup_spec.name
assert_equal "1.3.5", spec.version.to_s
assert_same spec.version, dup_spec.version
assert_equal Gem::Platform::RUBY, spec.platform
assert_same spec.platform, dup_spec.platform
assert_equal 'summary', spec.summary
assert_same spec.summary, dup_spec.summary
assert_equal %w[README.txt bin/exec ext/extconf.rb lib/file.rb
test/file.rb].sort,
spec.files
refute_same spec.files, dup_spec.files, 'files'
assert_equal %w[test/file.rb], spec.test_files
refute_same spec.test_files, dup_spec.test_files, 'test_files'
assert_equal %w[--foo], spec.rdoc_options
refute_same spec.rdoc_options, dup_spec.rdoc_options, 'rdoc_options'
assert_equal %w[README.txt], spec.extra_rdoc_files
refute_same spec.extra_rdoc_files, dup_spec.extra_rdoc_files,
'extra_rdoc_files'
assert_equal %w[exec], spec.executables
refute_same spec.executables, dup_spec.executables, 'executables'
assert_equal %w[ext/extconf.rb], spec.extensions
refute_same spec.extensions, dup_spec.extensions, 'extensions'
assert_equal %w[requirement], spec.requirements
refute_same spec.requirements, dup_spec.requirements, 'requirements'
assert_equal [Gem::Dependency.new('some_gem', Gem::Requirement.default)],
spec.dependencies
refute_same spec.dependencies, dup_spec.dependencies, 'dependencies'
assert_equal 'bin', spec.bindir
assert_same spec.bindir, dup_spec.bindir
assert_equal '>= 0', spec.required_ruby_version.to_s
assert_same spec.required_ruby_version, dup_spec.required_ruby_version
assert_equal '>= 0', spec.required_rubygems_version.to_s
assert_same spec.required_rubygems_version,
dup_spec.required_rubygems_version
end
def test_initialize_copy_broken
spec = Gem::Specification.new do |s|
s.name = 'a'
s.version = '1'
end
spec.instance_variable_set :@licenses, (class << (Object.new);self;end)
spec.loaded_from = '/path/to/file'
e = assert_raises Gem::FormatException do
spec.dup
end
assert_equal 'a-1 has an invalid value for @licenses', e.message
assert_equal '/path/to/file', e.file_path
end
def test_initialize_prerelease_version_before_name
spec = Gem::Specification.new do |s|
s.version = '1.0.0.dev'
s.name = 'a'
end
assert_equal "a", spec.name
assert_equal "1.0.0.dev", spec.version.to_s
end
def test__dump
@a2.platform = Gem::Platform.local
@a2.instance_variable_set :@original_platform, 'old_platform'
data = Marshal.dump @a2
same_spec = Marshal.load data
assert_equal 'old_platform', same_spec.original_platform
end
def test_activate
@a2.activate
assert @a2.activated?
end
def test_add_dependency_with_type
gem = util_spec "awesome", "1.0" do |awesome|
awesome.add_dependency true
awesome.add_dependency :gem_name
end
assert_equal %w[true gem_name], gem.dependencies.map {|dep| dep.name }
end
def test_add_dependency_from_existing_dependency
dep = Gem::Dependency.new("existing_dep", Gem::Requirement.new('> 1'), :runtime)
spec = Gem::Specification.new {|s| s.add_dependency dep }
assert_equal dep, spec.dependencies.first
end
def test_add_dependency_with_type_explicit
gem = util_spec "awesome", "1.0" do |awesome|
awesome.add_development_dependency "monkey"
end
monkey = gem.dependencies.detect {|d| d.name == "monkey" }
assert_equal(:development, monkey.type)
end
def test_author
assert_equal 'A User', @a1.author
end
def test_authors
assert_equal ['A User'], @a1.authors
end
def test_bindir_equals
@a1.bindir = 'apps'
assert_equal 'apps', @a1.bindir
end
def test_bindir_equals_nil
@a2.bindir = nil
@a2.executable = 'app'
assert_nil @a2.bindir
assert_equal %w[app lib/code.rb].sort, @a2.files
end
def test_extensions_equals_nil
@a2.instance_variable_set(:@extensions, nil)
assert_nil @a2.instance_variable_get(:@extensions)
assert_equal %w[lib/code.rb], @a2.files
end
def test_test_files_equals_nil
@a2.instance_variable_set(:@test_files, nil)
assert_nil @a2.instance_variable_get(:@test_files)
assert_equal %w[lib/code.rb], @a2.files
end
def test_executables_equals_nil
@a2.instance_variable_set(:@executables, nil)
assert_nil @a2.instance_variable_get(:@executables)
assert_equal %w[lib/code.rb], @a2.files
end
def test_extra_rdoc_files_equals_nil
@a2.instance_variable_set(:@extra_rdoc_files, nil)
assert_nil @a2.instance_variable_get(:@extra_rdoc_files)
assert_equal %w[lib/code.rb], @a2.files
end
def test_build_args
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
assert_empty @ext.build_args
File.open @ext.build_info_file, 'w' do |io|
io.puts
end
assert_empty @ext.build_args
File.open @ext.build_info_file, 'w' do |io|
io.puts '--with-foo-dir=wherever'
end
assert_equal %w[--with-foo-dir=wherever], @ext.build_args
end
def test_build_extensions
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
refute_path_exists @ext.extension_dir, 'sanity check'
refute_empty @ext.extensions, 'sanity check'
extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
FileUtils.mkdir_p File.dirname extconf_rb
File.open extconf_rb, 'w' do |f|
f.write <<-'RUBY'
File.open 'Makefile', 'w' do |f|
f.puts "clean:\n\techo clean"
f.puts "default:\n\techo built"
f.puts "install:\n\techo installed"
end
RUBY
end
@ext.build_extensions
assert_path_exists @ext.extension_dir
end
def test_default_spec_stub_is_marked_default
default = new_default_spec 'default', 2
install_default_gems default
stub = Gem::Specification.stubs.find {|s| s.name == 'default' }
assert_predicate stub, :default_gem?
stub = Gem::Specification.find_all_by_name('default').first
assert_predicate stub, :default_gem?
end
def test_build_extensions_built
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
refute_empty @ext.extensions, 'sanity check'
gem_build_complete =
File.join @ext.extension_dir, 'gem.build_complete'
FileUtils.mkdir_p @ext.extension_dir
FileUtils.touch gem_build_complete
@ext.build_extensions
gem_make_out = File.join @ext.extension_dir, 'gem_make.out'
refute_path_exists gem_make_out
end
def test_build_extensions_default_gem
spec = new_default_spec 'default', 1
spec.extensions << 'extconf.rb'
extconf_rb = File.join spec.gem_dir, spec.extensions.first
FileUtils.mkdir_p File.dirname extconf_rb
File.open extconf_rb, 'w' do |f|
f.write <<-'RUBY'
File.open 'Makefile', 'w' do |f|
f.puts "default:\n\techo built"
f.puts "install:\n\techo installed"
end
RUBY
end
spec.build_extensions
refute_path_exists spec.extension_dir
end
def test_build_extensions_error
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
refute_empty @ext.extensions, 'sanity check'
assert_raises Gem::Ext::BuildError do
@ext.build_extensions
end
end
def test_build_extensions_extensions_dir_unwritable
skip 'chmod not supported' if Gem.win_platform?
skip 'skipped in root privilege' if Process.uid.zero?
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
refute_empty @ext.extensions, 'sanity check'
extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
FileUtils.mkdir_p File.dirname extconf_rb
File.open extconf_rb, 'w' do |f|
f.write <<-'RUBY'
File.open 'Makefile', 'w' do |f|
f.puts "clean:\n\techo clean"
f.puts "default:\n\techo built"
f.puts "install:\n\techo installed"
end
RUBY
end
FileUtils.mkdir_p File.join @ext.base_dir, 'extensions'
FileUtils.chmod 0555, @ext.base_dir
FileUtils.chmod 0555, File.join(@ext.base_dir, 'extensions')
@ext.build_extensions
refute_path_exists @ext.extension_dir
ensure
unless ($DEBUG or win_platform? or Process.uid.zero? or Gem.java_platform?)
FileUtils.chmod 0755, File.join(@ext.base_dir, 'extensions')
FileUtils.chmod 0755, @ext.base_dir
end
end
def test_build_extensions_no_extensions_dir_unwritable
skip 'chmod not supported' if Gem.win_platform?
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
refute_empty @ext.extensions, 'sanity check'
extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
FileUtils.mkdir_p File.dirname extconf_rb
File.open extconf_rb, 'w' do |f|
f.write <<-'RUBY'
File.open 'Makefile', 'w' do |f|
f.puts "clean:\n\techo clean"
f.puts "default:\n\techo built"
f.puts "install:\n\techo installed"
end
RUBY
end
FileUtils.rm_r File.join @gemhome, 'extensions'
FileUtils.chmod 0555, @gemhome
@ext.build_extensions
gem_make_out = File.join @ext.extension_dir, 'gem_make.out'
refute_path_exists gem_make_out
ensure
FileUtils.chmod 0755, @gemhome
end
def test_build_extensions_none
refute_path_exists @a1.extension_dir, 'sanity check'
assert_empty @a1.extensions, 'sanity check'
@a1.build_extensions
refute_path_exists @a1.extension_dir
end
def test_build_extensions_preview
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
FileUtils.mkdir_p File.dirname extconf_rb
File.open extconf_rb, 'w' do |f|
f.write <<-'RUBY'
File.open 'Makefile', 'w' do |f|
f.puts "clean:\n\techo clean"
f.puts "default:\n\techo built"
f.puts "install:\n\techo installed"
end
RUBY
end
refute_empty @ext.extensions, 'sanity check'
@ext.installed_by_version = v('2.2.0.preview.2')
@ext.build_extensions
gem_make_out = File.join @ext.extension_dir, 'gem_make.out'
assert_path_exists gem_make_out
end
def test_contains_requirable_file_eh
code_rb = File.join @a1.gem_dir, 'lib', 'code.rb'
FileUtils.mkdir_p File.dirname code_rb
FileUtils.touch code_rb
assert @a1.contains_requirable_file? 'code'
end
def test_contains_requirable_file_eh_extension
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
_, err = capture_output do
refute @ext.contains_requirable_file? 'nonexistent'
end
expected = "Ignoring ext-1 because its extensions are not built. " +
"Try: gem pristine ext --version 1\n"
assert_equal expected, err
end
def test_contains_requirable_file_eh_extension_java_platform
ext_spec(platform: Gem::Platform.new("java"))
_, err = capture_output do
refute @ext.contains_requirable_file? 'nonexistent'
end
assert_empty err
end
def test_date
assert_date @a1.date
end
def test_date_equals_date
@a1.date = Date.new(2003, 9, 17)
assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_string
@a1.date = '2003-09-17'
assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_string_bad
assert_raises Gem::InvalidSpecificationException do
@a1.date = '9/11/2003'
end
end
def test_date_equals_time
@a1.date = Time.local(2003, 9, 17, 0,0,0)
assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_time_local
@a1.date = Time.local(2003, 9, 17, 19,50,0) # may not pass in utc >= +4
assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_time_utc
@a1.date = Time.utc(2003, 9, 17, 19,50,0)
assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_tolerates_hour_sec_zulu
@a1.date = "2012-01-12 11:22:33.4444444 Z"
assert_equal Time.utc(2012,01,12,0,0,0), @a1.date
end
def test_date_tolerates_hour_sec_and_timezone
@a1.date = "2012-01-12 11:22:33.4444444 +02:33"
assert_equal Time.utc(2012,01,12,0,0,0), @a1.date
end
def test_date_use_env_source_date_epoch
epoch = ENV["SOURCE_DATE_EPOCH"]
ENV["SOURCE_DATE_EPOCH"] = "123456789"
assert_equal Time.utc(1973,11,29,0,0,0), @a1.date
ensure
ENV["SOURCE_DATE_EPOCH"] = epoch
end
def test_dependencies
util_setup_deps
assert_equal [@bonobo, @monkey], @gem.dependencies
end
def test_dependent_gems
util_setup_deps
assert_empty @gem.dependent_gems
bonobo = util_spec 'bonobo', 1
install_gem bonobo
install_gem @gem
expected = [
[@gem, @bonobo, [bonobo]],
]
assert_equal expected, bonobo.dependent_gems
end
def test_doc_dir
assert_equal File.join(@gemhome, 'doc', 'a-1'), @a1.doc_dir
end
def test_doc_dir_type
assert_equal File.join(@gemhome, 'doc', 'a-1', 'ri'), @a1.doc_dir('ri')
end
def test_runtime_dependencies
util_setup_deps
assert_equal [@bonobo], @gem.runtime_dependencies
end
def test_development_dependencies
util_setup_deps
assert_equal [@monkey], @gem.development_dependencies
end
def test_description
assert_equal 'This is a test description', @a1.description
end
def test_eql_eh
g1 = util_spec 'gem', 1
g2 = util_spec 'gem', 1
assert_equal g1, g2
assert_equal g1.hash, g2.hash
assert_equal true, g1.eql?(g2)
end
def test_eql_eh_extensions
spec = @a1.dup
spec.extensions = 'xx'
refute_operator @a1, :eql?, spec
refute_operator spec, :eql?, @a1
end
def test_executables
@a1.executable = 'app'
assert_equal %w[app], @a1.executables
end
def test_executable_equals
@a2.executable = 'app'
assert_equal 'app', @a2.executable
assert_equal %w[bin/app lib/code.rb].sort, @a2.files
end
def test_extensions
assert_equal ['ext/extconf.rb'], ext_spec.extensions
end
def test_extension_dir
enable_shared, RbConfig::CONFIG['ENABLE_SHARED'] =
RbConfig::CONFIG['ENABLE_SHARED'], 'no'
ext_spec
refute_empty @ext.extensions
expected =
File.join(@ext.base_dir, 'extensions', Gem::Platform.local.to_s,
"#{Gem.ruby_api_version}-static", @ext.full_name)
assert_equal expected, @ext.extension_dir
ensure
RbConfig::CONFIG['ENABLE_SHARED'] = enable_shared
end
def test_extension_dir_override
enable_shared, RbConfig::CONFIG['ENABLE_SHARED'] =
RbConfig::CONFIG['ENABLE_SHARED'], 'no'
class << Gem
alias orig_default_ext_dir_for default_ext_dir_for
remove_method :default_ext_dir_for
def Gem.default_ext_dir_for(base_dir)
'elsewhere'
end
end
ext_spec
refute_empty @ext.extensions
expected = File.join @tempdir, 'elsewhere', @ext.full_name
assert_equal expected, @ext.extension_dir
ensure
RbConfig::CONFIG['ENABLE_SHARED'] = enable_shared
class << Gem
remove_method :default_ext_dir_for
alias default_ext_dir_for orig_default_ext_dir_for
end
end
def test_files
@a1.files = %w[files bin/common]
@a1.test_files = %w[test_files bin/common]
@a1.executables = %w[executables common]
@a1.extra_rdoc_files = %w[extra_rdoc_files bin/common]
@a1.extensions = %w[extensions bin/common]
expected = %w[
bin/common
bin/executables
extensions
extra_rdoc_files
files
test_files
]
assert_equal expected, @a1.files
end
def test_files_append
@a1.files = %w[files bin/common]
@a1.test_files = %w[test_files bin/common]
@a1.executables = %w[executables common]
@a1.extra_rdoc_files = %w[extra_rdoc_files bin/common]
@a1.extensions = %w[extensions bin/common]
expected = %w[
bin/common
bin/executables
extensions
extra_rdoc_files
files
test_files
]
assert_equal expected, @a1.files
@a1.files << "generated_file.c"
expected << "generated_file.c"
expected.sort!
assert_equal expected, @a1.files
end
def test_files_duplicate
@a2.files = %w[a b c d b]
@a2.extra_rdoc_files = %w[x y z x]
@a2.normalize
assert_equal %w[a b c d x y z], @a2.files
assert_equal %w[x y z], @a2.extra_rdoc_files
end
def test_files_extra_rdoc_files
@a2.files = %w[a b c d]
@a2.extra_rdoc_files = %w[x y z]
@a2.normalize
assert_equal %w[a b c d x y z], @a2.files
end
def test_files_non_array
@a1.files = "F"
@a1.test_files = "TF"
@a1.executables = "X"
@a1.extra_rdoc_files = "ERF"
@a1.extensions = "E"
assert_equal %w[E ERF F TF bin/X], @a1.files
end
def test_files_non_array_pathological
@a1.instance_variable_set :@files, "F"
@a1.instance_variable_set :@test_files, "TF"
@a1.instance_variable_set :@extra_rdoc_files, "ERF"
@a1.instance_variable_set :@extensions, "E"
@a1.instance_variable_set :@executables, "X"
assert_equal %w[E ERF F TF bin/X], @a1.files
assert_kind_of Integer, @a1.hash
end
def test_for_cache
@a2.add_runtime_dependency 'b', '1'
@a2.dependencies.first.instance_variable_set :@type, nil
@a2.required_rubygems_version = Gem::Requirement.new '> 0'
@a2.test_files = %w[test/test_b.rb]
refute_empty @a2.files
refute_empty @a2.test_files
spec = @a2.for_cache
assert_empty spec.files
assert_empty spec.test_files
refute_empty @a2.files
refute_empty @a2.test_files
end
def test_full_gem_path
assert_equal File.join(@gemhome, 'gems', @a1.full_name), @a1.full_gem_path
@a1.original_platform = 'mswin32'
assert_equal File.join(@gemhome, 'gems', @a1.original_name),
@a1.full_gem_path
end
def test_full_gem_path_double_slash
gemhome = @gemhome.to_s.sub(/\w\//, '\&/')
@a1.loaded_from = File.join gemhome, "specifications", @a1.spec_name
expected = File.join @gemhome, "gems", @a1.full_name
assert_equal expected, @a1.full_gem_path
end
def test_full_name
assert_equal 'a-1', @a1.full_name
@a1 = Gem::Specification.new "a", 1
@a1.platform = Gem::Platform.new ['universal', 'darwin', nil]
assert_equal 'a-1-universal-darwin', @a1.full_name
@a1 = Gem::Specification.new "a", 1
@a1.instance_variable_set :@new_platform, 'mswin32'
assert_equal 'a-1-mswin32', @a1.full_name, 'legacy'
return if win_platform?
@a1 = Gem::Specification.new "a", 1
@a1.platform = 'current'
assert_equal 'a-1-x86-darwin-8', @a1.full_name
end
def test_full_name_windows
test_cases = {
'i386-mswin32' => 'a-1-x86-mswin32-60',
'i386-mswin32_80' => 'a-1-x86-mswin32-80',
'i386-mingw32' => 'a-1-x86-mingw32',
}
test_cases.each do |arch, expected|
@a1 = Gem::Specification.new "a", 1
util_set_arch arch
@a1.platform = 'current'
assert_equal expected, @a1.full_name
end
end
def test_gem_build_complete_path
expected = File.join @a1.extension_dir, 'gem.build_complete'
assert_equal expected, @a1.gem_build_complete_path
end
def test_hash
assert_equal @a1.hash, @a1.hash
assert_equal @a1.hash, @a1.dup.hash
refute_equal @a1.hash, @a2.hash
end
def test_installed_by_version
assert_equal v(0), @a1.installed_by_version
@a1.installed_by_version = Gem.rubygems_version
assert_equal Gem.rubygems_version, @a1.installed_by_version
end
def test_base_dir
assert_equal @gemhome, @a1.base_dir
end
def test_base_dir_not_loaded
@a1.instance_variable_set :@loaded_from, nil
assert_equal Gem.dir, @a1.base_dir
end
def test_base_dir_default
default_dir =
File.join Gem.default_specifications_dir, @a1.spec_name
@a1.instance_variable_set :@loaded_from, default_dir
assert_equal Gem.default_dir, @a1.base_dir
end
def test_lib_files
@a1.files = %w[lib/foo.rb Rakefile]
assert_equal %w[lib/foo.rb], @a1.lib_files
end
def test_license
assert_equal 'MIT', @a1.license
end
def test_licenses
assert_equal ['MIT'], @a1.licenses
end
def test_name
assert_equal 'a', @a1.name
end
def test_original_name
assert_equal 'a-1', @a1.full_name
@a1.platform = 'i386-linux'
@a1.instance_variable_set :@original_platform, 'i386-linux'
assert_equal 'a-1-i386-linux', @a1.original_name
end
def test_platform
assert_equal Gem::Platform::RUBY, @a1.platform
end
def test_platform_change_reset_full_name
orig_full_name = @a1.full_name
@a1.platform = "universal-unknown"
refute_equal orig_full_name, @a1.full_name
end
def test_platform_change_reset_cache_file
orig_cache_file = @a1.cache_file
@a1.platform = "universal-unknown"
refute_equal orig_cache_file, @a1.cache_file
end
def test_platform_equals
@a1.platform = nil
assert_equal Gem::Platform::RUBY, @a1.platform
@a1.platform = Gem::Platform::RUBY
assert_equal Gem::Platform::RUBY, @a1.platform
test_cases = {
'i386-mswin32' => ['x86', 'mswin32', '60'],
'i386-mswin32_80' => ['x86', 'mswin32', '80'],
'i386-mingw32' => ['x86', 'mingw32', nil ],
'x86-darwin8' => ['x86', 'darwin', '8' ],
}
test_cases.each do |arch, expected|
util_set_arch arch
@a1.platform = Gem::Platform::CURRENT
assert_equal Gem::Platform.new(expected), @a1.platform
end
end
def test_platform_equals_current
@a1.platform = Gem::Platform::CURRENT
assert_equal Gem::Platform.local, @a1.platform
assert_equal Gem::Platform.local.to_s, @a1.original_platform
end
def test_platform_equals_legacy
@a1.platform = 'mswin32'
assert_equal Gem::Platform.new('x86-mswin32'), @a1.platform
@a1.platform = 'i586-linux'
assert_equal Gem::Platform.new('x86-linux'), @a1.platform
@a1.platform = 'powerpc-darwin'
assert_equal Gem::Platform.new('ppc-darwin'), @a1.platform
end
def test_prerelease_spec_adds_required_rubygems_version
@prerelease = util_spec('tardis', '2.2.0.a')
refute @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new('1.3.1'))
assert @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new('1.4.0'))
end
def test_require_paths
enable_shared 'no' do
ext_spec
@ext.require_paths = 'lib'
assert_equal [@ext.extension_dir, 'lib'], @ext.require_paths
end
end
def test_require_paths_default_ext_dir_for
class << Gem
send :alias_method, :orig_default_ext_dir_for, :default_ext_dir_for
remove_method :default_ext_dir_for
end
def Gem.default_ext_dir_for(base_dir)
'/foo'
end
enable_shared 'no' do
ext_spec
@ext.require_paths = 'lib'
assert_equal [File.expand_path('/foo/ext-1'), 'lib'], @ext.require_paths
end
ensure
class << Gem
send :remove_method, :default_ext_dir_for
send :alias_method, :default_ext_dir_for, :orig_default_ext_dir_for
send :remove_method, :orig_default_ext_dir_for
end
end
def test_source
assert_kind_of Gem::Source::Installed, @a1.source
end
def test_source_paths
ext_spec
@ext.require_paths = %w[lib ext foo]
@ext.extensions << 'bar/baz'
expected = %w[
lib
ext
foo
bar
]
assert_equal expected, @ext.source_paths
end
def test_full_require_paths
ext_spec
@ext.require_paths = 'lib'
expected = [
File.join(@gemhome, 'gems', @ext.original_name, 'lib'),
@ext.extension_dir,
]
assert_equal expected, @ext.full_require_paths
end
def test_to_fullpath
ext_spec
@ext.require_paths = 'lib'
dir = File.join(@gemhome, 'gems', @ext.original_name, 'lib')
expected_rb = File.join(dir, 'code.rb')
FileUtils.mkdir_p dir
FileUtils.touch expected_rb
dir = @ext.extension_dir
ext = RbConfig::CONFIG["DLEXT"]
expected_so = File.join(dir, "ext.#{ext}")
FileUtils.mkdir_p dir
FileUtils.touch expected_so
assert_nil @ext.to_fullpath("code")
assert_nil @ext.to_fullpath("code.rb")
assert_nil @ext.to_fullpath("code.#{ext}")
assert_nil @ext.to_fullpath("ext")
assert_nil @ext.to_fullpath("ext.rb")
assert_nil @ext.to_fullpath("ext.#{ext}")
@ext.activate
assert_equal expected_rb, @ext.to_fullpath("code")
assert_equal expected_rb, @ext.to_fullpath("code.rb")
assert_nil @ext.to_fullpath("code.#{ext}")
assert_equal expected_so, @ext.to_fullpath("ext")
assert_nil @ext.to_fullpath("ext.rb")
assert_equal expected_so, @ext.to_fullpath("ext.#{ext}")
assert_nil @ext.to_fullpath("notexist")
end
def test_fullpath_return_rb_extension_file_when_exist_the_same_name_file
ext_spec
@ext.require_paths = 'lib'
dir = File.join(@gemhome, 'gems', @ext.original_name, 'lib')
expected_rb = File.join(dir, 'code.rb')
FileUtils.mkdir_p dir
FileUtils.touch expected_rb
dir = @ext.extension_dir
ext = RbConfig::CONFIG["DLEXT"]
expected_so = File.join(dir, "code.#{ext}")
FileUtils.mkdir_p dir
FileUtils.touch expected_so
@ext.activate
assert_equal expected_rb, @ext.to_fullpath("code")
end
def test_require_already_activated
save_loaded_features do
a1 = util_spec "a", "1", nil, "lib/d#{$$}.rb"
install_specs a1 # , a2, b1, b2, c1, c2
a1.activate
assert_equal %w[a-1], loaded_spec_names
assert_equal [], unresolved_names
assert require "d#{$$}"
assert_equal %w[a-1], loaded_spec_names
assert_equal [], unresolved_names
end
end
def test_require_already_activated_indirect_conflict
save_loaded_features do
a1 = util_spec "a", "1", "b" => "> 0"
a2 = util_spec "a", "2", "b" => "> 0"
b1 = util_spec "b", "1", "c" => ">= 1"
b2 = util_spec "b", "2", "c" => ">= 2"
c1 = util_spec "c", "1", nil, "lib/d#{$$}.rb"
c2 = util_spec("c", "2", { "a" => "1" }, "lib/d#{$$}.rb") # conflicts with a-2
install_specs c1, b1, a1, a2, c2, b2
a1.activate
c1.activate
assert_equal %w[a-1 c-1], loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
assert require "d#{$$}"
assert_equal %w[a-1 c-1], loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
end
end
def test_requirements
assert_equal ['A working computer'], @a1.requirements
end
def test_allowed_push_host
assert_nil @a1.metadata['allowed_push_host']
assert_equal 'https://privategemserver.com', @a3.metadata['allowed_push_host']
end
def test_runtime_dependencies_legacy
make_spec_c1
# legacy gems don't have a type
@c1.runtime_dependencies.each do |dep|
dep.instance_variable_set :@type, nil
end
expected = %w[rake jabber4r pqa]
assert_equal expected, @c1.runtime_dependencies.map {|d| d.name }
end
def test_spaceship_name
s1 = util_spec 'a', '1'
s2 = util_spec 'b', '1'
assert_equal(-1, (s1 <=> s2))
assert_equal(0, (s1 <=> s1))
assert_equal(1, (s2 <=> s1))
end
def test_spaceship_platform
s1 = util_spec 'a', '1'
s2 = util_spec 'a', '1' do |s|
s.platform = Gem::Platform.new 'x86-my_platform1'
end
assert_equal(-1, (s1 <=> s2))
assert_equal(0, (s1 <=> s1))
assert_equal(1, (s2 <=> s1))
end
def test_spaceship_version
s1 = util_spec 'a', '1'
s2 = util_spec 'a', '2'
assert_equal(-1, (s1 <=> s2))
assert_equal(0, (s1 <=> s1))
assert_equal(1, (s2 <=> s1))
end
def test_spec_file
assert_equal File.join(@gemhome, 'specifications', 'a-1.gemspec'),
@a1.spec_file
end
def test_spec_name
assert_equal 'a-1.gemspec', @a1.spec_name
end
def test_summary
assert_equal 'this is a summary', @a1.summary
end
def test_test_files
@a1.test_file = 'test/suite.rb'
assert_equal ['test/suite.rb'], @a1.test_files
end
def test_runtime_predicate_true
@a2.add_runtime_dependency 'b', '1'
assert_predicate @a2.dependencies.first, :runtime?
@a2.dependencies.first.instance_variable_set :@type, nil
assert_predicate @a2.dependencies.first, :runtime?
end
def test_runtime_predicate_false
@a2.add_development_dependency 'b', '1'
refute_predicate @a2.dependencies.first, :runtime?
end
def test_to_ruby
@a2.add_runtime_dependency 'b', '1'
@a2.dependencies.first.instance_variable_set :@type, nil
@a2.required_rubygems_version = Gem::Requirement.new '> 0'
@a2.require_paths << 'other'
ruby_code = @a2.to_ruby
expected = <<-SPEC
# -*- encoding: utf-8 -*-
# stub: a 2 ruby lib\0other
Gem::Specification.new do |s|
s.name = "a".freeze
s.version = "2"
s.required_rubygems_version = Gem::Requirement.new(\"> 0\".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze, "other".freeze]
s.authors = ["A User".freeze]
s.date = "#{@a2.date.strftime("%Y-%m-%d")}"
s.description = "This is a test description".freeze
s.email = "example@example.com".freeze
s.files = ["lib/code.rb".freeze]
s.homepage = "http://example.com".freeze
s.rubygems_version = "#{Gem::VERSION}".freeze
s.summary = "this is a summary".freeze
if s.respond_to? :specification_version then
s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
end
if s.respond_to? :add_runtime_dependency then
s.add_runtime_dependency(%q<b>.freeze, [\"= 1\"])
else
s.add_dependency(%q<b>.freeze, [\"= 1\"])
end
end
SPEC
assert_equal expected, ruby_code
same_spec = eval ruby_code
assert_equal @a2, same_spec
end
def test_to_ruby_with_rsa_key
require 'rubygems/openssl'
skip 'openssl is missing' unless defined?(OpenSSL::PKey::RSA)
rsa_key = OpenSSL::PKey::RSA.new(2048)
@a2.signing_key = rsa_key
ruby_code = @a2.to_ruby
expected = <<-SPEC
# -*- encoding: utf-8 -*-
# stub: a 2 ruby lib
Gem::Specification.new do |s|
s.name = "a".freeze
s.version = "2"
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze]
s.authors = ["A User".freeze]
s.date = "#{@a2.date.strftime("%Y-%m-%d")}"
s.description = "This is a test description".freeze
s.email = "example@example.com".freeze
s.files = ["lib/code.rb".freeze]
s.homepage = "http://example.com".freeze
s.rubygems_version = "#{Gem::VERSION}".freeze
s.summary = "this is a summary".freeze
end
SPEC
assert_equal expected, ruby_code
end
def test_to_ruby_for_cache
@a2.add_runtime_dependency 'b', '1'
@a2.dependencies.first.instance_variable_set :@type, nil
@a2.required_rubygems_version = Gem::Requirement.new '> 0'
@a2.installed_by_version = Gem.rubygems_version
# cached specs do not have spec.files populated:
ruby_code = @a2.to_ruby_for_cache
expected = <<-SPEC
# -*- encoding: utf-8 -*-
# stub: a 2 ruby lib
Gem::Specification.new do |s|
s.name = "a".freeze
s.version = "2"
s.required_rubygems_version = Gem::Requirement.new(\"> 0\".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze]
s.authors = ["A User".freeze]
s.date = "#{@a2.date.strftime("%Y-%m-%d")}"
s.description = "This is a test description".freeze
s.email = "example@example.com".freeze
s.homepage = "http://example.com".freeze
s.rubygems_version = "#{Gem::VERSION}".freeze
s.summary = "this is a summary".freeze
s.installed_by_version = "#{Gem::VERSION}" if s.respond_to? :installed_by_version
if s.respond_to? :specification_version then
s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
end
if s.respond_to? :add_runtime_dependency then
s.add_runtime_dependency(%q<b>.freeze, [\"= 1\"])
else
s.add_dependency(%q<b>.freeze, [\"= 1\"])
end
end
SPEC
assert_equal expected, ruby_code
same_spec = eval ruby_code
# cached specs do not have spec.files populated:
@a2.files = []
assert_equal @a2, same_spec
end
def test_to_ruby_fancy
make_spec_c1
@c1.platform = Gem::Platform.local
ruby_code = @c1.to_ruby
local = Gem::Platform.local
expected_platform = "[#{local.cpu.inspect}, #{local.os.inspect}, #{local.version.inspect}]"
stub_require_paths =
@c1.instance_variable_get(:@require_paths).join "\u0000"
extensions = @c1.extensions.join "\u0000"
expected = <<-SPEC
# -*- encoding: utf-8 -*-
# stub: a 1 #{win_platform? ? "x86-mswin32-60" : "x86-darwin-8"} #{stub_require_paths}
# stub: #{extensions}
Gem::Specification.new do |s|
s.name = "a".freeze
s.version = "1"
s.platform = Gem::Platform.new(#{expected_platform})
s.required_rubygems_version = Gem::Requirement.new(\">= 0\".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze]
s.authors = ["A User".freeze]
s.date = "#{@c1.date.strftime("%Y-%m-%d")}"
s.description = "This is a test description".freeze
s.email = "example@example.com".freeze
s.executables = ["exec".freeze]
s.extensions = ["ext/a/extconf.rb".freeze]
s.files = ["bin/exec".freeze, "ext/a/extconf.rb".freeze, "lib/code.rb".freeze, "test/suite.rb".freeze]
s.homepage = "http://example.com".freeze
s.licenses = ["MIT".freeze]
s.requirements = ["A working computer".freeze]
s.rubygems_version = "#{Gem::VERSION}".freeze
s.summary = "this is a summary".freeze
s.test_files = ["test/suite.rb".freeze]
if s.respond_to? :specification_version then
s.specification_version = 4
end
if s.respond_to? :add_runtime_dependency then
s.add_runtime_dependency(%q<rake>.freeze, [\"> 0.4\"])
s.add_runtime_dependency(%q<jabber4r>.freeze, [\"> 0.0.0\"])
s.add_runtime_dependency(%q<pqa>.freeze, [\"> 0.4\", \"<= 0.6\"])
else
s.add_dependency(%q<rake>.freeze, [\"> 0.4\"])
s.add_dependency(%q<jabber4r>.freeze, [\"> 0.0.0\"])
s.add_dependency(%q<pqa>.freeze, [\"> 0.4\", \"<= 0.6\"])
end
end
SPEC
assert_equal expected, ruby_code
same_spec = eval ruby_code
assert_equal @c1, same_spec
end
def test_to_ruby_keeps_requirements_as_originally_specified
spec = util_spec 'a', '1' do |s|
s.add_dependency 'b', ['~> 1.0', '>= 1.0.0']
end
assert_includes spec.to_ruby, '"~> 1.0", ">= 1.0.0"'
end
def test_to_ruby_legacy
gemspec1 = Gem::Deprecate.skip_during do
eval LEGACY_RUBY_SPEC
end
ruby_code = gemspec1.to_ruby
gemspec2 = eval ruby_code
assert_equal gemspec1, gemspec2
end
def test_to_ruby_nested_hash
metadata = {}
metadata[metadata] = metadata
@a2.metadata = metadata
ruby = @a2.to_ruby
assert_match %r%^ s\.metadata = \{ "%, ruby
end
def test_to_ruby_platform
@a2.platform = Gem::Platform.local
@a2.instance_variable_set :@original_platform, 'old_platform'
ruby_code = @a2.to_ruby
same_spec = eval ruby_code
assert_equal 'old_platform', same_spec.original_platform
end
def test_to_yaml
yaml_str = @a1.to_yaml
refute_match %r|!!null|, yaml_str
same_spec = Gem::Specification.from_yaml(yaml_str)
assert_equal @a1, same_spec
end
def test_to_yaml_fancy
@a1.platform = Gem::Platform.local
yaml_str = @a1.to_yaml
same_spec = Gem::Specification.from_yaml(yaml_str)
assert_equal Gem::Platform.local, same_spec.platform
assert_equal @a1, same_spec
end
def test_to_yaml_platform_empty_string
@a1.instance_variable_set :@original_platform, ''
assert_match %r{^platform: ruby$}, @a1.to_yaml
end
def test_to_yaml_platform_legacy
@a1.platform = 'powerpc-darwin7.9.0'
@a1.instance_variable_set :@original_platform, 'powerpc-darwin7.9.0'
yaml_str = @a1.to_yaml
same_spec = YAML.load yaml_str
assert_equal Gem::Platform.new('powerpc-darwin7'), same_spec.platform
assert_equal 'powerpc-darwin7.9.0', same_spec.original_platform
end
def test_to_yaml_platform_nil
@a1.instance_variable_set :@original_platform, nil
assert_match %r{^platform: ruby$}, @a1.to_yaml
end
def test_validate
util_setup_validate
Dir.chdir @tempdir do
assert @a1.validate
end
end
def x(s); s.gsub(/xxx/, ''); end
def w; x "WARxxxNING"; end
def t; x "TOxxxDO"; end
def f; x "FxxxIXME"; end
def test_validate_authors
util_setup_validate
Dir.chdir @tempdir do
@a1.authors = [""]
use_ui @ui do
@a1.validate
end
assert_match "#{w}: no author specified\n", @ui.error, 'error'
@a1.authors = [Object.new]
assert_equal [], @a1.authors
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal "authors may not be empty", e.message
@a1.authors = ["#{f} (who is writing this software)"]
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %("#{f}" or "#{t}" is not an author), e.message
@a1.authors = ["#{t} (who is writing this software)"]
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %("#{f}" or "#{t}" is not an author), e.message
end
end
def test_validate_autorequire
util_setup_validate
Dir.chdir @tempdir do
@a1.autorequire = 'code'
use_ui @ui do
@a1.validate
end
assert_match "#{w}: deprecated autorequire specified\n",
@ui.error, 'error'
end
end
def test_validate_dependencies
util_setup_validate
Dir.chdir @tempdir do
@a1.add_runtime_dependency 'b', '>= 1.0.rc1'
@a1.add_development_dependency 'c', '>= 2.0.rc2'
@a1.add_runtime_dependency 'd', '~> 1.2.3'
@a1.add_runtime_dependency 'e', '~> 1.2.3.4'
@a1.add_runtime_dependency 'g', '~> 1.2.3', '>= 1.2.3.4'
@a1.add_runtime_dependency 'h', '>= 1.2.3', '<= 2'
@a1.add_runtime_dependency 'i', '>= 1.2'
@a1.add_runtime_dependency 'j', '>= 1.2.3'
@a1.add_runtime_dependency 'k', '> 1.2'
@a1.add_runtime_dependency 'l', '> 1.2.3'
@a1.add_runtime_dependency 'm', '~> 2.1.0'
@a1.add_runtime_dependency 'n', '~> 0.1.0'
@a1.add_runtime_dependency 'o'
use_ui @ui do
@a1.validate
end
expected = <<-EXPECTED
#{w}: prerelease dependency on b (>= 1.0.rc1) is not recommended
#{w}: prerelease dependency on c (>= 2.0.rc2, development) is not recommended
#{w}: open-ended dependency on i (>= 1.2) is not recommended
if i is semantically versioned, use:
add_runtime_dependency 'i', '~> 1.2'
#{w}: open-ended dependency on j (>= 1.2.3) is not recommended
if j is semantically versioned, use:
add_runtime_dependency 'j', '~> 1.2', '>= 1.2.3'
#{w}: open-ended dependency on k (> 1.2) is not recommended
if k is semantically versioned, use:
add_runtime_dependency 'k', '~> 1.2', '> 1.2'
#{w}: open-ended dependency on l (> 1.2.3) is not recommended
if l is semantically versioned, use:
add_runtime_dependency 'l', '~> 1.2', '> 1.2.3'
#{w}: open-ended dependency on o (>= 0) is not recommended
use a bounded requirement, such as '~> x.y'
#{w}: See https://guides.rubygems.org/specification-reference/ for help
EXPECTED
assert_equal expected, @ui.error, 'warning'
end
end
def test_validate_dependencies_duplicates
util_setup_validate
Dir.chdir @tempdir do
@a1.add_runtime_dependency 'b', '~> 1.2'
@a1.add_runtime_dependency 'b', '>= 1.2.3'
@a1.add_development_dependency 'c', '~> 1.2'
@a1.add_development_dependency 'c', '>= 1.2.3'
use_ui @ui do
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
expected = <<-EXPECTED
duplicate dependency on b (>= 1.2.3), (~> 1.2) use:
add_runtime_dependency 'b', '>= 1.2.3', '~> 1.2'
duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use:
add_development_dependency 'c', '>= 1.2.3', '~> 1.2'
EXPECTED
assert_equal expected, e.message
end
assert_equal <<-EXPECTED, @ui.error
#{w}: See https://guides.rubygems.org/specification-reference/ for help
EXPECTED
end
end
def test_validate_dependencies_allowed_duplicates
util_setup_validate
Dir.chdir @tempdir do
@a1.add_runtime_dependency 'b', '~> 1.2'
@a1.add_development_dependency 'b', '= 1.2.3'
use_ui @ui do
@a1.validate
end
assert_equal '', @ui.error, 'warning'
end
end
def test_validate_prerelease_dependencies_with_prerelease_version
util_setup_validate
Dir.chdir @tempdir do
@a1.version = '1.0.0.beta.1'
@a1.add_runtime_dependency 'b', '~> 1.2.0.beta.1'
use_ui @ui do
@a1.validate
end
assert_equal '', @ui.error, 'warning'
end
end
def test_validate_rake_extension_have_rake_dependency_warning
util_setup_validate
Dir.chdir @tempdir do
@a1.extensions = ['Rakefile']
File.write File.join(@tempdir, 'Rakefile'), ''
use_ui @ui do
@a1.validate
end
assert_match(/add rake as a dependency/, @ui.error)
end
end
def test_validate_rake_extension_have_rake_dependency_no_warning
util_setup_validate
Dir.chdir @tempdir do
@a1.extensions = ['Rakefile']
@a1.add_runtime_dependency 'rake'
File.write File.join(@tempdir, 'Rakefile'), ''
use_ui @ui do
@a1.validate
end
refute_match(/add rake as a dependency/, @ui.error)
end
end
def test_validate_description
util_setup_validate
Dir.chdir @tempdir do
@a1.description = ''
use_ui @ui do
@a1.validate
end
@ui = Gem::MockGemUi.new
@a1.summary = "this is my summary"
@a1.description = @a1.summary
use_ui @ui do
@a1.validate
end
assert_match "#{w}: description and summary are identical\n",
@ui.error, "error"
@a1.description = "#{f} (describe your package)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %("#{f}" or "#{t}" is not a description), e.message
@a1.description = "#{t} (describe your package)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %("#{f}" or "#{t}" is not a description), e.message
end
end
def test_validate_email
util_setup_validate
Dir.chdir @tempdir do
@a1.email = "FIxxxXME (your e-mail)".sub(/xxx/, "")
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %("#{f}" or "#{t}" is not an email), e.message
@a1.email = "#{t} (your e-mail)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %("#{f}" or "#{t}" is not an email), e.message
end
end
def test_validate_empty
e = assert_raises Gem::InvalidSpecificationException do
Gem::Specification.new.validate
end
assert_equal 'missing value for attribute name', e.message
end
def test_validate_error
assert_raises Gem::InvalidSpecificationException do
use_ui @ui do
Gem::Specification.new.validate
end
end
assert_match 'See https://guides.rubygems.org/specification-reference/ for help', @ui.error
end
def test_validate_executables
util_setup_validate
FileUtils.mkdir_p File.join(@tempdir, 'bin')
File.write File.join(@tempdir, 'bin', 'exec'), ''
FileUtils.mkdir_p File.join(@tempdir, 'exec')
use_ui @ui do
Dir.chdir @tempdir do
assert @a1.validate
end
end
assert_equal %w[exec], @a1.executables
assert_equal '', @ui.output, 'output'
assert_match "#{w}: bin/exec is missing #! line\n", @ui.error, 'error'
end
def test_validate_empty_require_paths
if win_platform?
skip 'test_validate_empty_require_paths skipped on MS Windows (symlink)'
else
util_setup_validate
@a1.require_paths = []
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal 'specification must have at least one require_path',
e.message
end
end
def test_validate_files
skip 'test_validate_files skipped on MS Windows (symlink)' if win_platform?
util_setup_validate
@a1.files += ['lib', 'lib2']
@a1.extensions << 'ext/a/extconf.rb'
Dir.chdir @tempdir do
FileUtils.ln_s 'lib/code.rb', 'lib2' unless vc_windows?
use_ui @ui do
@a1.validate
end
assert_match 'WARNING: lib2 is a symlink, which is not supported on all platforms', @ui.error
end
assert_equal %w[bin/exec ext/a/extconf.rb lib/code.rb lib2 test/suite.rb].sort,
@a1.files
end
def test_unresolved_specs
specification = Gem::Specification.clone
set_orig specification
specification.define_singleton_method(:unresolved_deps) do
{ b: Gem::Dependency.new("x","1") }
end
specification.define_singleton_method(:find_all_by_name) do |dep_name|
[]
end
expected = <<-EXPECTED
WARN: Unresolved or ambiguous specs during Gem::Specification.reset:
x (= 1)
WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'
Please report a bug if this causes problems.
EXPECTED
actual_stdout, actual_stderr = capture_output do
specification.reset
end
assert_empty actual_stdout
assert_equal(expected, actual_stderr)
end
def test_unresolved_specs_with_versions
specification = Gem::Specification.clone
set_orig specification
specification.define_singleton_method(:unresolved_deps) do
{ b: Gem::Dependency.new("x","1") }
end
specification.define_singleton_method(:find_all_by_name) do |dep_name|
[
specification.new {|s| s.name = "z", s.version = Gem::Version.new("1") },
specification.new {|s| s.name = "z", s.version = Gem::Version.new("2") },
]
end
expected = <<-EXPECTED
WARN: Unresolved or ambiguous specs during Gem::Specification.reset:
x (= 1)
Available/installed versions of this gem:
- 1
- 2
WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'
Please report a bug if this causes problems.
EXPECTED
actual_stdout, actual_stderr = capture_output do
specification.reset
end
assert_empty actual_stdout
assert_equal(expected, actual_stderr)
end
def test_duplicate_runtime_dependency
expected = "WARNING: duplicated b dependency [\"~> 3.0\", \"~> 3.0\"]\n"
assert_output nil, expected do
@a1.add_runtime_dependency "b", "~> 3.0", "~> 3.0"
end
end
def set_orig(cls)
s_cls = cls.singleton_class
s_cls.send :alias_method, :orig_unresolved_deps , :unresolved_deps
s_cls.send :alias_method, :orig_find_all_by_name, :find_all_by_name
end
def test_validate_files_recursive
util_setup_validate
FileUtils.touch @a1.file_name
@a1.files = [@a1.file_name]
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal "#{@a1.full_name} contains itself (#{@a1.file_name}), check your files list",
e.message
end
def test_validate_homepage
util_setup_validate
Dir.chdir @tempdir do
@a1.homepage = nil
use_ui @ui do
@a1.validate
end
assert_match "#{w}: no homepage specified\n", @ui.error, 'error'
@ui = Gem::MockGemUi.new
@a1.homepage = ''
use_ui @ui do
@a1.validate
end
assert_match "#{w}: no homepage specified\n", @ui.error, 'error'
@a1.homepage = 'over at my cool site'
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal '"over at my cool site" is not a valid HTTP URI', e.message
@a1.homepage = 'ftp://rubygems.org'
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal '"ftp://rubygems.org" is not a valid HTTP URI', e.message
@a1.homepage = 'https://rubygems.org/'
assert_equal true, @a1.validate
@a1.homepage = 'https://rubygems.org'
assert_equal true, @a1.validate
end
end
def test_validate_license
util_setup_validate
use_ui @ui do
@a1.licenses.clear
@a1.validate
end
assert_match <<-WARNING, @ui.error
WARNING: licenses is empty, but is recommended. Use a license identifier from
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
WARNING
end
def test_validate_license_in_a_non_packaging_context
util_setup_validate
use_ui @ui do
@a1.licenses.clear
@a1.validate(false)
end
assert_empty @ui.error
end
def test_removed_methods
assert_equal Gem::Specification::REMOVED_METHODS, [:rubyforge_project=]
end
def test_validate_removed_rubyforge_project
util_setup_validate
use_ui @ui do
@a1.rubyforge_project = 'invalid-attribute'
@a1.validate
end
assert_match "rubyforge_project= is deprecated", @ui.error
end
def test_validate_license_values
util_setup_validate
use_ui @ui do
@a1.licenses = ['BSD']
@a1.validate
end
assert_match <<-WARNING, @ui.error
WARNING: license value 'BSD' is invalid. Use a license identifier from
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
WARNING
end
def test_validate_license_values_plus
util_setup_validate
use_ui @ui do
@a1.licenses = ['GPL-2.0+']
@a1.validate
end
assert_empty @ui.error
end
def test_validate_license_values_or_later
util_setup_validate
use_ui @ui do
@a1.licenses = ['GPL-2.0-or-later']
@a1.validate
end
assert_empty @ui.error
end
def test_validate_license_values_with
util_setup_validate
use_ui @ui do
@a1.licenses = ['GPL-2.0+ WITH Autoconf-exception-2.0']
@a1.validate
end
assert_empty @ui.error
end
def test_validate_license_with_nonsense_suffix
util_setup_validate
use_ui @ui do
@a1.licenses = ['GPL-2.0+ FOO', 'GPL-2.0 FOO']
@a1.validate
end
assert_match <<-WARNING, @ui.error
WARNING: license value 'GPL-2.0+ FOO' is invalid. Use a license identifier from
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
WARNING
assert_match <<-WARNING, @ui.error
WARNING: license value 'GPL-2.0 FOO' is invalid. Use a license identifier from
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
WARNING
end
def test_validate_license_with_invalid_exception
util_setup_validate
use_ui @ui do
@a1.licenses = ['GPL-2.0+ WITH Autocofn-exception-2.0']
@a1.validate
end
assert_match <<-WARNING, @ui.error
WARNING: license value 'GPL-2.0+ WITH Autocofn-exception-2.0' is invalid. Use a license identifier from
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
WARNING
end
def test_validate_license_gives_suggestions
util_setup_validate
use_ui @ui do
@a1.licenses = ['ruby']
@a1.validate
end
assert_match <<-WARNING, @ui.error
WARNING: license value 'ruby' is invalid. Use a license identifier from
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
Did you mean 'Ruby'?
WARNING
end
def test_validate_empty_files
util_setup_validate
use_ui @ui do
# we have to set all of these for #files to be empty
@a1.files = []
@a1.test_files = []
@a1.executables = []
@a1.validate
end
assert_match "no files specified", @ui.error
end
def test_validate_empty_homepage
util_setup_validate
use_ui @ui do
@a1.homepage = nil
@a1.validate
end
assert_match "no homepage specified", @ui.error
end
def test_validate_empty_summary
util_setup_validate
use_ui @ui do
@a1.summary = nil
@a1.validate
end
assert_match "no summary specified", @ui.error
end
def test_validate_name
util_setup_validate
e = assert_raises Gem::InvalidSpecificationException do
@a1.name = :json
@a1.validate
end
assert_equal 'invalid value for attribute name: ":json" must be a string', e.message
@a1.name = []
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal "invalid value for attribute name: \"[]\" must be a string", e.message
@a1.name = ""
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal "invalid value for attribute name: \"\" must include at least one letter", e.message
@a1.name = "12345"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal "invalid value for attribute name: \"12345\" must include at least one letter", e.message
@a1.name = "../malicious"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal "invalid value for attribute name: \"../malicious\" can only include letters, numbers, dashes, and underscores", e.message
@a1.name = "\ba\t"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal "invalid value for attribute name: \"\\ba\\t\" can only include letters, numbers, dashes, and underscores", e.message
end
def test_validate_non_nil
util_setup_validate
Dir.chdir @tempdir do
assert @a1.validate
Gem::Specification.non_nil_attributes.each do |name|
next if name == :files # set by #normalize
spec = @a1.dup
spec.instance_variable_set "@#{name}", nil
e = assert_raises Gem::InvalidSpecificationException do
spec.validate
end
assert_match %r{^#{name}}, e.message
end
end
end
def test_validate_permissions
skip 'chmod not supported' if Gem.win_platform?
util_setup_validate
Dir.chdir @tempdir do
File.chmod 0640, File.join('lib', 'code.rb')
File.chmod 0640, File.join('bin', 'exec')
use_ui @ui do
@a1.validate
end
assert_match "#{w}: lib/code.rb is not world-readable\n", @ui.error
assert_match "#{w}: bin/exec is not world-readable\n", @ui.error
assert_match "#{w}: bin/exec is not executable\n", @ui.error
end
end
def test_validate_permissions_of_missing_file_non_packaging
skip 'chmod not supported' if Gem.win_platform?
util_setup_validate
Dir.chdir @tempdir do
File.delete File.join('lib', 'code.rb')
use_ui @ui do
assert @a1.validate(false)
end
end
end
def test_validate_platform_legacy
util_setup_validate
Dir.chdir @tempdir do
@a1.platform = 'mswin32'
assert @a1.validate
@a1.platform = 'i586-linux'
assert @a1.validate
@a1.platform = 'powerpc-darwin'
assert @a1.validate
end
end
def test_validate_rubygems_version
util_setup_validate
@a1.rubygems_version = "3"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal "expected RubyGems version #{Gem::VERSION}, was 3",
e.message
end
def test_validate_specification_version
util_setup_validate
Dir.chdir @tempdir do
@a1.specification_version = '1.0'
e = assert_raises Gem::InvalidSpecificationException do
use_ui @ui do
@a1.validate
end
end
err = 'specification_version must be an Integer (did you mean version?)'
assert_equal err, e.message
end
end
def test_validate_summary
util_setup_validate
Dir.chdir @tempdir do
@a1.summary = ''
use_ui @ui do
@a1.validate
end
assert_match "#{w}: no summary specified\n", @ui.error, 'error'
@a1.summary = "#{f} (describe your package)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %("#{f}" or "#{t}" is not a summary), e.message
@a1.summary = "#{t} (describe your package)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal %("#{f}" or "#{t}" is not a summary), e.message
end
end
def test_validate_warning
util_setup_validate
use_ui @ui do
@a1.licenses.clear
@a1.validate
end
assert_match 'See https://guides.rubygems.org/specification-reference/ for help', @ui.error
end
def test_version
assert_equal Gem::Version.new('1'), @a1.version
end
def test_version_change_reset_full_name
orig_full_name = @a1.full_name
@a1.version = "2"
refute_equal orig_full_name, @a1.full_name
end
def test_version_change_reset_cache_file
orig_cache_file = @a1.cache_file
@a1.version = "2"
refute_equal orig_cache_file, @a1.cache_file
end
def test__load_fixes_Date_objects
spec = util_spec "a", 1
spec.instance_variable_set :@date, Date.today
spec = Marshal.load Marshal.dump(spec)
assert_kind_of Time, spec.date
end
def test_load_errors_contain_filename
specfile = Tempfile.new(self.class.name.downcase)
specfile.write "raise 'boom'"
specfile.close
begin
capture_output do
Gem::Specification.load(specfile.path)
end
rescue => e
name_rexp = Regexp.new(Regexp.escape(specfile.path))
assert e.backtrace.grep(name_rexp).any?
end
ensure
specfile.delete
end
def test_latest_specs
spec_fetcher do |fetcher|
fetcher.spec 'a', 1 do |s|
s.platform = Gem::Platform.new 'x86-my_platform1'
end
fetcher.spec 'a', 2
fetcher.spec 'a', 2 do |s|
s.platform = Gem::Platform.new 'x86-my_platform1'
end
fetcher.spec 'a', 2 do |s|
s.platform = Gem::Platform.new 'x86-other_platform1'
end
fetcher.spec 'a', 3 do |s|
s.platform = Gem::Platform.new 'x86-other_platform1'
end
end
expected = %W[
a-3-x86-other_platform-1
]
latest_specs = Gem::Specification.latest_specs.map(&:full_name).sort
assert_equal expected, latest_specs
end
def test_metadata_validates_ok
util_setup_validate
Dir.chdir @tempdir do
@m1 = quick_gem 'm', '1' do |s|
s.files = %w[lib/code.rb]
s.metadata = {
"one" => "two",
"home" => "three",
"homepage_uri" => "https://example.com/user/repo",
"funding_uri" => "https://example.com/donate",
}
end
use_ui @ui do
@m1.validate
end
end
end
def test_metadata_key_type_validation_fails
util_setup_validate
Dir.chdir @tempdir do
@m2 = quick_gem 'm', '2' do |s|
s.files = %w[lib/code.rb]
s.metadata = { 1 => "fail" }
end
e = assert_raises Gem::InvalidSpecificationException do
@m2.validate
end
assert_equal "metadata keys must be a String", e.message
end
end
def test_metadata_key_size_validation_fails
util_setup_validate
Dir.chdir @tempdir do
@m2 = quick_gem 'm', '2' do |s|
s.files = %w[lib/code.rb]
s.metadata = { ("x" * 129) => "fail" }
end
e = assert_raises Gem::InvalidSpecificationException do
@m2.validate
end
assert_equal "metadata key too large (129 > 128)", e.message
end
end
def test_metadata_value_type_validation_fails
util_setup_validate
Dir.chdir @tempdir do
@m2 = quick_gem 'm', '2' do |s|
s.files = %w[lib/code.rb]
s.metadata = { 'fail' => [] }
end
e = assert_raises Gem::InvalidSpecificationException do
@m2.validate
end
assert_equal "metadata values must be a String", e.message
end
end
def test_metadata_value_size_validation_fails
util_setup_validate
Dir.chdir @tempdir do
@m2 = quick_gem 'm', '2' do |s|
s.files = %w[lib/code.rb]
s.metadata = { 'fail' => ("x" * 1025) }
end
e = assert_raises Gem::InvalidSpecificationException do
@m2.validate
end
assert_equal "metadata value too large (1025 > 1024)", e.message
end
end
def test_metadata_link_validation_fails
util_setup_validate
Dir.chdir @tempdir do
@m2 = quick_gem 'm', '2' do |s|
s.files = %w[lib/code.rb]
s.metadata = { 'homepage_uri' => 'http:/example.com' }
end
e = assert_raises Gem::InvalidSpecificationException do
@m2.validate
end
assert_equal "metadata['homepage_uri'] has invalid link: \"http:/example.com\"", e.message
end
end
def test_metadata_specs
@m1 = quick_gem 'm', '1' do |s|
s.files = %w[lib/code.rb]
s.metadata = { 'one' => "two", 'two' => "three" }
end
valid_ruby_spec = <<-EOF
# -*- encoding: utf-8 -*-
# stub: m 1 ruby lib
Gem::Specification.new do |s|
s.name = "m".freeze
s.version = "1"
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
s.metadata = { "one" => "two", "two" => "three" } if s.respond_to? :metadata=
s.require_paths = ["lib".freeze]
s.authors = ["A User".freeze]
s.date = "#{@m1.date.strftime("%Y-%m-%d")}"
s.description = "This is a test description".freeze
s.email = "example@example.com".freeze
s.files = ["lib/code.rb".freeze]
s.homepage = "http://example.com".freeze
s.rubygems_version = "#{Gem::VERSION}".freeze
s.summary = "this is a summary".freeze
end
EOF
assert_equal @m1.to_ruby, valid_ruby_spec
end
def test_missing_extensions_eh
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
assert @ext.missing_extensions?
extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
FileUtils.mkdir_p File.dirname extconf_rb
File.open extconf_rb, 'w' do |f|
f.write <<-'RUBY'
File.open 'Makefile', 'w' do |f|
f.puts "clean:\n\techo clean"
f.puts "default:\n\techo built"
f.puts "install:\n\techo installed"
end
RUBY
end
@ext.build_extensions
refute @ext.missing_extensions?
end
def test_missing_extensions_eh_default_gem
spec = new_default_spec 'default', 1
spec.extensions << 'extconf.rb'
refute spec.missing_extensions?
end
def test_missing_extensions_eh_none
refute @a1.missing_extensions?
end
def test_find_all_by_full_name
pl = Gem::Platform.new 'i386-linux'
a1 = util_spec "a", "1"
a1_pre = util_spec "a", "1.0.0.pre.1"
a_1_platform = util_spec("a", "1") {|s| s.platform = pl }
a_b_1 = util_spec "a-b", "1"
a_b_1_platform = util_spec("a-b", "1") {|s| s.platform = pl }
a_b_1_1 = util_spec "a-b-1", "1"
a_b_1_1_platform = util_spec("a-b-1", "1") {|s| s.platform = pl }
install_specs(a1, a1_pre, a_1_platform, a_b_1, a_b_1_platform,
a_b_1_1, a_b_1_1_platform)
assert_equal [a1], Gem::Specification.find_all_by_full_name("a-1")
assert_equal [a1_pre], Gem::Specification.find_all_by_full_name("a-1.0.0.pre.1")
assert_equal [a_1_platform], Gem::Specification.find_all_by_full_name("a-1-x86-linux")
assert_equal [a_b_1_1], Gem::Specification.find_all_by_full_name("a-b-1-1")
assert_equal [a_b_1_1_platform], Gem::Specification.find_all_by_full_name("a-b-1-1-x86-linux")
assert_equal [], Gem::Specification.find_all_by_full_name("monkeys")
assert_equal [], Gem::Specification.find_all_by_full_name("a-1-foo")
end
def test_find_by_name
install_specs util_spec "a"
install_specs util_spec "a", 1
assert Gem::Specification.find_by_name "a"
assert Gem::Specification.find_by_name "a", "1"
assert Gem::Specification.find_by_name "a", ">1"
assert_raises Gem::MissingSpecError do
Gem::Specification.find_by_name "monkeys"
end
end
def test_find_by_name_with_only_prereleases
q = util_spec "q", "2.a"
install_specs q
assert Gem::Specification.find_by_name "q"
end
def test_find_by_name_prerelease
b = util_spec "b", "2.a"
b.activate
install_specs b
assert Gem::Specification.find_by_name "b"
assert_raises Gem::MissingSpecVersionError do
Gem::Specification.find_by_name "b", "1"
end
assert Gem::Specification.find_by_name "b", ">1"
end
def test_find_by_path
a = util_spec "foo", "1", nil, "lib/foo.rb"
install_specs a
assert_equal a, Gem::Specification.find_by_path('foo')
a.activate
assert_equal a, Gem::Specification.find_by_path('foo')
end
def test_find_inactive_by_path
a = util_spec "foo", "1", nil, "lib/foo.rb"
install_specs a
assert_equal a, Gem::Specification.find_inactive_by_path('foo')
a.activate
assert_nil Gem::Specification.find_inactive_by_path('foo')
end
def test_load_default_gem
Gem::Specification.reset
assert_equal [], Gem::Specification.map(&:full_name)
default_gem_spec = new_default_spec("default", "2.0.0.0",
nil, "default/gem.rb")
spec_path = File.join(@gemhome, "specifications", "default", default_gem_spec.spec_name)
write_file(spec_path) do |file|
file.print(default_gem_spec.to_ruby)
end
Gem::Specification.reset
assert_equal ["default-2.0.0.0"], Gem::Specification.map(&:full_name)
end
def util_setup_deps
@gem = util_spec "awesome", "1.0" do |awesome|
awesome.add_runtime_dependency "bonobo", []
awesome.add_development_dependency "monkey", []
end
@bonobo = Gem::Dependency.new("bonobo", [])
@monkey = Gem::Dependency.new("monkey", [], :development)
end
def util_setup_validate
Dir.chdir @tempdir do
FileUtils.mkdir_p File.join("ext", "a")
FileUtils.mkdir_p "lib"
FileUtils.mkdir_p "test"
FileUtils.mkdir_p "bin"
begin
umask_orig = File.umask(2)
FileUtils.touch File.join("ext", "a", "extconf.rb")
FileUtils.touch File.join("lib", "code.rb")
FileUtils.touch File.join("test", "suite.rb")
File.open "bin/exec", "w", 0755 do |fp|
fp.puts "#!#{Gem.ruby}"
end
ensure
File.umask(umask_orig)
end
end
end
def with_syck
begin
verbose, $VERBOSE = $VERBOSE, nil
require "yaml"
old_engine = YAML::ENGINE.yamler
YAML::ENGINE.yamler = 'syck'
load 'rubygems/syck_hack.rb'
rescue NameError
# probably on 1.8, ignore
ensure
$VERBOSE = verbose
end
yield
ensure
begin
YAML::ENGINE.yamler = old_engine
load 'rubygems/syck_hack.rb'
rescue NameError
# ignore
end
end
def with_psych
begin
require "yaml"
old_engine = YAML::ENGINE.yamler
YAML::ENGINE.yamler = 'psych'
load 'rubygems/syck_hack.rb'
rescue NameError
# probably on 1.8, ignore
end
yield
ensure
begin
YAML::ENGINE.yamler = old_engine
load 'rubygems/syck_hack.rb'
rescue NameError
# ignore
end
end
def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, false
yield
ensure
$VERBOSE = old_verbose
end
end
|