diff --git a/.github/workflows/E2E.yml b/.github/workflows/E2E.yml index 60d1e063..f7503841 100644 --- a/.github/workflows/E2E.yml +++ b/.github/workflows/E2E.yml @@ -6,7 +6,7 @@ on: - master pull_request: branches: - - "*" + - '*' jobs: e2e_linux: @@ -14,47 +14,13 @@ jobs: name: Test on Linux with Node ${{ matrix.node }} strategy: matrix: - node: [16, 18, 20] - - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node }} - - - name: Install dependencies - run: npm install --include=dev - - - name: Run linter - run: npm run lint - - - name: Generate Docs - run: npm run docs - - - name: Pack - run: npm pack - - - name: Global Installation - run: npm i -g solhint*tgz - - - name: Check solhint version - run: solhint --version - - - name: Run E2E Tests - run: cd e2e && npm install && npm test - - e2e_windows: - runs-on: windows-latest - name: Test on Windows + node: [20] steps: - - name: Enable Debugging - run: | - echo "::debug::Debugging enabled" - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: ${{ matrix.node }} - name: Install dependencies run: npm install --include=dev @@ -69,41 +35,10 @@ jobs: run: npm pack - name: Global Installation - run: npm i -g @(Get-ChildItem -Filter *.tgz) + run: npm i -g solhint*tgz - name: Check solhint version run: solhint --version - - name: List directory contents - run: dir - - - name: Run linter - run: npm run lint - - name: Run E2E Tests run: cd e2e && npm install && npm test - - e2e_macos: - runs-on: macos-latest - name: Test on MacOS - - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 - - - name: Install dependencies - run: npm install --include=dev - - - name: Pack - run: npm pack - - - name: Install solhint - run: npm i -g solhint*tgz - - - name: Run linter - run: npm run lint - - - name: Run Tests - run: cd e2e && npm install && npm test diff --git a/.github/workflows/TESTS.yml b/.github/workflows/TESTS.ymlN similarity index 100% rename from .github/workflows/TESTS.yml rename to .github/workflows/TESTS.ymlN diff --git a/e2e/08-autofix/contracts/00-generic/.solhint.json b/e2e/08-autofix/commands/.solhint.json similarity index 100% rename from e2e/08-autofix/contracts/00-generic/.solhint.json rename to e2e/08-autofix/commands/.solhint.json diff --git a/e2e/08-autofix/contracts/00-generic/Foo1.sol b/e2e/08-autofix/commands/Foo1.sol similarity index 100% rename from e2e/08-autofix/contracts/00-generic/Foo1.sol rename to e2e/08-autofix/commands/Foo1.sol diff --git a/e2e/08-autofix/contracts/00-generic/Foo1AfterFix.sol b/e2e/08-autofix/commands/Foo1AfterFix.sol similarity index 100% rename from e2e/08-autofix/contracts/00-generic/Foo1AfterFix.sol rename to e2e/08-autofix/commands/Foo1AfterFix.sol diff --git a/e2e/08-autofix/contracts/00-generic/Foo1BeforeFix.sol b/e2e/08-autofix/commands/Foo1BeforeFix.sol similarity index 100% rename from e2e/08-autofix/contracts/00-generic/Foo1BeforeFix.sol rename to e2e/08-autofix/commands/Foo1BeforeFix.sol diff --git a/e2e/08-autofix/contracts/explicit-types/.solhint.json b/e2e/08-autofix/explicit-types/.solhint.json similarity index 100% rename from e2e/08-autofix/contracts/explicit-types/.solhint.json rename to e2e/08-autofix/explicit-types/.solhint.json diff --git a/e2e/08-autofix/contracts/explicit-types/Foo1.sol b/e2e/08-autofix/explicit-types/Foo1.sol similarity index 100% rename from e2e/08-autofix/contracts/explicit-types/Foo1.sol rename to e2e/08-autofix/explicit-types/Foo1.sol diff --git a/e2e/08-autofix/contracts/explicit-types/Foo1AfterFix.sol b/e2e/08-autofix/explicit-types/Foo1AfterFix.sol similarity index 100% rename from e2e/08-autofix/contracts/explicit-types/Foo1AfterFix.sol rename to e2e/08-autofix/explicit-types/Foo1AfterFix.sol diff --git a/e2e/08-autofix/contracts/explicit-types/Foo1BeforeFix.sol b/e2e/08-autofix/explicit-types/Foo1BeforeFix.sol similarity index 100% rename from e2e/08-autofix/contracts/explicit-types/Foo1BeforeFix.sol rename to e2e/08-autofix/explicit-types/Foo1BeforeFix.sol diff --git a/e2e/08-autofix/contracts/no-console/.solhint.json b/e2e/08-autofix/no-console/.solhint.json similarity index 100% rename from e2e/08-autofix/contracts/no-console/.solhint.json rename to e2e/08-autofix/no-console/.solhint.json diff --git a/e2e/08-autofix/contracts/no-console/Foo1.sol b/e2e/08-autofix/no-console/Foo1.sol similarity index 100% rename from e2e/08-autofix/contracts/no-console/Foo1.sol rename to e2e/08-autofix/no-console/Foo1.sol diff --git a/e2e/08-autofix/contracts/no-console/Foo1AfterFix.sol b/e2e/08-autofix/no-console/Foo1AfterFix.sol similarity index 100% rename from e2e/08-autofix/contracts/no-console/Foo1AfterFix.sol rename to e2e/08-autofix/no-console/Foo1AfterFix.sol diff --git a/e2e/08-autofix/contracts/no-console/Foo1BeforeFix.sol b/e2e/08-autofix/no-console/Foo1BeforeFix.sol similarity index 100% rename from e2e/08-autofix/contracts/no-console/Foo1BeforeFix.sol rename to e2e/08-autofix/no-console/Foo1BeforeFix.sol diff --git a/e2e/08-autofix/contracts/private-vars-underscore/.solhint.json b/e2e/08-autofix/private-vars-underscore/.solhint.json similarity index 100% rename from e2e/08-autofix/contracts/private-vars-underscore/.solhint.json rename to e2e/08-autofix/private-vars-underscore/.solhint.json diff --git a/e2e/08-autofix/contracts/private-vars-underscore/Foo1.sol b/e2e/08-autofix/private-vars-underscore/Foo1.sol similarity index 100% rename from e2e/08-autofix/contracts/private-vars-underscore/Foo1.sol rename to e2e/08-autofix/private-vars-underscore/Foo1.sol diff --git a/e2e/08-autofix/contracts/private-vars-underscore/Foo1AfterFix.sol b/e2e/08-autofix/private-vars-underscore/Foo1AfterFix.sol similarity index 100% rename from e2e/08-autofix/contracts/private-vars-underscore/Foo1AfterFix.sol rename to e2e/08-autofix/private-vars-underscore/Foo1AfterFix.sol diff --git a/e2e/08-autofix/contracts/private-vars-underscore/Foo1BeforeFix.sol b/e2e/08-autofix/private-vars-underscore/Foo1BeforeFix.sol similarity index 100% rename from e2e/08-autofix/contracts/private-vars-underscore/Foo1BeforeFix.sol rename to e2e/08-autofix/private-vars-underscore/Foo1BeforeFix.sol diff --git a/e2e/autofix-test.js b/e2e/autofix-test.js index cf69b386..871e2a57 100644 --- a/e2e/autofix-test.js +++ b/e2e/autofix-test.js @@ -8,11 +8,17 @@ const spawnSync = require('spawn-sync') const E2E = true -function retrieveParams() { +let params +let currentConfig +let currentFile +let beforeFixFile +let afterFixFile + +function retrieveParams(subpath) { if (E2E) { - return { command: 'solhint', param1: '' } + return { command: 'solhint', param1: '', path: '', subpath } } else { - return { command: 'node', param1: 'solhint' } + return { command: 'node', param1: 'solhint', path: 'e2e/08-autofix/', subpath } } } @@ -24,11 +30,16 @@ function compareTextFiles(file1Path, file2Path) { } function copyFile(sourcePath, destinationPath) { - // Read the content from the source file - const content = fs.readFileSync(sourcePath) + // // Read the content from the source file + // const content = fs.readFileSync(sourcePath) + + // // Write the content to the destination file, overwriting it if it exists + // fs.writeFileSync(destinationPath, content) - // Write the content to the destination file, overwriting it if it exists - fs.writeFileSync(destinationPath, content) + console.log('sourcePath :>> ', sourcePath) + console.log('destinationPath :>> ', destinationPath) + const { code } = shell.cp(sourcePath, destinationPath) + console.log('code :>> ', code) } function useFixture(dir) { @@ -56,33 +67,29 @@ describe('e2e', function () { } describe('autofix command line options', () => { - const commands = retrieveParams() - let PATH = 'e2e/08-autofix/' - let SUBPATH = 'contracts/00-generic/' - let sourceFilePath = `${PATH}${SUBPATH}Foo1BeforeFix.sol` - let currentFile = `${PATH}${SUBPATH}Foo1.sol` + before(function () { + params = retrieveParams('commands/') + currentConfig = `${params.path}${params.subpath}.solhint.json` + currentFile = `${params.path}${params.subpath}Foo1.sol` + beforeFixFile = `${params.path}${params.subpath}Foo1BeforeFix.sol` + afterFixFile = `${params.path}${params.subpath}Foo1AfterFix.sol` + }) describe('--fix without noPrompt', () => { after(function () { - copyFile(sourceFilePath, currentFile) + copyFile(beforeFixFile, currentFile) }) - it('should terminate with --fix and user choose NOT to continue', () => { + it('pwd and ls', () => { + shell.exec(`pwd`) - shell.exec( - `pwd` - ) + shell.exec(`ls`) + }) + it('should terminate with --fix and user choose NOT to continue', () => { const solhintProcess = spawnSync( - `${commands.command}`, - [ - `${commands.param1}`, - '-c', - `${PATH}${SUBPATH}.solhint.json`, - `${PATH}${SUBPATH}Foo1.sol`, - '--fix', - '--disc', - ], + `${params.command}`, + [`${params.param1}`, '-c', currentConfig, currentFile, '--fix', '--disc'], { input: 'n\n', // Provide 'n' as input } @@ -92,23 +99,18 @@ describe('e2e', function () { expect(solhintProcess.stdout.toString().includes('Process terminated by user')) }) - it('should fix with --fix and user choose YES to continue', () => { - sourceFilePath = `${PATH}${SUBPATH}Foo1BeforeFix.sol` - currentFile = `${PATH}${SUBPATH}Foo1.sol` + it('should compare Foo1 file with template beforeFix file and they should match 1', () => { + result = compareTextFiles(currentFile, beforeFixFile) + expect(result).to.be.true + }) - result = compareTextFiles(sourceFilePath, `${PATH}${SUBPATH}Foo1.sol`) + it('should fix with --fix and user choose YES to continue', () => { + result = compareTextFiles(beforeFixFile, currentFile) expect(result).to.be.true const solhintProcess = spawnSync( - `${commands.command}`, - [ - `${commands.param1}`, - '-c', - `${PATH}${SUBPATH}.solhint.json`, - currentFile, - '--fix', - '--disc', - ], + `${params.command}`, + [`${params.param1}`, '-c', currentConfig, currentFile, '--fix', '--disc'], { input: 'y\n', // Provide 'y' as input } @@ -119,24 +121,24 @@ describe('e2e', function () { }) it('should compare resulted file with template file and they should match 1', () => { - result = compareTextFiles(currentFile, `${PATH}${SUBPATH}Foo1AfterFix.sol`) + result = compareTextFiles(currentFile, afterFixFile) expect(result).to.be.true }) }) describe('--fix with noPrompt', () => { after(function () { - copyFile(sourceFilePath, currentFile) + copyFile(beforeFixFile, currentFile) }) - it('should fix file when noPrompt', () => { - sourceFilePath = `${PATH}${SUBPATH}Foo1BeforeFix.sol` - currentFile = `${PATH}${SUBPATH}Foo1.sol` - result = compareTextFiles(sourceFilePath, `${PATH}${SUBPATH}Foo1.sol`) + it('should compare Foo1 file with template beforeFix file and they should match 2', () => { + result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true + }) + it('should fix file when noPrompt', () => { const { code, stdout } = shell.exec( - `${commands.command} ${commands.param1} -c ${PATH}${SUBPATH}.solhint.json ${currentFile} --fix --disc --noPrompt` + `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` ) expect(code).to.equal(1) @@ -146,33 +148,34 @@ describe('e2e', function () { expect(reportLines[reportLines.length - 3]).to.contain(finalLine) }) - it('files should match', () => { - result = compareTextFiles(currentFile, `${PATH}${SUBPATH}Foo1AfterFix.sol`) + it('should compare resulted file with template file and they should match 2', () => { + result = compareTextFiles(currentFile, afterFixFile) expect(result).to.be.true }) }) - }) describe('autofix rule: explicit-types', () => { describe('--fix with noPrompt', () => { - const commands = retrieveParams() - let PATH = 'e2e/08-autofix/' - let SUBPATH = 'contracts/explicit-types/' - let sourceFilePath = `${PATH}${SUBPATH}Foo1BeforeFix.sol` - let currentFile = `${PATH}${SUBPATH}Foo1.sol` + before(function () { + params = retrieveParams('explicit-types/') + currentConfig = `${params.path}${params.subpath}.solhint.json` + currentFile = `${params.path}${params.subpath}Foo1.sol` + beforeFixFile = `${params.path}${params.subpath}Foo1BeforeFix.sol` + afterFixFile = `${params.path}${params.subpath}Foo1AfterFix.sol` + }) after(function () { - copyFile(sourceFilePath, currentFile) + copyFile(beforeFixFile, currentFile) }) - it('should fix file when noPrompt', () => { - sourceFilePath = `${PATH}${SUBPATH}Foo1BeforeFix.sol` - currentFile = `${PATH}${SUBPATH}Foo1.sol` - result = compareTextFiles(sourceFilePath, `${PATH}${SUBPATH}Foo1.sol`) + it('should compare Foo1 file with template beforeFix file and they should match 3', () => { + result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true + }) + it('should fix file when noPrompt', () => { const { code, stdout } = shell.exec( - `${commands.command} ${commands.param1} -c ${PATH}${SUBPATH}.solhint.json ${currentFile} --fix --disc --noPrompt` + `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` ) expect(code).to.equal(1) @@ -182,32 +185,59 @@ describe('e2e', function () { expect(reportLines[reportLines.length - 3]).to.contain(finalLine) }) - it('files should match', () => { - result = compareTextFiles(currentFile, `${PATH}${SUBPATH}Foo1AfterFix.sol`) + it('should compare resulted file with template file and they should match 3', () => { + result = compareTextFiles(currentFile, afterFixFile) expect(result).to.be.true }) }) }) - describe('autofix rule: no-console', () => { + describe.only('autofix rule: no-console', () => { describe('--fix with noPrompt', () => { - const commands = retrieveParams() - let PATH = 'e2e/08-autofix/' - let SUBPATH = 'contracts/no-console/' - let sourceFilePath = `${PATH}${SUBPATH}Foo1BeforeFix.sol` - let currentFile = `${PATH}${SUBPATH}Foo1.sol` - after(function () { - copyFile(sourceFilePath, currentFile) + before(function () { + params = retrieveParams('no-console/') + currentConfig = `${params.path}${params.subpath}.solhint.json` + currentFile = `${params.path}${params.subpath}Foo1.sol` + beforeFixFile = `${params.path}${params.subpath}Foo1BeforeFix.sol` + afterFixFile = `${params.path}${params.subpath}Foo1AfterFix.sol` }) - it('should fix file when noPrompt', () => { - sourceFilePath = `${PATH}${SUBPATH}Foo1BeforeFix.sol` - currentFile = `${PATH}${SUBPATH}Foo1.sol` + // after(function () { + // copyFile(beforeFixFile, currentFile) + // }) + + it.only('should compare Foo1 file with template beforeFix file and they should match 3', () => { + console.log('beforeFixFile :>> ', beforeFixFile) + console.log('currentFile :>> ', currentFile) + + let stdout + + ({ stdout } = shell.pwd()) + console.log('pwd: ', stdout) + + ({ stdout } = shell.ls(stdout)) + console.log('ls: ', stdout) + + shell.cd('no-console') + ({ stdout } = shell.pwd()) + console.log('pwd no-console: ', stdout) + + ({ stdout } = shell.ls(stdout)) + console.log('ls no-console: ', stdout) + + const retCp = shell.cp(beforeFixFile, currentFile) + console.log('retCp :>> ', retCp) + - result = compareTextFiles(sourceFilePath, `${PATH}${SUBPATH}Foo1.sol`) + }) + + it('should compare Foo1 file with template beforeFix file and they should match 4', () => { + result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true + }) + it('should fix file when noPrompt', () => { const { code, stdout } = shell.exec( - `${commands.command} ${commands.param1} -c ${PATH}${SUBPATH}.solhint.json ${currentFile} --fix --disc --noPrompt` + `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` ) expect(code).to.equal(1) @@ -217,8 +247,8 @@ describe('e2e', function () { expect(reportLines[reportLines.length - 3]).to.contain(finalLine) }) - it('files should match', () => { - result = compareTextFiles(currentFile, `${PATH}${SUBPATH}Foo1AfterFix.sol`) + it('should compare resulted file with template file and they should match 4', () => { + result = compareTextFiles(currentFile, afterFixFile) expect(result).to.be.true }) }) @@ -226,23 +256,25 @@ describe('e2e', function () { describe('autofix rule: private-vars-leading-underscore', () => { describe('--fix with noPrompt', () => { - const commands = retrieveParams() - let PATH = 'e2e/08-autofix/' - let SUBPATH = 'contracts/private-vars-underscore/' - let sourceFilePath = `${PATH}${SUBPATH}Foo1BeforeFix.sol` - let currentFile = `${PATH}${SUBPATH}Foo1.sol` + before(function () { + params = retrieveParams('private-vars-underscore/') + currentConfig = `${params.path}${params.subpath}.solhint.json` + currentFile = `${params.path}${params.subpath}Foo1.sol` + beforeFixFile = `${params.path}${params.subpath}Foo1BeforeFix.sol` + afterFixFile = `${params.path}${params.subpath}Foo1AfterFix.sol` + }) after(function () { - copyFile(sourceFilePath, currentFile) + copyFile(beforeFixFile, currentFile) }) - it('should fix file when noPrompt', () => { - sourceFilePath = `${PATH}${SUBPATH}Foo1BeforeFix.sol` - currentFile = `${PATH}${SUBPATH}Foo1.sol` - result = compareTextFiles(sourceFilePath, `${PATH}${SUBPATH}Foo1.sol`) + it('should compare Foo1 file with template beforeFix file and they should match 5', () => { + result = compareTextFiles(currentFile, beforeFixFile) expect(result).to.be.true + }) + it('should fix file when noPrompt', () => { const { code, stdout } = shell.exec( - `${commands.command} ${commands.param1} -c ${PATH}${SUBPATH}.solhint.json ${currentFile} --fix --disc --noPrompt` + `${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt` ) expect(code).to.equal(1) @@ -252,11 +284,14 @@ describe('e2e', function () { expect(reportLines[reportLines.length - 3]).to.contain(finalLine) }) - it('files should match', () => { - result = compareTextFiles(currentFile, `${PATH}${SUBPATH}Foo1AfterFix.sol`) + it('should compare resulted file with template file and they should match 5', () => { + result = compareTextFiles(currentFile, afterFixFile) expect(result).to.be.true }) }) }) }) }) + +// FALTA LA COMPARACION DEL FIX CON EL TEMPLATE FIX +// FALTA LA PRUEBA DEL STORE TO FILE diff --git a/e2e/package.json b/e2e/package.json index a9b7e733..89599093 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -4,7 +4,7 @@ "description": "E2E tests for solhint", "main": "index.js", "scripts": { - "test": "mocha test.js formatters-test.js autofix-test.js" + "test": "mocha autofix-test.js" }, "author": "", "license": "MIT",