Unit test run failed caused by Chinese in assertion

The problem is about Github action:
I have a project(using .net core), But the unit test run failed(because assertion includes Chinese, It works well on my personal computer),any solution?

Here is my failed action: https://github.com/zhaobingwang/Sophon.Toolkit/runs/1319861012?check_suite_focus=true

The failed function is : ToChineseDateString(),ToChineseDateTimeString(),ToFriendlyDateString(),

@lannus,

I forked your repository an can reproduce the same problem.
I also tried to change the system locale to zh_CN, but it did not work.

    - name: Test
      run: |
        sudo apt-get update && sudo apt-get install tzdata locales -y && sudo locale-gen zh_CN.UTF-8
        sudo localectl set-locale LANG="zh_CN.UTF-8"
        export LANG="zh_CN.UTF-8"
        sudo update-locale

        dotnet test Sophon.Toolkit.sln --no-restore --verbosity normal

I have created an issue ticket (actions/virtual-environments#1952) to report the problem to the appropriate engineering team for further investigation and evaluation.

You can follow this issue ticket and add your comments to it.

Hello, @lannus
Could you please provide output from your local computer?

  1. locale (bash)
  2. localectl (bash)
  3. lsb_release -a
  4. [System.Globalization.CultureInfo]::GetCultures(“SpecificCultures”).Name -match “zh” (powershell)

Hi @al-cheb
My local machine is windows. I ran the unit test on Visual Studio 2019(Live Unit Testing) and the result was as expected. Here is the output,

@lannus, I found out that the file .\test\Sophon.Toolkit.Tests\Extensions\System\DateTimeExtensionsTest.cs saved in the gb2312 encoding instead of UTF8, after converting the file to UTF8 all tests start working. Please convert to UTF8 and reupload the file.

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        repository: zhaobingwang/Sophon.Toolkit
        ref: release/sophon.toolkit
    - name: Convert to UTF8
      shell: pwsh
      run: |
        $file =  Resolve-Path .\test\Sophon.Toolkit.Tests\Extensions\System\DateTimeExtensionsTest.cs
        [IO.File]::ReadAllLines($file, [Text.Encoding]::GetEncoding(936)) | Out-File $file -Encoding utf8
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.101
    - name: Install dependencies
      run: dotnet restore Sophon.Toolkit.sln
    - name: Build
      run: dotnet build Sophon.Toolkit.sln --configuration Release --no-restore
    - name: Test
      run: dotnet test Sophon.Toolkit.sln --no-restore --verbosity normal

image

1 Like

@al-cheb
I solved the problem in your way, Cool, thanks!