| 
									
										
										
										
											2017-04-15 22:05:56 +08:00
										 |  |  | require "hardware" | 
					
						
							|  |  |  | require "extend/os/mac/hardware/cpu" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe Hardware::CPU do | 
					
						
							|  |  |  |   describe "::can_run?" do | 
					
						
							|  |  |  |     it "reports that Intel Macs can run Intel executables" do | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       allow(described_class).to receive(:type).and_return :intel | 
					
						
							|  |  |  |       allow(described_class).to receive(:bits).and_return 64
 | 
					
						
							|  |  |  |       expect(described_class.can_run?(:i386)).to be true | 
					
						
							|  |  |  |       expect(described_class.can_run?(:x86_64)).to be true | 
					
						
							| 
									
										
										
										
											2017-04-15 22:05:56 +08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "reports that PowerPC Macs can run PowerPC executables" do | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       allow(described_class).to receive(:type).and_return :ppc | 
					
						
							|  |  |  |       allow(described_class).to receive(:bits).and_return 64
 | 
					
						
							|  |  |  |       expect(described_class.can_run?(:ppc)).to be true | 
					
						
							|  |  |  |       expect(described_class.can_run?(:ppc64)).to be true | 
					
						
							| 
									
										
										
										
											2017-04-15 22:05:56 +08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "reports that 32-bit Intel Macs can't run x86_64 executables" do | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       allow(described_class).to receive(:type).and_return :intel | 
					
						
							|  |  |  |       allow(described_class).to receive(:bits).and_return 32
 | 
					
						
							|  |  |  |       expect(described_class.can_run?(:x86_64)).to be false | 
					
						
							| 
									
										
										
										
											2017-04-15 22:05:56 +08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "reports that 32-bit PowerPC Macs can't run ppc64 executables" do | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       allow(described_class).to receive(:type).and_return :ppc | 
					
						
							|  |  |  |       allow(described_class).to receive(:bits).and_return 32
 | 
					
						
							|  |  |  |       expect(described_class.can_run?(:ppc64)).to be false | 
					
						
							| 
									
										
										
										
											2017-04-15 22:05:56 +08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "reports that Intel Macs can only run 32-bit PowerPC executables on 10.6 and older" do | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       allow(described_class).to receive(:type).and_return :intel | 
					
						
							| 
									
										
										
										
											2017-04-15 22:05:56 +08:00
										 |  |  |       allow(OS::Mac).to receive(:version).and_return OS::Mac::Version.new "10.6" | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       expect(described_class.can_run?(:ppc)).to be true | 
					
						
							| 
									
										
										
										
											2017-04-15 22:05:56 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       allow(OS::Mac).to receive(:version).and_return OS::Mac::Version.new "10.7" | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       expect(described_class.can_run?(:ppc)).to be false | 
					
						
							| 
									
										
										
										
											2017-04-15 22:05:56 +08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "reports that PowerPC Macs can't run Intel executables" do | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       allow(described_class).to receive(:type).and_return :ppc | 
					
						
							|  |  |  |       expect(described_class.can_run?(:i386)).to be false | 
					
						
							|  |  |  |       expect(described_class.can_run?(:x86_64)).to be false | 
					
						
							| 
									
										
										
										
											2017-04-15 22:05:56 +08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns false for unknown CPU types" do | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       allow(described_class).to receive(:type).and_return :dunno | 
					
						
							|  |  |  |       expect(described_class.can_run?(:i386)).to be false | 
					
						
							| 
									
										
										
										
											2017-04-15 22:05:56 +08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns false for unknown arches" do | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       expect(described_class.can_run?(:blah)).to be false | 
					
						
							| 
									
										
										
										
											2017-04-15 22:05:56 +08:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |