|
1 | 1 | // The testing setup has been derived from the actions/setup-go@bc6edb5 action. |
2 | 2 | // Check README.md for licence information. |
3 | 3 |
|
| 4 | +import * as fs from 'fs' |
| 5 | +import * as os from 'os' |
4 | 6 | import * as path from 'path' |
5 | 7 |
|
6 | 8 | import * as io from '@actions/io' |
@@ -40,6 +42,85 @@ process.env['RUNNER_TEMP'] = tempDir |
40 | 42 | import * as installer from '../src/installer' |
41 | 43 | import exp from 'constants' |
42 | 44 |
|
| 45 | +describe("readJuliaVersionFromToolVersionsFile tests", () => { |
| 46 | + let tempDirForToolVersions: string |
| 47 | + |
| 48 | + beforeEach(() => { |
| 49 | + tempDirForToolVersions = fs.mkdtempSync(path.join(os.tmpdir(), "setup-julia-tool-versions-")) |
| 50 | + }) |
| 51 | + |
| 52 | + afterEach(() => { |
| 53 | + fs.rmSync(tempDirForToolVersions, { force: true, recursive: true }) |
| 54 | + }) |
| 55 | + |
| 56 | + function writeToolVersions(content: string): string { |
| 57 | + const versionFilePath = path.join(tempDirForToolVersions, ".tool-versions") |
| 58 | + fs.writeFileSync(versionFilePath, content) |
| 59 | + return versionFilePath |
| 60 | + } |
| 61 | + |
| 62 | + it("Reads a Julia version", () => { |
| 63 | + const versionFilePath = writeToolVersions("julia 1.10.4\n") |
| 64 | + expect(installer.readJuliaVersionFromToolVersionsFile(versionFilePath)).toEqual("1.10.4") |
| 65 | + }) |
| 66 | + |
| 67 | + it("Handles comments and blank lines", () => { |
| 68 | + const versionFilePath = writeToolVersions("\n# tools\n\njulia 1.11.0\n") |
| 69 | + expect(installer.readJuliaVersionFromToolVersionsFile(versionFilePath)).toEqual("1.11.0") |
| 70 | + }) |
| 71 | + |
| 72 | + it("Finds Julia among multiple tools", () => { |
| 73 | + const versionFilePath = writeToolVersions("nodejs 24.11.1\njulia 1.10.7\npython 3.14.0\n") |
| 74 | + expect(installer.readJuliaVersionFromToolVersionsFile(versionFilePath)).toEqual("1.10.7") |
| 75 | + }) |
| 76 | + |
| 77 | + it("Uses the first Julia version token", () => { |
| 78 | + const versionFilePath = writeToolVersions("julia 1.10.4 1.11.1 # fallback\n") |
| 79 | + expect(installer.readJuliaVersionFromToolVersionsFile(versionFilePath)).toEqual("1.10.4") |
| 80 | + }) |
| 81 | + |
| 82 | + it("Reads a prerelease Julia version", () => { |
| 83 | + const versionFilePath = writeToolVersions("julia 1.11.0-rc1\n") |
| 84 | + expect(installer.readJuliaVersionFromToolVersionsFile(versionFilePath)).toEqual("1.11.0-rc1") |
| 85 | + }) |
| 86 | + |
| 87 | + it("Throws when the Julia entry only specifies major and minor", () => { |
| 88 | + const versionFilePath = writeToolVersions("julia 1.10\n") |
| 89 | + expect(() => installer.readJuliaVersionFromToolVersionsFile(versionFilePath)).toThrow("must specify major, minor, and patch") |
| 90 | + }) |
| 91 | + |
| 92 | + it("Throws when the Julia entry only specifies major", () => { |
| 93 | + const versionFilePath = writeToolVersions("julia 1\n") |
| 94 | + expect(() => installer.readJuliaVersionFromToolVersionsFile(versionFilePath)).toThrow("must specify major, minor, and patch") |
| 95 | + }) |
| 96 | + |
| 97 | + it("Throws when the Julia entry uses a version keyword", () => { |
| 98 | + const versionFilePath = writeToolVersions("julia lts\n") |
| 99 | + expect(() => installer.readJuliaVersionFromToolVersionsFile(versionFilePath)).toThrow("must specify major, minor, and patch") |
| 100 | + }) |
| 101 | + |
| 102 | + it("Throws when no Julia entry exists", () => { |
| 103 | + const versionFilePath = writeToolVersions("nodejs 24.11.1\npython 3.14.0\n") |
| 104 | + expect(() => installer.readJuliaVersionFromToolVersionsFile(versionFilePath)).toThrow("No Julia version found") |
| 105 | + }) |
| 106 | + |
| 107 | + it("Throws when the Julia entry has no version", () => { |
| 108 | + const versionFilePath = writeToolVersions("julia\n") |
| 109 | + expect(() => installer.readJuliaVersionFromToolVersionsFile(versionFilePath)).toThrow("No Julia version found") |
| 110 | + }) |
| 111 | + |
| 112 | + it("Throws when the version file is not named .tool-versions", () => { |
| 113 | + const versionFilePath = path.join(tempDirForToolVersions, "julia-version") |
| 114 | + fs.writeFileSync(versionFilePath, "julia 1.10.4\n") |
| 115 | + expect(() => installer.readJuliaVersionFromToolVersionsFile(versionFilePath)).toThrow("only supports .tool-versions") |
| 116 | + }) |
| 117 | + |
| 118 | + it("Throws when the version file does not exist", () => { |
| 119 | + const versionFilePath = path.join(tempDirForToolVersions, ".tool-versions") |
| 120 | + expect(() => installer.readJuliaVersionFromToolVersionsFile(versionFilePath)).toThrow("does not exist") |
| 121 | + }) |
| 122 | +}) |
| 123 | + |
43 | 124 | describe("getProjectFilePath tests", () => { |
44 | 125 | let orgJuliaProject |
45 | 126 | let orgWorkingDir |
|
0 commit comments