Skip to content

Commit

Permalink
🐍 Fixup java python (#219)
Browse files Browse the repository at this point in the history
* fix version catcher to not snag java

* fix stderror on windows

* clean up unused

* fixup tests

* add tests

* add tests
  • Loading branch information
GantMan authored Aug 17, 2018
1 parent 060f6dd commit 31eb84c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 5 deletions.
13 changes: 13 additions & 0 deletions __tests__/command_helpers/checkSTDERR.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const checkSTDERR = require('../../src/extensions/functions/checkSTDERR')
const context = require('mockContext')

describe('checkSTDERR', () => {
test('returns augmented string', async () => {
const rule = { rule: 'cli', binary: 'yarn', version: '--version' }
const normal = `${rule.binary} ${rule.version}`
const output = await checkSTDERR(rule, context)

expect(typeof output).toBe('string')
expect(output.length).toBeGreaterThan(normal.length)
})
}
14 changes: 13 additions & 1 deletion __tests__/command_helpers/getSolidarityHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,25 @@ describe('Test helper functions', () => {
// describe('loadModule', () => {
// })

let originalTimeout
describe('loadWebCheck', () => {
beforeAll(() => {
// These can be slow on CI
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000
})

afterAll(function() {
// Fix timeout change
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
})

test('loadWebCheck positive cases', async () => {
expect(await loadWebCheck(context, 'https://raw.githubusercontent.com/infinitered/solidarity-stacks/master/stacks/react-native.solidarity')).toBeTruthy()
})

test('loadWebCheck false cases', async () => {
await expect(loadWebCheck(context, 'https://raw.githubusercontent.com/infinitered/solidarity-stacks/master/stacks/failsauce'))
await expect(loadWebCheck(context, 'https://raw.githubusercontent.com/fail/sauce'))
.rejects
.toThrow()
})
Expand Down
4 changes: 2 additions & 2 deletions __tests__/command_helpers/getVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ describe('getVersion', () => {
})

test('throws an error if no version flag works', async () => {
const rule = { rule: 'cli', binary: 'ls' }
const rule = { rule: 'cli', binary: 'cd' }
let result

try {
await getVersion(rule, context)
} catch (e) {
result = e
}
expect(result).toEqual("No version was detected from the output of the binary 'ls'")
expect(result).toEqual("No version identifier flag for this binary was found")
})
})
15 changes: 15 additions & 0 deletions src/extensions/functions/checkSTDERR.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { CLIRule } from '../../types'

// Creates STDERR catching string
module.exports = (rule: CLIRule): string => {
const currentPlatform = process.platform
let grabErrorOutput: string
if (currentPlatform === 'win32') {
const tempFile = `solidarityWinFix${rule.binary}.tmp`
grabErrorOutput = `1>${tempFile} 2>&1 & type ${tempFile} & del ${tempFile}`
} else {
grabErrorOutput = '2>&1 | cat'
}

return `${rule.binary} ${rule.version} ${grabErrorOutput}`
}
3 changes: 2 additions & 1 deletion src/extensions/functions/getSolidarityHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const loadWebCheck = async (context, checkOption) => {
const checkSpinner = silentMode || moderateMode ? null : print.spin(`Running check on ${checkOption}`)
// the base URL is throw away, and will go away in next version of apisauce
const api = http.create({
baseURL: 'https://api.github.com'
baseURL: 'https://api.github.com',
timeout: 10000 // 10 seconds
})

// Load check from web
Expand Down
6 changes: 6 additions & 0 deletions src/extensions/functions/getVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise<s
// They specified how to check version
if (rule.version) {
versionOutput = await system.run(`${rule.binary} ${rule.version}`)
if (versionOutput === '') {
// Lets try again
// things like python and java use stderr instead of stdout
const checkSTDERR = require('./checkSTDERR')
versionOutput = await system.run(checkSTDERR(rule, context))
}
} else {
// We try the following in this order
// -v, --version, -version
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/functions/removeNonVersionCharacters.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CLIRule } from '../../types'
module.exports = (rule: CLIRule, line: string): string => {
const foundVersions = line.match(/(\d+\.)?(\d+\.)?(\d+)([^\sa-zA-Z0-9]+\w+)?/g)
const foundVersions = line.match(/(\d+\.)?(\d+\.)?(\d+)([^\sa-zA-Z0-9|_]+\w+)?/g)

if (Array.isArray(foundVersions)) {
const matchIndex = rule.matchIndex || 0
Expand Down

0 comments on commit 31eb84c

Please sign in to comment.