| 
									
										
										
										
											2019-06-26 21:12:00 -04:00
										 |  |  | import io = require('@actions/io'); | 
					
						
							|  |  |  | import fs = require('fs'); | 
					
						
							|  |  |  | import path = require('path'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const toolDir = path.join( | 
					
						
							| 
									
										
										
										
											2019-07-11 17:12:03 -04:00
										 |  |  |   __dirname, | 
					
						
							| 
									
										
										
										
											2019-06-26 21:12:00 -04:00
										 |  |  |   'runner', | 
					
						
							|  |  |  |   path.join( | 
					
						
							|  |  |  |     Math.random() | 
					
						
							|  |  |  |       .toString(36) | 
					
						
							|  |  |  |       .substring(7) | 
					
						
							|  |  |  |   ), | 
					
						
							|  |  |  |   'tools' | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | const tempDir = path.join( | 
					
						
							| 
									
										
										
										
											2019-07-11 17:12:03 -04:00
										 |  |  |   __dirname, | 
					
						
							| 
									
										
										
										
											2019-06-26 21:12:00 -04:00
										 |  |  |   'runner', | 
					
						
							|  |  |  |   path.join( | 
					
						
							|  |  |  |     Math.random() | 
					
						
							|  |  |  |       .toString(36) | 
					
						
							|  |  |  |       .substring(7) | 
					
						
							|  |  |  |   ), | 
					
						
							|  |  |  |   'temp' | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | process.env['RUNNER_TOOLSDIRECTORY'] = toolDir; | 
					
						
							|  |  |  | process.env['RUNNER_TEMPDIRECTORY'] = tempDir; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import * as finder from '../src/find-python'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('Finder tests', () => { | 
					
						
							| 
									
										
										
										
											2019-06-27 11:40:43 -04:00
										 |  |  |   it('Finds Python if it is installed', async () => { | 
					
						
							| 
									
										
										
										
											2019-07-11 17:04:02 -04:00
										 |  |  |     const pythonDir: string = path.join(toolDir, 'Python', '3.0.0', 'x64'); | 
					
						
							| 
									
										
										
										
											2019-06-27 11:40:43 -04:00
										 |  |  |     await io.mkdirP(pythonDir); | 
					
						
							|  |  |  |     fs.writeFileSync(`${pythonDir}.complete`, 'hello'); | 
					
						
							|  |  |  |     // This will throw if it doesn't find it in the cache (because no such version exists)
 | 
					
						
							| 
									
										
										
										
											2019-07-11 17:00:39 -04:00
										 |  |  |     await finder.findPythonVersion('3.x', 'x64'); | 
					
						
							| 
									
										
										
										
											2019-06-27 11:40:43 -04:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-06-26 21:12:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-27 11:40:43 -04:00
										 |  |  |   it('Errors if Python is not installed', async () => { | 
					
						
							|  |  |  |     // This will throw if it doesn't find it in the cache (because no such version exists)
 | 
					
						
							|  |  |  |     let thrown = false; | 
					
						
							|  |  |  |     try { | 
					
						
							| 
									
										
										
										
											2019-07-11 16:37:07 -04:00
										 |  |  |       await finder.findPythonVersion('3.300000', 'x64'); | 
					
						
							| 
									
										
										
										
											2019-06-27 11:40:43 -04:00
										 |  |  |     } catch { | 
					
						
							|  |  |  |       thrown = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     expect(thrown).toBeTruthy(); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-06-26 21:12:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-27 11:40:43 -04:00
										 |  |  |   it('Finds PyPy if it is installed', async () => { | 
					
						
							|  |  |  |     const pythonDir: string = path.join(toolDir, 'PyPy', '2.0.0', 'x64'); | 
					
						
							|  |  |  |     await io.mkdirP(pythonDir); | 
					
						
							|  |  |  |     fs.writeFileSync(`${pythonDir}.complete`, 'hello'); | 
					
						
							|  |  |  |     // This will throw if it doesn't find it in the cache (because no such version exists)
 | 
					
						
							|  |  |  |     await finder.findPythonVersion('pypy2', 'x64'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-06-26 21:12:00 -04:00
										 |  |  | }); |