CollectTests.awk 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/awk -f
  2. # ProtobufRuntime/Sources/Protobuf/ProtobufBinaryEncoding.swift - Binary encoding support
  3. #
  4. # This source file is part of the Swift.org open source project
  5. #
  6. # Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
  7. # Licensed under Apache License v2.0 with Runtime Library Exception
  8. #
  9. # See http://swift.org/LICENSE.txt for license information
  10. # See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
  11. #
  12. # -----------------------------------------------------------------------------
  13. #
  14. # The Linux version of XCTest cannot automatically
  15. # discover tests at run-time. So you can either manually
  16. # maintain lists of tests or collect them at build time.
  17. #
  18. # This script is used by the Makefile to do the latter:
  19. # = Scans each XCTest source file for 'class Foo: XCTestCase'
  20. # = Looks for 'func test*' within those classes
  21. # = Emits a class extension with the necessary 'allTests' property
  22. # = Emits an XCTMain invocation to run all the classes
  23. #
  24. # The macOS version of XCTest has another mechanism for
  25. # finding tests at run-time, so this is not needed there.
  26. #
  27. # -----------------------------------------------------------------------------
  28. BEGIN {
  29. CLASS=""
  30. TESTCASES=""
  31. TESTCASE_separator=""
  32. printf("//\n")
  33. printf("// GENERATED FILE\n")
  34. printf("// DO NOT EDIT\n")
  35. printf("// swift-format-ignore-file\n")
  36. printf("//\n")
  37. printf("\n")
  38. printf("import XCTest\n")
  39. printf("@testable import SwiftProtobufTests\n")
  40. printf("@testable import SwiftProtobufPluginLibraryTests\n")
  41. printf("\n")
  42. }
  43. /class .*:.* XCTestCase/ {
  44. if (CLASS != "") {
  45. printf("\n ]\n")
  46. printf("}\n")
  47. }
  48. split($0, a, ":")
  49. n=split(a[1], words, " ")
  50. CLASS=words[n]
  51. TESTCASES = TESTCASES TESTCASE_separator "\n" " testCase(" CLASS ".allTests)"
  52. TESTCASE_separator = ","
  53. printf("\n")
  54. printf("extension %s {\n", CLASS)
  55. printf(" static var allTests = [")
  56. FUNC_separator=""
  57. }
  58. /^ *func *test.*/ {
  59. split($0, a, "(")
  60. split(a[1], words, " ")
  61. FUNC=words[2]
  62. printf("")
  63. printf("%s\n (\"%s\", %s)", FUNC_separator, FUNC, FUNC)
  64. FUNC_separator = ","
  65. }
  66. END {
  67. if (CLASS != "") {
  68. printf("\n ]\n")
  69. printf("}\n")
  70. }
  71. printf("\n")
  72. printf("XCTMain(\n")
  73. printf(" [")
  74. printf(TESTCASES)
  75. printf("\n ]\n)\n")
  76. }