From 35515cb438337c32481b16379f39ab3d1234f543 Mon Sep 17 00:00:00 2001 From: Leonel Sanches da Silva Date: Wed, 2 Apr 2025 06:56:08 -0700 Subject: [PATCH 1/2] =?UTF-8?q?-=20Atualiza=C3=A7=C3=A3o=20do=20workflow.?= =?UTF-8?q?=20-=20Testando=20chamadas=20de=20procedimentos,=20conforme=20r?= =?UTF-8?q?eportado=20no=20Discord.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/principal.yml | 36 ++-- fontes/interpretador/interpretador-visualg.ts | 3 +- package.json | 2 +- testes/interpretador.test.ts | 180 +++++++++++------- yarn.lock | 8 +- 5 files changed, 132 insertions(+), 97 deletions(-) diff --git a/.github/workflows/principal.yml b/.github/workflows/principal.yml index f84b450..01c626f 100644 --- a/.github/workflows/principal.yml +++ b/.github/workflows/principal.yml @@ -13,29 +13,29 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: '16' + node-version: '20' # Maneira tradicional de build, sem cobertura. - name: NPM - Dependências run: | sudo npm install - - name: Testes unitários - run: | - sudo npm run testes-unitarios - - name: Cobertura de Código - uses: MishaKav/jest-coverage-comment@main + # - name: Testes unitários + # run: | + # sudo npm run testes-unitarios + # - name: Cobertura de Código + # uses: MishaKav/jest-coverage-comment@main # Os pacotes abaixo continuam dando o seguinte problema: # https://github.com/ArtiomTr/jest-coverage-report-action/issues/233 # A solução dada pelo autor não resolve o problema. - # - uses: ArtiomTr/jest-coverage-report-action@v2 - # id: coverage - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} - # test-script: yarn testes-unitarios - # package-manager: yarn - # output: report-markdown - # - uses: marocchino/sticky-pull-request-comment@v2 - # with: - # message: ${{ steps.coverage.outputs.report }} + - uses: ArtiomTr/jest-coverage-report-action@v2 + id: coverage + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + test-script: yarn testes-unitarios + package-manager: yarn + output: report-markdown + - uses: marocchino/sticky-pull-request-comment@v2 + with: + message: ${{ steps.coverage.outputs.report }} diff --git a/fontes/interpretador/interpretador-visualg.ts b/fontes/interpretador/interpretador-visualg.ts index fbc329b..b828e69 100644 --- a/fontes/interpretador/interpretador-visualg.ts +++ b/fontes/interpretador/interpretador-visualg.ts @@ -7,8 +7,7 @@ import { Construto, FimPara, FormatacaoEscrita, - Logico, - Variavel, + Logico } from '@designliquido/delegua/construtos'; import { Aleatorio, diff --git a/package.json b/package.json index cc7cdf8..ac77f0a 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "deixar-codigo-bonito": "yarn prettier --config .prettierrc --write fontes/**/*.ts" }, "dependencies": { - "@designliquido/delegua": "^0.39.6", + "@designliquido/delegua": "^0.39.8", "lodash": "^4.17.21" }, "devDependencies": { diff --git a/testes/interpretador.test.ts b/testes/interpretador.test.ts index 6fd22fe..7721489 100644 --- a/testes/interpretador.test.ts +++ b/testes/interpretador.test.ts @@ -697,83 +697,119 @@ describe('Interpretador', () => { }); }); - it('Procedimento', async () => { - const saidasMensagens = ['Digite dois valores: ', 'A variavel escolhida é 3'] - // Aqui vamos simular a resposta para duas variáveis de `leia()`. - const respostas = [ - "2", "3" - ]; - (interpretador as any).interfaceEntradaSaida = { - question: (mensagem: string, callback: Function) => { - callback(respostas.pop()); + describe('Procedimentos', () => { + it('Sem parâmetros', async () => { + const retornoLexador = lexador.mapear([ + 'algoritmo "DetectorPesado"', + 'var', + ' I: inteiro', + ' N, Pesado: caractere', + ' P, Mai: real', + 'procedimento Topo', + 'inicio', + ' LimpaTela', + ' EscrevaL("-----------------------------------")', + ' EscrevaL("D E T E C T O R D E P E S A D O")', + ' EscrevaL("-----------------------------------")', + 'fimprocedimento', + 'inicio', + ' Topo', + 'fimalgoritmo' + ], -1); + const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1); + + let chamadasLimpaTela = 0; + interpretador.funcaoLimpaTela = () => { + chamadasLimpaTela++; } - }; - - const retornoLexador = lexador.mapear([ - 'algoritmo "semnome"', - '// Função :', - '// Autor :', - '// Data : 27/02/2014', - '// Seção de Declarações ', - 'var', - 'a,b:inteiro', - 'procedimento mostranumero (a:inteiro;b:inteiro)', - '', - 'inicio', - '', - 'se a > b entao', - ' escreval ("A variavel escolhida é ",a)', - 'senao', - ' escreval ("A variavel escolhida é ",b)', - 'fimse', - 'fimprocedimento', - '', - 'inicio', - 'escreval ("Digite dois valores: ")', - 'leia (a,b)', - 'mostranumero (a,b)', - '', - 'fimalgoritmo' - ], -1); - const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1); - - interpretador.funcaoDeRetorno = (saida: any) => { - expect(saidasMensagens.includes(saida)).toBeTruthy() - } - const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes); + const _saidas: string[] = []; + interpretador.funcaoDeRetorno = (saida: any) => { + _saidas.push(saida); + } + + const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes); + + expect(retornoInterpretador.erros).toHaveLength(0); + expect(chamadasLimpaTela).toBe(1); + expect(_saidas).toHaveLength(3); + }); - expect(retornoInterpretador.erros).toHaveLength(0); + it('Com parâmetros', async () => { + const saidasMensagens = ['Digite dois valores: ', 'A variavel escolhida é 3'] + // Aqui vamos simular a resposta para duas variáveis de `leia()`. + const respostas = [ + "2", "3" + ]; + (interpretador as any).interfaceEntradaSaida = { + question: (mensagem: string, callback: Function) => { + callback(respostas.pop()); + } + }; + + const retornoLexador = lexador.mapear([ + 'algoritmo "semnome"', + '// Função :', + '// Autor :', + '// Data : 27/02/2014', + '// Seção de Declarações ', + 'var', + 'a,b:inteiro', + 'procedimento mostranumero (a:inteiro;b:inteiro)', + 'inicio', + ' se a > b entao', + ' escreval ("A variavel escolhida é ",a)', + ' senao', + ' escreval ("A variavel escolhida é ",b)', + ' fimse', + 'fimprocedimento', + 'inicio', + 'escreval ("Digite dois valores: ")', + 'leia (a,b)', + 'mostranumero (a,b)', + '', + 'fimalgoritmo' + ], -1); + const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1); + + interpretador.funcaoDeRetorno = (saida: any) => { + expect(saidasMensagens.includes(saida)).toBeTruthy() + } + + const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes); + + expect(retornoInterpretador.erros).toHaveLength(0); + }); + + it('Procedimento com passagem por referência', async () => { + const retornoLexador = lexador.mapear([ + 'algoritmo "Exemplo Parametros Referencia"', + 'var', + ' m,n,res: inteiro', + ' procedimento soma (x,y: inteiro; var result: inteiro)', + ' inicio', + ' result <- x + y', + ' fimprocedimento', + 'inicio', + ' n <- 4', + ' m <- -9', + ' soma(n,m,res)', + ' escreva(res)', + 'fimalgoritmo' + ], -1); + + const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1); + + interpretador.funcaoDeRetornoMesmaLinha = (saida: string) => { + expect(saida).toEqual("-5") + } + + const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes); + + expect(retornoInterpretador.erros).toHaveLength(0); + }); }); - it('Procedimento com passagem por referência', async () => { - const retornoLexador = lexador.mapear([ - 'algoritmo "Exemplo Parametros Referencia"', - 'var', - ' m,n,res: inteiro', - ' procedimento soma (x,y: inteiro; var result: inteiro)', - ' inicio', - ' result <- x + y', - ' fimprocedimento', - 'inicio', - ' n <- 4', - ' m <- -9', - ' soma(n,m,res)', - ' escreva(res)', - 'fimalgoritmo' - ], -1); - - const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1); - - interpretador.funcaoDeRetornoMesmaLinha = (saida: string) => { - expect(saida).toEqual("-5") - } - - const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes); - - expect(retornoInterpretador.erros).toHaveLength(0); - }) - it('Operadores Lógicos', async () => { const saidasMensagens = ['A verdadeiro', 'A falso', 'A falso', 'A verdadeiro', 'B falso', 'C verdadeiro'] const retornoLexador = lexador.mapear([ diff --git a/yarn.lock b/yarn.lock index ade2ff5..856353a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -277,10 +277,10 @@ dependencies: "@jridgewell/trace-mapping" "0.3.9" -"@designliquido/delegua@^0.39.6": - version "0.39.6" - resolved "https://registry.yarnpkg.com/@designliquido/delegua/-/delegua-0.39.6.tgz#c9bcd8915492d8a441e45e3ee5786c62f22d200e" - integrity sha512-J5pHpgBZZgZoDeMUtXc4I06JEbv9RzdSsL0wMh9eRa3j8UufZicMGVzExR2naFuydSQDy20+hYaFCu2kFXYQXw== +"@designliquido/delegua@^0.39.8": + version "0.39.8" + resolved "https://registry.yarnpkg.com/@designliquido/delegua/-/delegua-0.39.8.tgz#d6b2b63717aedc95da2c62a96b77419d5794835a" + integrity sha512-nKCL+kDHX8r2oOQdsN2V/K3UVuTZdvNnaPuE3JUmgZR66BlvjsdVSlyLn5yizOrwbVxG9Hoz0KFczLormMKmOg== dependencies: antlr4ts "^0.5.0-alpha.4" browser-process-hrtime "^1.0.0" From d61c380cb5f5a22211995067685724f6b8059638 Mon Sep 17 00:00:00 2001 From: Leonel Sanches da Silva Date: Wed, 2 Apr 2025 07:02:09 -0700 Subject: [PATCH 2/2] Usando workflow sem o `jest-coverage-report-action`. --- .github/workflows/principal.yml | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/principal.yml b/.github/workflows/principal.yml index 01c626f..553dd50 100644 --- a/.github/workflows/principal.yml +++ b/.github/workflows/principal.yml @@ -21,21 +21,20 @@ jobs: - name: NPM - Dependências run: | sudo npm install - # - name: Testes unitários - # run: | - # sudo npm run testes-unitarios - # - name: Cobertura de Código - # uses: MishaKav/jest-coverage-comment@main + - name: Testes unitários + run: | + sudo npm run testes-unitarios + - name: Cobertura de Código + uses: MishaKav/jest-coverage-comment@main # Os pacotes abaixo continuam dando o seguinte problema: - # https://github.com/ArtiomTr/jest-coverage-report-action/issues/233 - # A solução dada pelo autor não resolve o problema. - - uses: ArtiomTr/jest-coverage-report-action@v2 - id: coverage - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - test-script: yarn testes-unitarios - package-manager: yarn - output: report-markdown - - uses: marocchino/sticky-pull-request-comment@v2 - with: - message: ${{ steps.coverage.outputs.report }} + # Error: Error: EACCES: permission denied, rmdir 'node_modules/.bin' + # - uses: ArtiomTr/jest-coverage-report-action@v2 + # id: coverage + # with: + # github-token: ${{ secrets.GITHUB_TOKEN }} + # test-script: yarn testes-unitarios + # package-manager: yarn + # output: report-markdown + # - uses: marocchino/sticky-pull-request-comment@v2 + # with: + # message: ${{ steps.coverage.outputs.report }}