Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Jan 9, 2024
1 parent 5dfcf28 commit b8106f2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
2 changes: 0 additions & 2 deletions __tests__/fixtures/PkgA/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
[compat]
julia = "1, >=1.1, ^1.2"
2 changes: 0 additions & 2 deletions __tests__/fixtures/PkgB/JuliaProject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
[compat]
julia = "1.7"
28 changes: 14 additions & 14 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Check README.md for licence information.

import * as path from 'path'
import * as fs from 'fs'

import * as io from '@actions/io'

Expand Down Expand Up @@ -40,16 +39,6 @@ process.env['RUNNER_TEMP'] = tempDir

import * as installer from '../src/installer'

function genProjectToml(juliaVersions: Array<string> | undefined = undefined) {
const tomlLines = ["[compat]"]

if (typeof juliaVersions !== "undefined") {
tomlLines.push(`julia = "${juliaVersions.join(", ")}"`)
}

return tomlLines.join("\n")
}

describe("getProjectFile tests", () => {
it("Can determine project file is missing", () => {
expect(() => installer.getProjectFile("DNE.toml")).toThrow("Unable to locate project file")
Expand All @@ -67,13 +56,25 @@ describe("getProjectFile tests", () => {
})

describe("readJuliaCompatVersions tests", () => {
it('Can determine Julia compat entries from a file', () => {
it('Can determine Julia compat entries', () => {
// Note: Julia's Pkg.jl uses caret as the default specifier (e.g. `1.2.3 == ^1.2.3`) where as
// NPM's semver uses tilde as the default specifier (e.g. `1.2.3 == 1.2.x == ~1.2.3`). In order
// to ensure the Julia default is respected we'll be sure to add the caret specify where needed.
// https://pkgdocs.julialang.org/v1/compatibility/#Version-specifier-format
// https://github.com/npm/node-semver#x-ranges-12x-1x-12-
const toml = '[compat]\njulia = "1, >=1.1, ^1.2, ~1.3"'
expect(installer.readJuliaCompatVersions(toml)).toEqual(["^1", ">=1.1", "^1.2", "~1.3"])
})

it('Handle whitespace', () => {
const toml = '[compat]\njulia = " 1,2 , 3 ,"'
expect(installer.readJuliaCompatVersions(toml)).toEqual(["^1", "^2", "^3"])
})

it('Handle missing compat entries', () => {
expect(installer.readJuliaCompatVersions("")).toEqual([])
expect(installer.readJuliaCompatVersions("[compat]")).toEqual([])
expect(installer.readJuliaCompatVersions("[compat]\njulia = \"\"")).toEqual([])
})
})

Expand Down Expand Up @@ -134,9 +135,8 @@ describe('version matching tests', () => {
expect(installer.getJuliaVersion(versions, "MIN", true, ["^1.7"])).toEqual("1.7.3-rc1")

// NPM's semver package treats "1.7" as "~1.7" instead of "^1.7" like Julia
expect(installer.getJuliaVersion(versions, "MIN", false, ["1.7"])).toThrow("Could not find a Julia version")
expect(() => installer.getJuliaVersion(versions, "MIN", false, ["1.7"])).toThrow("Could not find a Julia version that matches")

expect(installer.getJuliaVersion(versions, "MIN", true, [""])).toEqual("1.6.7")
expect(() => installer.getJuliaVersion(versions, "MIN", true, [])).toThrow("Julia project file does not specify a compat for Julia")
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function readJuliaCompatVersions(projectFileContent: string): string[] {
compatVersions.push(versionRange.trim().replace(/^(?=\d)/, "^"))
}

return compatVersions
return compatVersions.filter(v => v)
}

export function getJuliaVersion(availableReleases: string[], versionInput: string, includePrerelease: boolean = false, juliaCompatVersions: string[] = []): string {
Expand Down

0 comments on commit b8106f2

Please sign in to comment.