Skip to content

[lldb] Add test for Swift.DecodingError enum #8813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lldb/test/API/lang/swift/enums/decoding_error/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SWIFT_SOURCES := main.swift

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import os


class TestCase(TestBase):
@swiftTest
@skipUnlessFoundation
def test_swift_decoding_error(self):
"""Regression test for Swift.DecodingError, a specific instance of a multipayload enum."""
self.build()
lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift")
)

substrs = [
"(DecodingError) ", " = keyNotFound {",
'debugDescription = "No value associated with key CodingKeys(stringValue: \\"number\\", intValue: nil)',
]
self.expect("frame variable error", substrs=substrs)
self.expect("expression error", substrs=substrs)
16 changes: 16 additions & 0 deletions lldb/test/API/lang/swift/enums/decoding_error/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Foundation

struct Payload: Decodable {
var number: Int
}

func main() {
do {
let data = Data(#"{"numero":23}"#.utf8)
_ = try JSONDecoder().decode(Payload.self, from: data)
} catch {
print("break here")
}
}

main()