From ae0553bc7224afd4537a348dfd615541ef9db5cf Mon Sep 17 00:00:00 2001 From: Konrad `ktoso` Malawski Date: Tue, 21 Mar 2023 07:47:21 +0900 Subject: [PATCH] remove linux test shims **Motivation:** no longer needed since we require 5.6+ **Modifications:** remove the linux tests generator **Result:** cleaner build --- .../InstrumentTests+XCTest.swift | 33 --- .../InstrumentationSystemTests+XCTest.swift | 33 --- Tests/LinuxMain.swift | 48 ---- .../DynamicTracepointTracerTests+XCTest.swift | 34 --- Tests/TracingTests/SpanTests+XCTest.swift | 44 ---- .../TracingTests/TracedLockTests+XCTest.swift | 33 --- Tests/TracingTests/TracerTests+XCTest.swift | 44 ---- ...ingInstrumentationSystemTests+XCTest.swift | 33 --- scripts/generate_linux_tests.rb | 242 ------------------ scripts/soundness.sh | 12 - 10 files changed, 556 deletions(-) delete mode 100644 Tests/InstrumentationTests/InstrumentTests+XCTest.swift delete mode 100644 Tests/InstrumentationTests/InstrumentationSystemTests+XCTest.swift delete mode 100644 Tests/LinuxMain.swift delete mode 100644 Tests/TracingTests/DynamicTracepointTracerTests+XCTest.swift delete mode 100644 Tests/TracingTests/SpanTests+XCTest.swift delete mode 100644 Tests/TracingTests/TracedLockTests+XCTest.swift delete mode 100644 Tests/TracingTests/TracerTests+XCTest.swift delete mode 100644 Tests/TracingTests/TracingInstrumentationSystemTests+XCTest.swift delete mode 100755 scripts/generate_linux_tests.rb diff --git a/Tests/InstrumentationTests/InstrumentTests+XCTest.swift b/Tests/InstrumentationTests/InstrumentTests+XCTest.swift deleted file mode 100644 index 20c0028..0000000 --- a/Tests/InstrumentationTests/InstrumentTests+XCTest.swift +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Distributed Tracing open source project -// -// Copyright (c) 2020-2021 Apple Inc. and the Swift Distributed Tracing project -// authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// -// -// InstrumentTests+XCTest.swift -// -import XCTest -/// -/// NOTE: This file was generated by generate_linux_tests.rb -/// -/// Do NOT edit this file directly as it will be regenerated automatically when needed. -/// - -extension InstrumentTests { - - @available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings") - static var allTests : [(String, (InstrumentTests) -> () throws -> Void)] { - return [ - ("testMultiplexInvokesAllInstruments", testMultiplexInvokesAllInstruments), - ] - } -} - diff --git a/Tests/InstrumentationTests/InstrumentationSystemTests+XCTest.swift b/Tests/InstrumentationTests/InstrumentationSystemTests+XCTest.swift deleted file mode 100644 index 74d5a19..0000000 --- a/Tests/InstrumentationTests/InstrumentationSystemTests+XCTest.swift +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Distributed Tracing open source project -// -// Copyright (c) 2020-2021 Apple Inc. and the Swift Distributed Tracing project -// authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// -// -// InstrumentationSystemTests+XCTest.swift -// -import XCTest -/// -/// NOTE: This file was generated by generate_linux_tests.rb -/// -/// Do NOT edit this file directly as it will be regenerated automatically when needed. -/// - -extension InstrumentationSystemTests { - - @available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings") - static var allTests : [(String, (InstrumentationSystemTests) -> () throws -> Void)] { - return [ - ("testItProvidesAccessToASingletonInstrument", testItProvidesAccessToASingletonInstrument), - ] - } -} - diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift deleted file mode 100644 index c8bf729..0000000 --- a/Tests/LinuxMain.swift +++ /dev/null @@ -1,48 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Distributed Tracing open source project -// -// Copyright (c) 2020-2021 Apple Inc. and the Swift Distributed Tracing project -// authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// -// -// LinuxMain.swift -// -import XCTest -/// -/// NOTE: This file was generated by generate_linux_tests.rb -/// -/// Do NOT edit this file directly as it will be regenerated automatically when needed. -/// - -#if os(Linux) || os(FreeBSD) - @testable import InstrumentationTests - @testable import TracingTests - -// This protocol is necessary to we can call the 'run' method (on an existential of this protocol) -// without the compiler noticing that we're calling a deprecated function. -// This hack exists so we can deprecate individual tests which test deprecated functionality without -// getting a compiler warning... -protocol LinuxMainRunner { func run() } -class LinuxMainRunnerImpl: LinuxMainRunner { - @available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings") - func run() { - XCTMain([ - testCase(DynamicTracepointTracerTests.allTests), - testCase(InstrumentTests.allTests), - testCase(InstrumentationSystemTests.allTests), - testCase(SpanTests.allTests), - testCase(TracedLockTests.allTests), - testCase(TracerTests.allTests), - testCase(TracingInstrumentationSystemTests.allTests), - ]) - } -} -(LinuxMainRunnerImpl() as LinuxMainRunner).run() -#endif diff --git a/Tests/TracingTests/DynamicTracepointTracerTests+XCTest.swift b/Tests/TracingTests/DynamicTracepointTracerTests+XCTest.swift deleted file mode 100644 index 8c3a061..0000000 --- a/Tests/TracingTests/DynamicTracepointTracerTests+XCTest.swift +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Distributed Tracing open source project -// -// Copyright (c) 2020-2021 Apple Inc. and the Swift Distributed Tracing project -// authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// -// -// DynamicTracepointTracerTests+XCTest.swift -// -import XCTest -/// -/// NOTE: This file was generated by generate_linux_tests.rb -/// -/// Do NOT edit this file directly as it will be regenerated automatically when needed. -/// - -extension DynamicTracepointTracerTests { - - @available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings") - static var allTests : [(String, (DynamicTracepointTracerTests) -> () throws -> Void)] { - return [ - ("test_adhoc_enableBySourceLoc", test_adhoc_enableBySourceLoc), - ("test_adhoc_enableByFunction", test_adhoc_enableByFunction), - ] - } -} - diff --git a/Tests/TracingTests/SpanTests+XCTest.swift b/Tests/TracingTests/SpanTests+XCTest.swift deleted file mode 100644 index fbd5ec5..0000000 --- a/Tests/TracingTests/SpanTests+XCTest.swift +++ /dev/null @@ -1,44 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Distributed Tracing open source project -// -// Copyright (c) 2020-2021 Apple Inc. and the Swift Distributed Tracing project -// authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// -// -// SpanTests+XCTest.swift -// -import XCTest -/// -/// NOTE: This file was generated by generate_linux_tests.rb -/// -/// Do NOT edit this file directly as it will be regenerated automatically when needed. -/// - -extension SpanTests { - - @available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings") - static var allTests : [(String, (SpanTests) -> () throws -> Void)] { - return [ - ("testSpanEventIsExpressibleByStringLiteral", testSpanEventIsExpressibleByStringLiteral), - ("testSpanAttributeIsExpressibleByStringLiteral", testSpanAttributeIsExpressibleByStringLiteral), - ("testSpanAttributeIsExpressibleByStringInterpolation", testSpanAttributeIsExpressibleByStringInterpolation), - ("testSpanAttributeIsExpressibleByIntegerLiteral", testSpanAttributeIsExpressibleByIntegerLiteral), - ("testSpanAttributeIsExpressibleByFloatLiteral", testSpanAttributeIsExpressibleByFloatLiteral), - ("testSpanAttributeIsExpressibleByBooleanLiteral", testSpanAttributeIsExpressibleByBooleanLiteral), - ("testSpanAttributeIsExpressibleByArrayLiteral", testSpanAttributeIsExpressibleByArrayLiteral), - ("testSpanAttributesUX", testSpanAttributesUX), - ("testSpanAttributesCustomValue", testSpanAttributesCustomValue), - ("testSpanAttributesAreIterable", testSpanAttributesAreIterable), - ("testSpanAttributesMerge", testSpanAttributesMerge), - ("testSpanParentConvenience", testSpanParentConvenience), - ] - } -} - diff --git a/Tests/TracingTests/TracedLockTests+XCTest.swift b/Tests/TracingTests/TracedLockTests+XCTest.swift deleted file mode 100644 index 84d1a42..0000000 --- a/Tests/TracingTests/TracedLockTests+XCTest.swift +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Distributed Tracing open source project -// -// Copyright (c) 2020-2021 Apple Inc. and the Swift Distributed Tracing project -// authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// -// -// TracedLockTests+XCTest.swift -// -import XCTest -/// -/// NOTE: This file was generated by generate_linux_tests.rb -/// -/// Do NOT edit this file directly as it will be regenerated automatically when needed. -/// - -extension TracedLockTests { - - @available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings") - static var allTests : [(String, (TracedLockTests) -> () throws -> Void)] { - return [ - ("test_tracesLockedTime", test_tracesLockedTime), - ] - } -} - diff --git a/Tests/TracingTests/TracerTests+XCTest.swift b/Tests/TracingTests/TracerTests+XCTest.swift deleted file mode 100644 index b5a8cf1..0000000 --- a/Tests/TracingTests/TracerTests+XCTest.swift +++ /dev/null @@ -1,44 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Distributed Tracing open source project -// -// Copyright (c) 2020-2021 Apple Inc. and the Swift Distributed Tracing project -// authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// -// -// TracerTests+XCTest.swift -// -import XCTest -/// -/// NOTE: This file was generated by generate_linux_tests.rb -/// -/// Do NOT edit this file directly as it will be regenerated automatically when needed. -/// - -extension TracerTests { - - @available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings") - static var allTests : [(String, (TracerTests) -> () throws -> Void)] { - return [ - ("testContextPropagation", testContextPropagation), - ("testContextPropagationWithNoOpSpan", testContextPropagationWithNoOpSpan), - ("testWithSpan_success", testWithSpan_success), - ("testWithSpan_throws", testWithSpan_throws), - ("testWithSpan_automaticBaggagePropagation_sync", testWithSpan_automaticBaggagePropagation_sync), - ("testWithSpan_automaticBaggagePropagation_sync_throws", testWithSpan_automaticBaggagePropagation_sync_throws), - ("testWithSpan_automaticBaggagePropagation_async", testWithSpan_automaticBaggagePropagation_async), - ("testWithSpan_enterFromNonAsyncCode_passBaggage_asyncOperation", testWithSpan_enterFromNonAsyncCode_passBaggage_asyncOperation), - ("testWithSpan_automaticBaggagePropagation_async_throws", testWithSpan_automaticBaggagePropagation_async_throws), - ("test_static_Tracer_withSpan_automaticBaggagePropagation_async_throws", test_static_Tracer_withSpan_automaticBaggagePropagation_async_throws), - ("test_static_Tracer_withSpan_automaticBaggagePropagation_throws", test_static_Tracer_withSpan_automaticBaggagePropagation_throws), - ("testWithSpan_recordErrorWithAttributes", testWithSpan_recordErrorWithAttributes), - ] - } -} - diff --git a/Tests/TracingTests/TracingInstrumentationSystemTests+XCTest.swift b/Tests/TracingTests/TracingInstrumentationSystemTests+XCTest.swift deleted file mode 100644 index ef03044..0000000 --- a/Tests/TracingTests/TracingInstrumentationSystemTests+XCTest.swift +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Distributed Tracing open source project -// -// Copyright (c) 2020-2021 Apple Inc. and the Swift Distributed Tracing project -// authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// -// -// TracingInstrumentationSystemTests+XCTest.swift -// -import XCTest -/// -/// NOTE: This file was generated by generate_linux_tests.rb -/// -/// Do NOT edit this file directly as it will be regenerated automatically when needed. -/// - -extension TracingInstrumentationSystemTests { - - @available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings") - static var allTests : [(String, (TracingInstrumentationSystemTests) -> () throws -> Void)] { - return [ - ("testItProvidesAccessToATracer", testItProvidesAccessToATracer), - ] - } -} - diff --git a/scripts/generate_linux_tests.rb b/scripts/generate_linux_tests.rb deleted file mode 100755 index dc8bfa3..0000000 --- a/scripts/generate_linux_tests.rb +++ /dev/null @@ -1,242 +0,0 @@ -#!/usr/bin/env ruby - -# -# process_test_files.rb -# -# Copyright 2016 Tony Stone -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Created by Tony Stone on 5/4/16. -# -require 'getoptlong' -require 'fileutils' -require 'pathname' - -include FileUtils - -# -# This ruby script will auto generate LinuxMain.swift and the +XCTest.swift extension files for Swift Package Manager on Linux platforms. -# -# See https://github.com/apple/swift-corelibs-xctest/blob/master/Documentation/Linux.md -# -def header(fileName) - string = <<-eos -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Distributed Tracing open source project -// -// Copyright (c) 2020-2021 Apple Inc. and the Swift Distributed Tracing project -// authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// -// -// -// -import XCTest -/// -/// NOTE: This file was generated by generate_linux_tests.rb -/// -/// Do NOT edit this file directly as it will be regenerated automatically when needed. -/// - eos - - string - .sub('', File.basename(fileName)) - .sub('', Time.now.to_s) -end - -def createExtensionFile(fileName, classes) - extensionFile = fileName.sub! '.swift', '+XCTest.swift' - print 'Creating file: ' + extensionFile + "\n" - - File.open(extensionFile, 'w') do |file| - file.write header(extensionFile) - file.write "\n" - - for classArray in classes - file.write 'extension ' + classArray[0] + " {\n\n" - file.write ' @available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")' +"\n" - file.write ' static var allTests : [(String, (' + classArray[0] + ") -> () throws -> Void)] {\n" - file.write " return [\n" - - for funcName in classArray[1] - file.write ' ("' + funcName + '", ' + funcName + "),\n" - end - - file.write " ]\n" - file.write " }\n" - file.write "}\n\n" - end - end -end - -def createLinuxMain(testsDirectory, allTestSubDirectories, files) - fileName = testsDirectory + '/LinuxMain.swift' - print 'Creating file: ' + fileName + "\n" - - File.open(fileName, 'w') do |file| - file.write header(fileName) - file.write "\n" - - file.write "#if os(Linux) || os(FreeBSD)\n" - for testSubDirectory in allTestSubDirectories.sort { |x, y| x <=> y } - file.write ' @testable import ' + testSubDirectory + "\n" - end - file.write "\n" - file.write "// This protocol is necessary to we can call the 'run' method (on an existential of this protocol)\n" - file.write "// without the compiler noticing that we're calling a deprecated function.\n" - file.write "// This hack exists so we can deprecate individual tests which test deprecated functionality without\n" - file.write "// getting a compiler warning...\n" - file.write "protocol LinuxMainRunner { func run() }\n" - file.write "class LinuxMainRunnerImpl: LinuxMainRunner {\n" - file.write ' @available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")' + "\n" - file.write " func run() {\n" - file.write " XCTMain([\n" - - testCases = [] - for classes in files - for classArray in classes - testCases << classArray[0] - end - end - - for testCase in testCases.sort { |x, y| x <=> y } - file.write ' testCase(' + testCase + ".allTests),\n" - end - file.write " ])\n" - file.write " }\n" - file.write "}\n" - file.write "(LinuxMainRunnerImpl() as LinuxMainRunner).run()\n" - file.write "#endif\n" - end -end - -def parseSourceFile(fileName) - puts 'Parsing file: ' + fileName + "\n" - - classes = [] - currentClass = nil - inIfLinux = false - inElse = false - ignore = false - - # - # Read the file line by line - # and parse to find the class - # names and func names - # - File.readlines(fileName).each do |line| - if inIfLinux - if /\#else/.match(line) - inElse = true - ignore = true - else - if /\#end/.match(line) - inElse = false - inIfLinux = false - ignore = false - end - end - else - if /\#if[ \t]+os\(Linux\)/.match(line) - inIfLinux = true - ignore = false - end - end - - next if ignore - # Match class or func - match = line[/class[ \t]+[a-zA-Z0-9_]*(?=[ \t]*:[ \t]*XCTestCase)|func[ \t]+test[a-zA-Z0-9_]*(?=[ \t]*\(\))/, 0] - if match - - if match[/class/, 0] == 'class' - className = match.sub(/^class[ \t]+/, '') - # - # Create a new class / func structure - # and add it to the classes array. - # - currentClass = [className, []] - classes << currentClass - else # Must be a func - funcName = match.sub(/^func[ \t]+/, '') - # - # Add each func name the the class / func - # structure created above. - # - currentClass[1] << funcName - end - end - end - classes -end - -# -# Main routine -# -# - -testsDirectory = 'Tests' - -options = GetoptLong.new(['--tests-dir', GetoptLong::OPTIONAL_ARGUMENT]) -options.quiet = true - -begin - options.each do |option, value| - case option - when '--tests-dir' - testsDirectory = value - end - end -rescue GetoptLong::InvalidOption -end - -allTestSubDirectories = [] -allFiles = [] - -Dir[testsDirectory + '/*'].each do |subDirectory| - next unless File.directory?(subDirectory) - directoryHasClasses = false - Dir[subDirectory + '/*Test{s,}.swift'].each do |fileName| - next unless File.file? fileName - fileClasses = parseSourceFile(fileName) - - # - # If there are classes in the - # test source file, create an extension - # file for it. - # - next unless fileClasses.count > 0 - createExtensionFile(fileName, fileClasses) - directoryHasClasses = true - allFiles << fileClasses - end - - if directoryHasClasses - allTestSubDirectories << Pathname.new(subDirectory).split.last.to_s - end -end - -# -# Last step is the create a LinuxMain.swift file that -# references all the classes and funcs in the source files. -# -if allFiles.count > 0 - createLinuxMain(testsDirectory, allTestSubDirectories, allFiles) -end -# eof diff --git a/scripts/soundness.sh b/scripts/soundness.sh index f2fce6b..73cb962 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -16,18 +16,6 @@ set -eu here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -printf "=> Checking linux tests... " -FIRST_OUT="$(git status --porcelain)" -ruby "$here/../scripts/generate_linux_tests.rb" > /dev/null -SECOND_OUT="$(git status --porcelain)" -if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then - printf "\033[0;31mmissing changes!\033[0m\n" - git --no-pager diff - exit 1 -else - printf "\033[0;32mokay.\033[0m\n" -fi - bash $here/validate_license_headers.sh bash $here/validate_language.sh bash $here/validate_format.sh