ESP32-basiertes Kraftort-Suchger�t mit GPS, LED-Ring und PlatformIO-Firmware.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

141 Zeilen
4.1KB

  1. # =========================================================================
  2. # Unity - A Test Framework for C
  3. # ThrowTheSwitch.org
  4. # Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams
  5. # SPDX-License-Identifier: MIT
  6. # =========================================================================
  7. # !/usr/bin/ruby
  8. #
  9. # unity_test_summary.rb
  10. #
  11. require 'fileutils'
  12. require 'set'
  13. class UnityTestSummary
  14. include FileUtils::Verbose
  15. attr_reader :report, :total_tests, :failures, :ignored
  16. attr_writer :targets, :root
  17. def initialize(_opts = {})
  18. @report = ''
  19. @total_tests = 0
  20. @failures = 0
  21. @ignored = 0
  22. end
  23. def run
  24. # Clean up result file names
  25. results = @targets.map { |target| target.tr('\\', '/') }
  26. # Dig through each result file, looking for details on pass/fail:
  27. failure_output = []
  28. ignore_output = []
  29. results.each do |result_file|
  30. lines = File.readlines(result_file).map(&:chomp)
  31. raise "Empty test result file: #{result_file}" if lines.empty?
  32. output = get_details(result_file, lines)
  33. failure_output << output[:failures] unless output[:failures].empty?
  34. ignore_output << output[:ignores] unless output[:ignores].empty?
  35. tests, failures, ignored = parse_test_summary(lines)
  36. @total_tests += tests
  37. @failures += failures
  38. @ignored += ignored
  39. end
  40. if @ignored > 0
  41. @report += "\n"
  42. @report += "--------------------------\n"
  43. @report += "UNITY IGNORED TEST SUMMARY\n"
  44. @report += "--------------------------\n"
  45. @report += ignore_output.flatten.join("\n")
  46. end
  47. if @failures > 0
  48. @report += "\n"
  49. @report += "--------------------------\n"
  50. @report += "UNITY FAILED TEST SUMMARY\n"
  51. @report += "--------------------------\n"
  52. @report += failure_output.flatten.join("\n")
  53. end
  54. @report += "\n"
  55. @report += "--------------------------\n"
  56. @report += "OVERALL UNITY TEST SUMMARY\n"
  57. @report += "--------------------------\n"
  58. @report += "#{@total_tests} TOTAL TESTS #{@failures} TOTAL FAILURES #{@ignored} IGNORED\n"
  59. @report += "\n"
  60. end
  61. def usage(err_msg = nil)
  62. puts "\nERROR: "
  63. puts err_msg if err_msg
  64. puts "\nUsage: unity_test_summary.rb result_file_directory/ root_path/"
  65. puts ' result_file_directory - The location of your results files.'
  66. puts ' Defaults to current directory if not specified.'
  67. puts ' Should end in / if specified.'
  68. puts ' root_path - Helpful for producing more verbose output if using relative paths.'
  69. exit 1
  70. end
  71. protected
  72. def get_details(_result_file, lines)
  73. results = { failures: [], ignores: [], successes: [] }
  74. lines.each do |line|
  75. status_match = line.match(/^[^:]+:[^:]+:\w+(?:\([^)]*\))?:([^:]+):?/)
  76. next unless status_match
  77. status = status_match.captures[0]
  78. line_out = (@root && (@root != 0) ? "#{@root}#{line}" : line).gsub(/\//, '\\')
  79. case status
  80. when 'IGNORE' then results[:ignores] << line_out
  81. when 'FAIL' then results[:failures] << line_out
  82. when 'PASS' then results[:successes] << line_out
  83. end
  84. end
  85. results
  86. end
  87. def parse_test_summary(summary)
  88. raise "Couldn't parse test results: #{summary}" unless summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ }
  89. [Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i]
  90. end
  91. end
  92. if $0 == __FILE__
  93. # parse out the command options
  94. opts, args = ARGV.partition { |v| v =~ /^--\w+/ }
  95. opts.map! { |v| v[2..].to_sym }
  96. # create an instance to work with
  97. uts = UnityTestSummary.new(opts)
  98. begin
  99. # look in the specified or current directory for result files
  100. args[0] ||= './'
  101. targets = "#{ARGV[0].tr('\\', '/')}**/*.test*"
  102. results = Dir[targets]
  103. raise "No *.testpass, *.testfail, or *.testresults files found in '#{targets}'" if results.empty?
  104. uts.targets = results
  105. # set the root path
  106. args[1] ||= "#{Dir.pwd}/"
  107. uts.root = ARGV[1]
  108. # run the summarizer
  109. puts uts.run
  110. rescue StandardError => e
  111. uts.usage e.message
  112. end
  113. end