Skip to content

Commit

Permalink
fix e2e v2
Browse files Browse the repository at this point in the history
  • Loading branch information
dbale-altoros committed May 11, 2024
1 parent d86157f commit 0cec1f7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Solhint changed how the exit codes are implemented:
#### Solhint QUIET mode
QUIET mode (-c quiet) option now works with the warnings and may exit with 1 if there are more than defined by user

Thanks to [@juanpcapurro](https://github.com/juanpcapurro) for providing the code

<br><br>
## [4.5.4] - 2024-04-10
Expand Down
27 changes: 14 additions & 13 deletions e2e/autofix-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const shell = require('shelljs')
const spawnSync = require('spawn-sync')

const E2E = true
const EXIT_CODES = { BAD_OPTIONS: 255, OK: 0, REPORTED_ERRORS: 1 }

let params
let currentConfig
Expand Down Expand Up @@ -103,7 +104,7 @@ describe('e2e', function () {
}
)

expect(solhintProcess.status).to.equal(0)
expect(solhintProcess.status).to.equal(EXIT_CODES.REPORTED_ERRORS)
expect(solhintProcess.stdout.toString().includes('5 problems (5 errors, 0 warnings)'))
})
})
Expand All @@ -129,7 +130,7 @@ describe('e2e', function () {
`${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt`
)

expect(code).to.equal(0)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)

const reportLines = stdout.split('\n')
const finalLine = '5 problems (5 errors, 0 warnings)'
Expand Down Expand Up @@ -175,8 +176,8 @@ describe('e2e', function () {
expect(result).to.be.true
})

it('should execute and exit with code 0 (2)', () => {
expect(code).to.equal(0)
it('should execute and exit with code 1 (2)', () => {
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
})

it('should get the right report (2)', () => {
Expand Down Expand Up @@ -221,8 +222,8 @@ describe('e2e', function () {
expect(result).to.be.true
})

it('should execute and exit with code 1 (3)', () => {
expect(code).to.equal(0)
it('should execute and exit with code 0 (3)', () => {
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
})

it('should get the right report (3)', () => {
Expand Down Expand Up @@ -268,7 +269,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (4)', () => {
expect(code).to.equal(0)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
})

it('should get the right report (4)', () => {
Expand Down Expand Up @@ -314,7 +315,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (5)', () => {
expect(code).to.equal(0)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
})

it('should get the right report (5)', () => {
Expand Down Expand Up @@ -361,7 +362,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (6)', () => {
expect(code).to.equal(0)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
})

it('should get the right report (6)', () => {
Expand Down Expand Up @@ -401,7 +402,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (6)', () => {
expect(code).to.equal(0)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
})

it('should get the right report (6)', () => {
Expand Down Expand Up @@ -448,7 +449,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (7)', () => {
expect(code).to.equal(0)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
})

it('should get the right report (7)', () => {
Expand Down Expand Up @@ -494,7 +495,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (8)', () => {
expect(code).to.equal(0)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
})

it('should get the right report (8)', () => {
Expand Down Expand Up @@ -540,7 +541,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (8)', () => {
expect(code).to.equal(0)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
})

it('should get the right report (8)', () => {
Expand Down
12 changes: 6 additions & 6 deletions e2e/formatters-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('e2e', function () {
expect(reportLines[i]).to.equal(expectedLine)
}
// because there's an error
expect(code).to.equal(EXIT_CODES.OK)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)

const finalLine = '10 problem/s (1 error/s, 9 warning/s)'
expect(reportLines[reportLines.length - 2]).to.contain(finalLine)
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('e2e', function () {
const strExpected = JSON.stringify(expectedFinalOutput)
expect(strExpected).to.equal(strOutput)
// There's an error, that is why exit code is 1
expect(code).to.equal(EXIT_CODES.OK)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
})
})

Expand Down Expand Up @@ -221,7 +221,7 @@ describe('e2e', function () {
expect(reportLines[i]).to.equal(expectedLine)
}
// because there's an error
expect(code).to.equal(EXIT_CODES.OK)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)

const finalLine = '10 problem/s (1 error/s, 9 warning/s)'
expect(reportLines[reportLines.length - 2]).to.contain(finalLine)
Expand Down Expand Up @@ -293,7 +293,7 @@ describe('e2e', function () {

expect(reportLines[i].replace(/\s/g, '')).to.equal(expectedLine.replace(/\s/g, ''))
}
expect(code).to.equal(EXIT_CODES.OK)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)

const finalLine = '\u2716 10 problems (1 error, 9 warnings)'
expect(reportLines[reportLines.length - 3]).to.equal(finalLine)
Expand Down Expand Up @@ -400,7 +400,7 @@ describe('e2e', function () {
expect(reportLines[3]).to.eq(tableHeader1)
expect(reportLines[4]).to.eq(tableHeader2)

expect(code).to.equal(EXIT_CODES.OK)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
})
})

Expand Down Expand Up @@ -717,7 +717,7 @@ describe('e2e', function () {
]

// There's an error, that is why exit code is 1
expect(code).to.equal(EXIT_CODES.OK)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
expect(sarifOutput.runs[0].artifacts[0].location.uri).to.eq(expectedUriPathFoo)
expect(sarifOutput.runs[0].artifacts[1].location.uri).to.eq(expectedUriPathFoo2)
expect(sarifOutput.runs[0].artifacts[2].location.uri).to.eq(expectedUriPathFoo3)
Expand Down
17 changes: 8 additions & 9 deletions e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,23 @@ describe('e2e', function () {
})

it('should show warning when using --init', function () {
const { code, stdout } = shell.exec(`${NODE}solhint --init`)

const { code, stderr } = shell.exec(`${NODE}solhint --init`)
expect(code).to.equal(EXIT_CODES.BAD_OPTIONS)
expect(stdout.trim()).to.equal('Configuration file already exists')
expect(stderr).to.include('Configuration file already exists')
})
})

describe('no-empty-blocks', function () {
const PATH = '03-no-empty-blocks'
const { PREFIX, SUFFIX } = prepareContext(PATH)

describe('No contracts to lint', function () {
it('should fail with appropiate message', function () {
const { code, stderr } = shell.exec(`${NODE}solhint Foo.sol ${SUFFIX}`)

it('No contracts to lint should fail with appropiate message', function () {
const { code, stderr } = shell.exec(`${NODE}solhint Foo1.sol ${SUFFIX}`)

expect(code).to.equal(EXIT_CODES.BAD_OPTIONS)
expect(stderr).to.include('No files to lint!')
})
})

it('should end with REPORTED_ERRORS = 1 because report contains errors', function () {
const { code, stdout } = shell.exec(`${NODE}solhint ${PREFIX}Foo.sol ${SUFFIX}`)
Expand Down Expand Up @@ -213,9 +211,10 @@ describe('e2e', function () {

it(`should raise error for wrongFunctionDefinitionName() only`, () => {
const SUFFIX2 = `-c ${PREFIX}test/.solhint.json --disc`

const { code, stdout } = shell.exec(`${NODE}solhint ${PREFIX}test/FooTest.sol ${SUFFIX2}`)

expect(code).to.equal(EXIT_CODES.OK)
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
expect(stdout.trim()).to.contain(
'Function wrongFunctionDefinitionName() must match Foundry test naming convention '
)
Expand Down

0 comments on commit 0cec1f7

Please sign in to comment.