Skip to content

Commit

Permalink
add e2e tests to --max-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dbale-altoros committed Jul 19, 2023
1 parent ff2695d commit f67e559
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 18 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/E2E.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,18 @@ jobs:

e2e_windows:
runs-on: windows-latest
name: Run linter and E2E Tests on Windows
name: Run linter and E2E Tests on Windows

steps:
- name: Enable Debugging
run: |
echo "::debug::Debugging enabled"
- name: Print a message
run: |
echo "This is a regular message"
echo "::warning::This is a warning message"
echo "::error::This is an error message"
echo "::debug::This is a debug message"
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions e2e/05-max-warnings/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "solhint:all"
}
11 changes: 11 additions & 0 deletions e2e/05-max-warnings/contracts/Foo.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.8;

contract Foo {
uint256 public constant test1 = 1;
uint256 TEST2;

constructor() {

}
}
15 changes: 15 additions & 0 deletions e2e/05-max-warnings/contracts/Foo2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;

contract Foo {
uint256 public constant test1 = 1;
uint256 TEST2;

constructor() {}

function TEST() {}

modifier ZAR_tok() {}

uint256 SOSO;
}
86 changes: 86 additions & 0 deletions e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,90 @@ describe('e2e', function() {
expect(code).to.equal(0)
})
})

describe('--max-warnings parameter tests', function() {
// Foo contract has 6 warnings
// Foo2 contract has 1 error and 14 warnings
useFixture('05-max-warnings')

it('should not return error for max 7 warnings', function() {
const { code } = shell.exec('solhint contracts/Foo.sol --max-warnings 7')
expect(code).to.equal(0)
})

it('should return error for max 3 warnings', function() {
const { code, stdout } = shell.exec('solhint contracts/Foo.sol --max-warnings 3')

console.log('--------------------------------------------------------------------------');
console.log('code :>> ', code);
console.log('stdout 3 warn :>> \n', stdout);
console.log('==========================================================================');

expect(code).to.equal(1)
expect(stdout.trim()).to.contain('Solhint found more warnings than the maximum specified (maximum: 3, found: 6)')
})

it('should return error for Compiler version rule, ignoring 3 --max-warnings', function() {
const { code, stdout } = shell.exec('solhint contracts/Foo2.sol --max-warnings 3')

console.log('--------------------------------------------------------------------------');
console.log('code :>> ', code);
console.log('stdout 3 warn and error :>> \n', stdout);
console.log('==========================================================================');

expect(code).to.equal(1)
expect(stdout.trim()).to.contain('Error/s found on rules! [max-warnings] rule ignored. Fixing errors enables max-warnings')
})

it('should return error for Compiler version rule. No message for max-warnings', function() {
const { code, stdout } = shell.exec('solhint contracts/Foo2.sol --max-warnings 7')

console.log('--------------------------------------------------------------------------');
console.log('code :>> ', code);
console.log('stdout 7 warn and error NOT ignored :>> \n', stdout);
console.log('==========================================================================');

expect(code).to.equal(1)
expect(stdout.trim()).to.not.contain('Error/s found on rules! [max-warnings] rule ignored. Fixing errors enables max-warnings')
})

describe.only('--max-warnings parameter tests', function() {
it(' max warning 30', function() {
const { code, stdout } = shell.exec('solhint contracts/Foo2.sol --max-warnings 30')

console.log('--------------------------------------------------------------------------');
console.log('code :>> ', code);
console.log('stdout 30 :>> \n', stdout);
console.log('==========================================================================');
})

it(' max warning 7', function() {
const { code, stdout } = shell.exec('solhint contracts/Foo2.sol --max-warnings 7')

console.log('--------------------------------------------------------------------------');
console.log('code :>> ', code);
console.log('stdout 7 :>> \n', stdout);
console.log('==========================================================================');
})

it(' max warning 8', function() {
const { code, stdout } = shell.exec('solhint contracts/Foo2.sol --max-warnings 8')

console.log('--------------------------------------------------------------------------');
console.log('code :>> ', code);
console.log('stdout 8 :>> \n', stdout);
console.log('==========================================================================');
})

it(' max warning 9', function() {
const { code, stdout } = shell.exec('solhint contracts/Foo2.sol --max-warnings 9')

console.log('--------------------------------------------------------------------------');
console.log('code :>> ', code);
console.log('stdout 9 :>> \n', stdout);
console.log('==========================================================================');
})
})

})
})
66 changes: 49 additions & 17 deletions solhint.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
/* eslint-disable eqeqeq */

const program = require('commander')
const _ = require('lodash')
Expand All @@ -8,8 +9,8 @@ const process = require('process')
const linter = require('./lib/index')
const { loadConfig } = require('./lib/config/config-file')
const { validate } = require('./lib/config/config-validator')
const applyFixes = require('./lib/apply-fixes')
const ruleFixer = require('./lib/rule-fixer')
// const applyFixes = require('./lib/apply-fixes')
// const ruleFixer = require('./lib/rule-fixer')
const packageJson = require('./package.json')

function init() {
Expand Down Expand Up @@ -54,6 +55,37 @@ function init() {
}

function execMainAction() {
process.stdout.write('-------------------============================---------------------')
process.stdout.write('program.opts().maxWarnings :>> ', program.opts().maxWarnings)
process.stdout.write('-------------------============================---------------------')

process.exitCode = Number(program.opts().maxWarnings)

// eslint-disable-next-line func-names
process.on('exit', function (code) {
return console.log(`Exit Code: ${code}`)
})

/*
if (program.opts().maxWarnings == 30) {
console.log('\n30 ----------')
process.exit(30)
}
if (program.opts().maxWarnings == 9) {
console.log('\n9 -----------')
process.exit(9)
}
if (program.opts().maxWarnings == 8) {
console.log('\n8 -----------')
process.exit(8)
}
if (program.opts().maxWarnings == 7) {
console.log('\n7 -----------')
process.exit(7)
}
process.exit(20)
if (program.opts().init) {
writeSampleConfigFile()
}
Expand Down Expand Up @@ -98,7 +130,8 @@ function execMainAction() {
printReports(reports, formatterFn)
exitWithCode(reports)
// exitWithCode(reports)
*/
}

function processStdin(options) {
Expand All @@ -120,7 +153,7 @@ function processStdin(options) {

printReports(reports, formatterFn)

exitWithCode(reports)
// exitWithCode(reports)
}

function writeSampleConfigFile() {
Expand Down Expand Up @@ -183,9 +216,9 @@ function processStr(input) {
return linter.processStr(input, readConfig())
}

function processPath(path) {
return linter.processPath(path, readConfig())
}
// function processPath(path) {
// return linter.processPath(path, readConfig())
// }

function areWarningsExceeded(reports) {
const warningsCount = reports.reduce((acc, i) => acc + i.warningCount, 0)
Expand All @@ -196,10 +229,12 @@ function areWarningsExceeded(reports) {
}

function printReports(reports, formatter) {
// eslint-disable-next-line no-unused-vars
const warnings = areWarningsExceeded(reports)

console.log(formatter(reports))

/*
if (
program.opts().maxWarnings &&
reports &&
Expand All @@ -214,14 +249,12 @@ function printReports(reports, formatter) {
)
} else {
console.log(
'Error/s found on rules! [max-warnings] rule ignored. Fixing errors enables max-warnings',
program.opts().maxWarnings,
warnings.warningsCount
'Error/s found on rules! [max-warnings] rule ignored. Fixing errors enables max-warnings'
)
}
process.exit(1)
process.exit(20)
}

*/
return reports
}

Expand Down Expand Up @@ -271,10 +304,9 @@ function listRules() {
process.exit(0)
}

function exitWithCode(reports) {
const errorsCount = reports.reduce((acc, i) => acc + i.errorCount, 0)

process.exit(errorsCount > 0 ? 1 : 0)
}
// function exitWithCode(reports) {
// const errorsCount = reports.reduce((acc, i) => acc + i.errorCount, 0)
// process.exit(errorsCount > 0 ? 1 : 0)
// }

init()

0 comments on commit f67e559

Please sign in to comment.