Skip to content

Instantly share code, notes, and snippets.

@mehulmpt
Created November 7, 2020 20:47
Show Gist options
  • Save mehulmpt/5ec748203a2bee452aa79cdf845c3a49 to your computer and use it in GitHub Desktop.
Save mehulmpt/5ec748203a2bee452aa79cdf845c3a49 to your computer and use it in GitHub Desktop.
const { exec } = require('child_process')
const fs = require('fs')
const stdin = `
3
5
10
15
`.trim()
const expectedOutput = `
5
10
`
.trim()
.split('\n')
const java = exec(`cd ${process.env.USER_CODE_DIR} && javac HelloWorld.java && java HelloWorld`)
java.stdin.write(stdin + '\n')
let _realOutput = ''
java.stdout.on('data', (data) => {
_realOutput += data.toString()
})
java.stdout.on('close', () => {
const results = []
const realOutput = _realOutput.trim().split('\n')
for (let i = 0; i < expectedOutput.length; i++) {
const expectedRow = expectedOutput[i]
const actualRow = realOutput[i]
results.push(expectedRow === actualRow)
}
fs.writeFileSync(process.env.UNIT_TEST_OUTPUT_FILE, JSON.stringify(results))
process.exit(0)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment