diff --git a/languages/swift/runnables.scm b/languages/swift/runnables.scm index ce677fd..fb9dec4 100644 --- a/languages/swift/runnables.scm +++ b/languages/swift/runnables.scm @@ -1,4 +1,11 @@ -;; @Suite struct TestSuite +;; Tags are named according to which testing library the test uses: +;; swift-testing-* = Swift Testing library +;; swift-xctest-* = XCTest library +;; +;; While the tasks defined in this extension don't care which library is used, +;; other tasks built by users might. + +;; @Suite struct/class ( (class_declaration (modifiers @@ -8,78 +15,102 @@ ) ) ) - name: (type_identifier) @_name - ) @_swift-test-suite - (#set! tag swift-test-suite) + name: (type_identifier) @_name @SWIFT_TEST_CLASS + ) @_swift-testing-suite + (#set! tag swift-testing-suite) ) -;; @Test test func +;; @Test top-level func ( - (function_declaration - (modifiers - (attribute - (user_type - (type_identifier) @run (#eq? @run "Test") + (source_file + (function_declaration + (modifiers + (attribute + (user_type + (type_identifier) @run (#eq? @run "Test") + ) + ) ) + name: (simple_identifier) @_name @SWIFT_TEST_FUNC + ) @_swift-testing-bare-func + ) + (#set! tag swift-testing-bare-func) +) + +;; @Test within struct/class +( + (class_declaration + name: (type_identifier) @_name @SWIFT_TEST_CLASS + body: (class_body + (function_declaration + (modifiers + (attribute + (user_type + (type_identifier) @run (#eq? @run "Test") + ) + ) + ) + name: (simple_identifier) @_name @SWIFT_TEST_FUNC ) ) - name: (simple_identifier) @_name - ) @_swift-test-test - (#set! tag swift-test-test) + ) @_swift-testing-member-func + (#set! tag swift-testing-member-func) ) -;; QuickSpec subclass +;; XCTestCase subclass ( (class_declaration - name: (type_identifier) @_name + name: (type_identifier) @SWIFT_TEST_CLASS (inheritance_specifier inherits_from: (user_type - (type_identifier) @run (#eq? @run "QuickSpec") + (type_identifier) @run (#eq? @run "XCTestCase") ) ) - ) @_swift-test-quick-spec - (#set! tag swift-test-quick-spec) + ) @_swift-xctest-class + (#set! tag swift-xctest-class) ) -;; AsyncSpec subclass +;; Test function within XCTestCase ( (class_declaration - name: (type_identifier) @_name + name: (type_identifier) @SWIFT_TEST_CLASS (inheritance_specifier inherits_from: (user_type - (type_identifier) @run (#eq? @run "AsyncSpec") + (type_identifier) @_superclass_name (#eq? @_superclass_name "XCTestCase") ) ) - ) @_swift-test-async-spec - (#set! tag swift-test-async-spec) + body: (class_body + (function_declaration + name: (simple_identifier) @_name @SWIFT_TEST_FUNC @run (#match? @run "^test") + ) + ) + ) @_swift-xctest-func + (#set! tag swift-xctest-func) ) -;; XCTestCase subclass + +;; QuickSpec subclass ( (class_declaration name: (type_identifier) @_name (inheritance_specifier inherits_from: (user_type - (type_identifier) @run (#eq? @run "XCTestCase") + (type_identifier) @run (#eq? @run "QuickSpec") ) ) - ) @_swift-test-test-case - (#set! tag swift-test-test-case) + ) @_swift-test-quick-spec + (#set! tag swift-test-quick-spec) ) -;; Test function within XCTestCase +;; AsyncSpec subclass ( (class_declaration + name: (type_identifier) @_name (inheritance_specifier inherits_from: (user_type - (type_identifier) @test_class_name (#eq? @test_class_name "XCTestCase") - ) - ) - body: (class_body - (function_declaration - name: (simple_identifier) @_name @run (#match? @run "^test") + (type_identifier) @run (#eq? @run "AsyncSpec") ) ) - ) @_swift-test-func - (#set! tag swift-test-func) -) + ) @_swift-test-async-spec + (#set! tag swift-test-async-spec) +) \ No newline at end of file diff --git a/languages/swift/tasks.json b/languages/swift/tasks.json index 7da5b0c..8ca29aa 100644 --- a/languages/swift/tasks.json +++ b/languages/swift/tasks.json @@ -1,16 +1,33 @@ [ - // These don't yet work: `swift test --filter` only supports Symbols (not filenames) - // { - // "label": "swift test", - // "command": "swift", - // "args": ["test", "--filter", "${ZED_STEM}"], - // "tags": [ - // "swift-test-async-spec", - // "swift-test-quick-spec", - // "swift-test-func", - // "swift-test-suite", - // "swift-test-test-case", - // "swift-test-test" - // ] - // } + // The first component of a test specifier is the test target name. Since we don't + // know that here, our filters match any leading word. + // + // Test specifiers can be listed with "swift test list". + + { + "label": "$ZED_CUSTOM_SWIFT_TEST_CLASS test", + "command": "swift", + "args": ["test", "--filter", "'^\\w+\\.$ZED_CUSTOM_SWIFT_TEST_CLASS/'"], + "tags": ["swift-xctest-class", "swift-testing-suite"] + }, + { + "label": "$ZED_CUSTOM_SWIFT_TEST_CLASS.$ZED_CUSTOM_SWIFT_TEST_FUNC test", + "command": "swift", + "args": [ + "test", + "--filter", + "'^\\w+\\.$ZED_CUSTOM_SWIFT_TEST_CLASS/$ZED_CUSTOM_SWIFT_TEST_FUNC\\b'" + ], + "tags": ["swift-xctest-func", "swift-testing-member-func"] + }, + { + "label": "$ZED_CUSTOM_SWIFT_TEST_FUNC test", + "command": "swift", + "args": [ + "test", + "--filter", + "'^\\w+\\.$ZED_CUSTOM_SWIFT_TEST_FUNC\\b'" + ], + "tags": ["swift-testing-bare-func"] + } ]