[swift-corelibs-dev] Strange behavior the same code fails when building a Cocoa CLI and succeeds in Swift-corelibs-foundation context.

Philippe Hausler phausler at apple.com
Mon Dec 18 11:00:59 CST 2017


Good find, 

You can make a pull request and we can get our continuous integration servers to start building that and testing your change – that is probably the easiest way to get validation on your tests and changes.

There are a few issues however with your test that might be worth considering. Comments inline...

> On Dec 18, 2017, at 8:45 AM, Benoit Pereira da silva via swift-corelibs-dev <swift-corelibs-dev at swift.org> wrote:
> 
> Dear All,
> 
> 
> I do encounter a very strange Issue.
> 
> I have been adding a test to `swift-corelibs-foundation/testJSONSerialization.swift`
> This test succeed within swift-corelibs-foundation test, but fails when repackaged to a Cocoa CLI app.
> 
> The  swift-corelibs-foundation test : 
> 
> 
>     func test_serializeFloatingPointWithANonDotDecimalSeparatorLocale() {
>         // We use a locale that is using "," as decimal separator.
>         setlocale(LC_ALL,"fr_FR”)

This change will set the locale globally for the rest of the process, you probably want to make sure to reset the locale back to it’s original state.

> 
>         let dictionary = ["decimalValue":1.1]
>         do{
>             let data = try JSONSerialization.data(withJSONObject: dictionary)
>             if let json =  String(data:data, encoding:.utf8){
>                 XCTAssert(!json.contains(","), "Expected result: \"{\"decimalValue\":1.1000000000000001}\" found: \"\(json)\"" )
>             }else{
>                 XCTFail("Failed during string encoding")
>             }
>         }catch{
>             XCTFail("Failed during serialization")
>         }
>     }
> 
> 
> The simple CLI code that proves the bug (https://bugs.swift.org/browse/SR-6631 <https://bugs.swift.org/browse/SR-6631>)
> 
> //
> //  main.swift
> //  doubleEncoding
> //
> //  Created by Benoit Pereira da silva on 02/12/2017.
> //  Copyright © 2017 Pereira da Silva. All rights reserved.
> //
> 
> import Foundation
> 
> // Let's set to french
> setlocale(LC_ALL,"fr_FR")
> 
> do{
>     let dictionary = ["decimalValue":1.1]
>     let data = try JSONSerialization.data(withJSONObject: dictionary)
>     if let json =  String(data:data, encoding:.utf8){
>         // the result is : "{"decimalValue":1,1000000000000001}"
>         // The decimal separator should not be "," but "."
>         print(json)
>     }
> }catch{
>     print("\(error)")
> }
> 
> 
> 
> Any idea ?
> I do use Toolchain: Swift Development Snapshot 2017-12-17 (a)

Building a CLI tool will use the objective-c Foundation in the system so that wont use your freshly built swift-corelibs-foundation. So that means we have a bug in the objc side if this is actually happening on Darwin (which is a completely different issue…) That should be a radar against Foundation and I definitely think that may very well be a bug… 

> 
> 
> Benoit
> 
> 
> 
> Benoit Pereira da Silva
> Ultra Mobile Developer & Movement Activist
> Développeur Ultra Mobile & Militant du mouvement
> https://pereira-da-silva.com <https://pereira-da-silva.com/>
> 
> <bannerp.jpg>
> 
> 
> 
> ✄ --------------------------------
> This e-mail is confidential. Distribution, copy, publication or use of this information for any purpose is prohibited without agreement of the sender.
> Ce message est confidentiel. Toute distribution, copie, publication ou usage des informations contenues dans ce message sont interdits sans agrément préalable de l'expéditeur.
> 
> 
> 
> _______________________________________________
> swift-corelibs-dev mailing list
> swift-corelibs-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20171218/902b272a/attachment.html>


More information about the swift-corelibs-dev mailing list