Compilar a serio, testar e documentar: README uniforme + testes + limpeza de artefactos
O relatorio nunca tinha sido compilado neste ambiente. Compila agora com
latexmk -pdf report.tex -> 12 paginas, 0 erros fatais, mas so depois de
instalar texlive-science: o wsdcr.cls carrega matlab-prettifier.sty (linha
156), que falta no texlive-latex-extra e fazia a compilacao parar.
Varios defeitos do documento original ficam apenas registados, porque nao se
altera conteudo: 3 \ref{} com argumento vazio (Control_Design.tex 170 e 186),
2 overfull hbox, 13 underfull, e 0 citacoes (nao ha bibliografia nenhuma).
As 31 figuras referenciadas existem todas em disco; 4.5.eps e 4.png nao sao
referenciados e nao foram apagados.
Testes reais em tests/, alvo make test: compila, confirma 12 paginas, ausencia
de erros fatais no log, existencia de todas as figuras, e devolve != 0 quando
falha. tests/test_report_negative.py prova por negativa que a bateria falha
quando deve (figura inexistente, PDF corrompido). make check corre tudo.
O wsdcr.cls e de terceiros e nao tem licenca declarada; nao foi apagada nem
lhe foi atribuida licenca. A nota de proveniencia no README foi corrigida:
o ficheiro apresenta-se como "Waseda Course Report Class" (2022/10/28), sem
autor individual, curso ou universidade identificaveis.
Artefactos de compilacao (aux, log, toc, fls, fdb_latexmk, synctex.gz e os
24 PDF derivados de eps) saem do indice e entram no .gitignore; o report.pdf
fica versionado porque e o produto.
Licenca continua por definir por co-autoria (Joao Ferreira).
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Teste negativo: injeta defeitos conhecidos e confirma que a bateria falha.
|
||||
|
||||
Um teste que passa sempre nao prova nada. Aqui:
|
||||
1. aponta uma figura para um ficheiro inexistente e confirma que o teste
|
||||
de figuras falha (codigo != 0);
|
||||
2. corrompe o PDF e confirma que o teste de paginas falha.
|
||||
|
||||
Tudo e restaurado no fim (try/finally). Uso: python3 tests/test_report_negative.py
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
ROOT = os.path.dirname(HERE)
|
||||
sys.path.insert(0, HERE)
|
||||
|
||||
import test_report # noqa: E402
|
||||
|
||||
SRC = os.path.join(ROOT, "structure", "Control_Design.tex")
|
||||
|
||||
|
||||
def negative_missing_figure():
|
||||
"""Aponta um \\includegraphics para um ficheiro que nao existe."""
|
||||
print("-" * 68)
|
||||
print("NEGATIVA 1: figura apontada para ficheiro inexistente")
|
||||
print("-" * 68)
|
||||
backup = SRC + ".negbak"
|
||||
shutil.copy2(SRC, backup)
|
||||
try:
|
||||
body = open(SRC, encoding="utf-8").read()
|
||||
injected = body.replace(
|
||||
"\\includegraphics[width=0.49\\textwidth]{imgs/4.1.eps}",
|
||||
"\\includegraphics[width=0.49\\textwidth]{imgs/figura_que_nao_existe.eps}",
|
||||
1,
|
||||
)
|
||||
assert injected != body, "nao consegui injetar a figura em falta"
|
||||
open(SRC, "w", encoding="utf-8").write(injected)
|
||||
|
||||
failures, _ = test_report.run(ROOT, do_build=False)
|
||||
hit = [f for f in failures if "figuras" in f]
|
||||
print(" falhas detetadas: %d" % len(failures))
|
||||
for f in hit:
|
||||
print(" ->", f)
|
||||
if not hit:
|
||||
print(" FALHOU: a ausencia da figura NAO foi detetada")
|
||||
return False
|
||||
print(" OK: a falta de figura foi detetada e a bateria saiu != 0")
|
||||
return True
|
||||
finally:
|
||||
shutil.move(backup, SRC)
|
||||
|
||||
|
||||
def negative_broken_pdf():
|
||||
"""Corrompe o PDF e confirma que o teste de paginas falha."""
|
||||
print()
|
||||
print("-" * 68)
|
||||
print("NEGATIVA 2: PDF ausente/invalido")
|
||||
print("-" * 68)
|
||||
pdf = os.path.join(ROOT, "report.pdf")
|
||||
if not os.path.exists(pdf):
|
||||
print(" SALTA: nao ha report.pdf para corromper")
|
||||
return True
|
||||
backup = pdf + ".negbak"
|
||||
shutil.copy2(pdf, backup)
|
||||
try:
|
||||
with open(pdf, "wb") as fh:
|
||||
fh.write(b"nao e um pdf")
|
||||
failures, _ = test_report.run(ROOT, do_build=False)
|
||||
hit = [f for f in failures if "pdf" in f]
|
||||
print(" falhas detetadas: %d" % len(failures))
|
||||
for f in hit[:4]:
|
||||
print(" ->", f)
|
||||
if not hit:
|
||||
print(" FALHOU: o PDF invalido NAO foi detetado")
|
||||
return False
|
||||
print(" OK: o PDF invalido foi detetado")
|
||||
return True
|
||||
finally:
|
||||
shutil.move(backup, pdf)
|
||||
|
||||
|
||||
def main():
|
||||
print("=" * 68)
|
||||
print("medical-robotic -- testes negativos")
|
||||
print("=" * 68)
|
||||
ok1 = negative_missing_figure()
|
||||
ok2 = negative_broken_pdf()
|
||||
print()
|
||||
print("=" * 68)
|
||||
if ok1 and ok2:
|
||||
print("NEGATIVAS OK -- as verificacoes falham quando devem falhar")
|
||||
return 0
|
||||
print("NEGATIVAS FALHARAM")
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user