NTestTapOut.lua 1.1 KB

123456789101112131415161718192021222324252627282930
  1. -- This is a NTest output handler that formats its output in a way that
  2. -- resembles the Test Anything Protocol (though prefixed with "TAP: " so we can
  3. -- more readily find it in comingled output streams).
  4. local nrun
  5. return function(e, test, msg, err)
  6. msg = msg or ""
  7. err = err or ""
  8. if e == "pass" then
  9. print(("\nTAP: ok %d %s # %s"):format(nrun, test, msg))
  10. nrun = nrun + 1
  11. elseif e == "fail" then
  12. print(("\nTAP: not ok %d %s # %s: %s"):format(nrun, test, msg, err))
  13. nrun = nrun + 1
  14. elseif e == "except" then
  15. print(("\nTAP: not ok %d %s # exn; %s: %s"):format(nrun, test, msg, err))
  16. nrun = nrun + 1
  17. elseif e == "abort" then
  18. print(("\nTAP: Bail out! %d %s # exn; %s: %s"):format(nrun, test, msg, err))
  19. elseif e == "start" then
  20. -- We don't know how many tests we plan to run, so emit a comment instead
  21. print(("\nTAP: # STARTUP %s"):format(test))
  22. nrun = 1
  23. elseif e == "finish" then
  24. -- Ah, now, here we go; we know how many tests we ran, so signal completion
  25. print(("\nTAP: POST 1..%d"):format(nrun))
  26. elseif #msg ~= 0 or #err ~= 0 then
  27. print(("\nTAP: # %s: %s: %s"):format(test, msg, err))
  28. end
  29. end