mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
fix(cli): changes to input/output should run all affected tests
This commit is contained in:
parent
17efe8a113
commit
d18ca22470
@ -5,7 +5,7 @@ import chalk from 'chalk'
|
|||||||
import { Solution } from '../../services/Solution'
|
import { Solution } from '../../services/Solution'
|
||||||
import { GitAffected } from '../../services/GitAffected'
|
import { GitAffected } from '../../services/GitAffected'
|
||||||
import { template } from '../../services/Template'
|
import { template } from '../../services/Template'
|
||||||
import { Test, successMessage } from '../../services/Test'
|
import { Test } from '../../services/Test'
|
||||||
|
|
||||||
export class RunTestCommand extends Command {
|
export class RunTestCommand extends Command {
|
||||||
static paths = [['run', 'test']]
|
static paths = [['run', 'test']]
|
||||||
@ -78,7 +78,7 @@ export class RunTestCommand extends Command {
|
|||||||
programmingLanguageName: this.programmingLanguage
|
programmingLanguageName: this.programmingLanguage
|
||||||
})
|
})
|
||||||
await solution.test()
|
await solution.test()
|
||||||
console.log(successMessage)
|
console.log(Test.successMessage)
|
||||||
return 0
|
return 0
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import execa from 'execa'
|
import execa from 'execa'
|
||||||
|
|
||||||
|
import { Challenge } from './Challenge'
|
||||||
import { Solution } from './Solution'
|
import { Solution } from './Solution'
|
||||||
|
|
||||||
const solutionsRegex = new RegExp(
|
const solutionsRegex = new RegExp(
|
||||||
@ -10,6 +11,10 @@ const dockerRegex = new RegExp(
|
|||||||
/templates\/docker\/(c|cpp|cs|dart|java|javascript|python|rust|typescript)\/Dockerfile/
|
/templates\/docker\/(c|cpp|cs|dart|java|javascript|python|rust|typescript)\/Dockerfile/
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const inputOutputRegex = new RegExp(
|
||||||
|
/challenges\/[\s\S]*\/test\/[0-9]\/(input.txt|output.txt)/
|
||||||
|
)
|
||||||
|
|
||||||
export interface GitAffectedOptions {
|
export interface GitAffectedOptions {
|
||||||
isContinuousIntegration: boolean
|
isContinuousIntegration: boolean
|
||||||
base?: string
|
base?: string
|
||||||
@ -81,6 +86,13 @@ export class GitAffected implements GitAffectedOptions {
|
|||||||
const [,, programmingLanguageName] = filePath.replaceAll('\\', '/').split('/')
|
const [,, programmingLanguageName] = filePath.replaceAll('\\', '/').split('/')
|
||||||
return programmingLanguageName
|
return programmingLanguageName
|
||||||
})
|
})
|
||||||
|
const affectedInputOutput = files.filter((filePath) => {
|
||||||
|
return inputOutputRegex.test(filePath)
|
||||||
|
})
|
||||||
|
const affectedChallenges = affectedInputOutput.map((filePath) => {
|
||||||
|
const [, challengeName] = filePath.replaceAll('\\', '/').split('/')
|
||||||
|
return new Challenge({ name: challengeName })
|
||||||
|
})
|
||||||
const solutionsChallenges = await Solution.getManyByPaths(affectedSolutionsPaths)
|
const solutionsChallenges = await Solution.getManyByPaths(affectedSolutionsPaths)
|
||||||
const solutionsDocker = await Solution.getManyByProgrammingLanguages(affectedLanguages)
|
const solutionsDocker = await Solution.getManyByProgrammingLanguages(affectedLanguages)
|
||||||
const solutions: Solution[] = solutionsDocker
|
const solutions: Solution[] = solutionsDocker
|
||||||
@ -89,6 +101,19 @@ export class GitAffected implements GitAffectedOptions {
|
|||||||
solutions.push(solution)
|
solutions.push(solution)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (const challenge of affectedChallenges) {
|
||||||
|
let isSolutionIncluded = false
|
||||||
|
for (const solution of solutions) {
|
||||||
|
if (solution.challenge.name === challenge.name) {
|
||||||
|
isSolutionIncluded = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isSolutionIncluded) {
|
||||||
|
const solutionsByChallenge = await Solution.getManyByChallenge(challenge)
|
||||||
|
solutions.push(...solutionsByChallenge)
|
||||||
|
}
|
||||||
|
}
|
||||||
return solutions
|
return solutions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,23 @@ export class Solution implements SolutionOptions {
|
|||||||
return solution
|
return solution
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getManyByChallenge (challenge: Challenge): Promise<Solution[]> {
|
||||||
|
const solutionsPath = path.join(challenge.path, 'solutions')
|
||||||
|
const languagesSolution = (await fs.promises.readdir(solutionsPath)).filter(
|
||||||
|
(name) => {
|
||||||
|
return name !== '.gitkeep'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
const paths: string[] = []
|
||||||
|
for (const language of languagesSolution) {
|
||||||
|
const solutionPath = (await fs.promises.readdir(path.join(solutionsPath, language))).map((solutionName) => {
|
||||||
|
return `challenges/${challenge.name}/solutions/${language}/${solutionName}`
|
||||||
|
})
|
||||||
|
paths.push(...solutionPath)
|
||||||
|
}
|
||||||
|
return await Solution.getManyByPaths(paths)
|
||||||
|
}
|
||||||
|
|
||||||
static async getManyByProgrammingLanguages (programmingLanguages?: string[]): Promise<Solution[]> {
|
static async getManyByProgrammingLanguages (programmingLanguages?: string[]): Promise<Solution[]> {
|
||||||
const languages = programmingLanguages ?? await template.getProgrammingLanguages()
|
const languages = programmingLanguages ?? await template.getProgrammingLanguages()
|
||||||
const challengesPath = path.join(
|
const challengesPath = path.join(
|
||||||
|
@ -29,8 +29,6 @@ export interface TestOptions {
|
|||||||
elapsedTimeMilliseconds: number
|
elapsedTimeMilliseconds: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export const successMessage = `${chalk.bold.green('Success:')} Tests passed! 🎉`
|
|
||||||
|
|
||||||
export class Test implements TestOptions {
|
export class Test implements TestOptions {
|
||||||
public index: number
|
public index: number
|
||||||
public path: string
|
public path: string
|
||||||
@ -39,6 +37,7 @@ export class Test implements TestOptions {
|
|||||||
public output: string
|
public output: string
|
||||||
public stdout: string
|
public stdout: string
|
||||||
public elapsedTimeMilliseconds: number
|
public elapsedTimeMilliseconds: number
|
||||||
|
static successMessage = `${chalk.bold.green('Success:')} Tests passed! 🎉`
|
||||||
|
|
||||||
constructor (options: TestOptions) {
|
constructor (options: TestOptions) {
|
||||||
this.index = options.index
|
this.index = options.index
|
||||||
@ -139,7 +138,7 @@ export class Test implements TestOptions {
|
|||||||
await solution.test()
|
await solution.test()
|
||||||
console.log('\n------------------------------\n')
|
console.log('\n------------------------------\n')
|
||||||
}
|
}
|
||||||
console.log(successMessage)
|
console.log(Test.successMessage)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/Divlo/programming-challenges"
|
"url": "https://github.com/Divlo/programming-challenges"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.0.0",
|
"node": ">=16.0.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user