@devquest/cli 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -10,7 +10,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
10
10
|
const fs_1 = __importDefault(require("fs"));
|
|
11
11
|
/**
|
|
12
12
|
* Suite de testes para o desafio Build Your Own Formatter
|
|
13
|
-
* Estágio 1:
|
|
13
|
+
* Estágio 1: fmt_read (Leitura e Saída Crua)
|
|
14
14
|
*/
|
|
15
15
|
async function runStage(stage, cwd) {
|
|
16
16
|
console.log(chalk_1.default.blue(`\n[Test Suite] Avaliando Estágio ${stage} para build-your-own-formatter...`));
|
|
@@ -21,56 +21,47 @@ async function runStage(stage, cwd) {
|
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
23
23
|
async function testStage1(cwd) {
|
|
24
|
-
console.log(chalk_1.default.gray(`[
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
shell: true,
|
|
38
|
-
cwd,
|
|
39
|
-
encoding: 'utf-8'
|
|
40
|
-
});
|
|
41
|
-
if (result.status !== 0) {
|
|
42
|
-
console.log(chalk_1.default.red(`❌ Erro ao executar o código: ${result.stderr}`));
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
const output = result.stdout;
|
|
46
|
-
console.log(chalk_1.default.gray(`Saída do usuário:\n${output}`));
|
|
47
|
-
// Validação rigorosa: O Estágio 1 espera que o usuário imprima uma lista de tokens em JSON
|
|
48
|
-
try {
|
|
49
|
-
const tokens = JSON.parse(output.trim());
|
|
50
|
-
const hasConst = tokens.some((t) => t.type === 'KEYWORD' && t.value === 'const');
|
|
51
|
-
const hasIdentifier = tokens.some((t) => t.type === 'IDENTIFIER' && t.value === 'x');
|
|
52
|
-
const hasLiteral = tokens.some((t) => t.type === 'LITERAL' && t.value === '10');
|
|
53
|
-
if (hasConst && hasIdentifier && hasLiteral) {
|
|
54
|
-
console.log(chalk_1.default.green(`✅ Scanner identificou os tokens (const, x, 10) corretamente no formato JSON.`));
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
console.log(chalk_1.default.red(`❌ Scanner produziu JSON, mas os tokens esperados (const, x, 10) não foram encontrados ou estão no formato errado.`));
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch (e) {
|
|
63
|
-
console.log(chalk_1.default.red(`❌ Erro de Formato: O Estágio 1 exige que o Scanner imprima a lista de tokens em formato JSON válido.`));
|
|
64
|
-
console.log(chalk_1.default.yellow(`Exemplo esperado: [{"type": "KEYWORD", "value": "const"}, ...]`));
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
24
|
+
console.log(chalk_1.default.gray(`[Validador fmt_read] Validando se o arquivo é lido e impresso sem alterações...`));
|
|
25
|
+
const entryPoint = fs_1.default.existsSync(path_1.default.join(cwd, 'dist/index.js'))
|
|
26
|
+
? 'dist/index.js'
|
|
27
|
+
: 'src/index.ts';
|
|
28
|
+
const cmd = entryPoint.endsWith('.ts') ? 'npx ts-node' : 'node';
|
|
29
|
+
// 1. Teste de Leitura Correta
|
|
30
|
+
const testFilePath = path_1.default.join(cwd, 'test_sample.ts');
|
|
31
|
+
const sampleContent = 'const a = 1;\nconsole.log(a);';
|
|
32
|
+
fs_1.default.writeFileSync(testFilePath, sampleContent);
|
|
33
|
+
const runValid = (0, child_process_1.spawnSync)(`${cmd} ${entryPoint} ${testFilePath}`, { shell: true, cwd, encoding: 'utf-8' });
|
|
34
|
+
if (runValid.status !== 0) {
|
|
35
|
+
console.log(chalk_1.default.red(`\n❌ Erro: O programa deve retornar exit code 0 para arquivos válidos. Recebido: ${runValid.status}`));
|
|
36
|
+
return false;
|
|
67
37
|
}
|
|
68
|
-
|
|
69
|
-
console.log(chalk_1.default.red(
|
|
38
|
+
if (runValid.stdout.trim() !== sampleContent.trim()) {
|
|
39
|
+
console.log(chalk_1.default.red(`\n❌ Erro: O conteúdo impresso no stdout não coincide exatamente com o esperado.`));
|
|
40
|
+
console.log(chalk_1.default.bgGreen.black('\n ESPERADO (Correct Content) '));
|
|
41
|
+
console.log(chalk_1.default.green(sampleContent));
|
|
42
|
+
console.log(chalk_1.default.bgRed.black('\n RECEBIDO (Your Output) '));
|
|
43
|
+
console.log(chalk_1.default.red(runValid.stdout));
|
|
44
|
+
console.log(chalk_1.default.yellow(`\n💡 Dica: Verifique se você não está imprimindo mensagens de depuração ou espaços extras.`));
|
|
70
45
|
return false;
|
|
71
46
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
47
|
+
console.log(chalk_1.default.green(`✅ Conteúdo lido e impresso corretamente.`));
|
|
48
|
+
// 2. Teste de Ausência de Argumentos
|
|
49
|
+
console.log(chalk_1.default.gray(`[Validador usage] Verificando tratamento de falta de argumentos...`));
|
|
50
|
+
const runNoArgs = (0, child_process_1.spawnSync)(`${cmd} ${entryPoint}`, { shell: true, cwd, encoding: 'utf-8' });
|
|
51
|
+
if (runNoArgs.status === 0) {
|
|
52
|
+
console.log(chalk_1.default.red(`\n❌ Erro: O programa deve retornar exit code 1 quando nenhum argumento é passado.`));
|
|
53
|
+
return false;
|
|
75
54
|
}
|
|
55
|
+
console.log(chalk_1.default.green(`✅ Tratamento de falta de argumentos validado.`));
|
|
56
|
+
// 3. Teste de Arquivo Inexistente
|
|
57
|
+
console.log(chalk_1.default.gray(`[Validador file_error] Verificando tratamento de arquivo inexistente...`));
|
|
58
|
+
const runInexistent = (0, child_process_1.spawnSync)(`${cmd} ${entryPoint} inexistent.ts`, { shell: true, cwd, encoding: 'utf-8' });
|
|
59
|
+
if (runInexistent.status === 0) {
|
|
60
|
+
console.log(chalk_1.default.red(`\n❌ Erro: O programa deve retornar exit code 1 para arquivos inexistentes.`));
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
console.log(chalk_1.default.green(`✅ Tratamento de arquivo inexistente validado.`));
|
|
64
|
+
if (fs_1.default.existsSync(testFilePath))
|
|
65
|
+
fs_1.default.unlinkSync(testFilePath);
|
|
66
|
+
return true;
|
|
76
67
|
}
|