Skip to content
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

try_verify_against_date_command_format fail when LANG is set to other locale #1060

Closed
scarf005 opened this issue May 12, 2023 · 10 comments
Closed

Comments

@scarf005
Copy link
Contributor

scarf005 commented May 12, 2023

Summary

GNU date uses environment variable LANG to localize its input, however try_verify_against_date_command_format does not explicitly set LANG, which makes the test fail when date is set to another locale.

Reproduction

(asked in #1060 (comment))

with `LANG=ko_KR.UTF-8`
 ~/r/chrono   locale …  bash                                                                                                                                                                                     2023년 05월 28일 (일) 오후 01시 05분 44초scarf@TG02:~/repo/chrono$ export LANG=ko_KR.UTF-8
scarf@TG02:~/repo/chrono$ date
2023. 05. 28. (일) 13:05:49 KST
scarf@TG02:~/repo/chrono$ cargo test --package chrono --test dateutils --features unstable-locales -- try_verify_against_date_command_format --exact --nocapture 
   Compiling chrono v0.4.24 (/home/scarf/repo/chrono)
    Finished test [unoptimized + debuginfo] target(s) in 1.01s
     Running tests/dateutils.rs (target/debug/deps/dateutils-917f84c226dfcdb1)

running 1 test
thread 'try_verify_against_date_command_format' panicked at 'assertion failed: `(left == right)`
  left: `"d01 D01/01/70 F1970-01-01 H12 I12 j001 k12 l12 m01 M11 S13 T12:11:13 u4 U00 w4 W00 X12시 11분 13초 y70 Y1970 z+09:00\n"`,
 right: `"d01 D01/01/70 F1970-01-01 H12 I12 j001 k12 l12 m01 M11 S13 T12:11:13 u4 U00 w4 W00 X12:11:13 y70 Y1970 z+09:00\n"`', tests/dateutils.rs:121:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test try_verify_against_date_command_format ... FAILED

failures:

failures:
    try_verify_against_date_command_format

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s

error: test failed, to rerun pass `-p chrono --test dateutils`
scarf@TG02:~/repo/chrono$ 
with `LANG=c`

scarf@TG02:/repo/chrono$ export LANG=c
scarf@TG02:
/repo/chrono$ date
Sun May 28 13:06:42 KST 2023
scarf@TG02:~/repo/chrono$ cargo test --package chrono --test dateutils --features unstable-locales -- try_verify_against_date_command_format --exact --nocapture
Finished test [unoptimized + debuginfo] target(s) in 0.03s
Running tests/dateutils.rs (target/debug/deps/dateutils-917f84c226dfcdb1)

running 1 test
test try_verify_against_date_command_format ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.14s

scarf@TG02:~/repo/chrono$

Details

> echo $LANG
ko_KR.UTF-8
Error log
 *  Executing task: cargo test --package chrono --test dateutils --features unstable-locales -- try_verify_against_date_command_format --exact --nocapture 

    Finished test [unoptimized + debuginfo] target(s) in 0.03s
     Running tests/dateutils.rs (target/debug/deps/dateutils-917f84c226dfcdb1)

running 1 test
thread 'try_verify_against_date_command_format' panicked at 'assertion failed: `(left == right)`
  left: `"d01 D01/01/70 F1970-01-01 H12 I12 j001 k12 l12 m01 M11 S13 T12:11:13 u4 U00 w4 W00 X12시 11분 13초 y70 Y1970 z+09:00\n"`,
 right: `"d01 D01/01/70 F1970-01-01 H12 I12 j001 k12 l12 m01 M11 S13 T12:11:13 u4 U00 w4 W00 X12:11:13 y70 Y1970 z+09:00\n"`', tests/dateutils.rs:121:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5
   1: core::panicking::panic_fmt
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:211:5
   4: dateutils::verify_against_date_command_format_local
             at ./tests/dateutils.rs:121:5
   5: dateutils::try_verify_against_date_command_format
             at ./tests/dateutils.rs:135:9
   6: dateutils::try_verify_against_date_command_format::{{closure}}
             at ./tests/dateutils.rs:126:45
   7: core::ops::function::FnOnce::call_once
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/ops/function.rs:250:5
   8: core::ops::function::FnOnce::call_once
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
test try_verify_against_date_command_format ... FAILED

failures:

failures:
    try_verify_against_date_command_format

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.01s

error: test failed, to rerun pass `-p chrono --test dateutils`

 *  The terminal process "cargo 'test', '--package', 'chrono', '--test', 'dateutils', '--features', 'unstable-locales', '--', 'try_verify_against_date_command_format', '--exact', '--nocapture'" failed to launch (exit code: 101). 
 *  Terminal will be reused by tasks, press any key to close it. 
@djc
Copy link
Contributor

djc commented May 26, 2023

Does #1058 fix this?

@scarf005
Copy link
Contributor Author

scarf005 commented May 26, 2023

i found it when testing #1058 locally. in my guess the error happens because the date binary uses LANG env, which this test does not set explicitly.

@jtmoon79
Copy link
Contributor

@scarf005 can you post or link to the testing source code?

@scarf005
Copy link
Contributor Author

@jtmoon79
Copy link
Contributor

@jtmoon79 could you clarify? if you meant which test is failing: https://github.com/chronotope/chrono/blob/9dfa7b0028123ec3c728487443e8431adb4dc1e7/tests/dateutils.rs#L124-L139

Ah okay, I misunderstood that this was your own extra test you added. Thanks for the link.

@jtmoon79
Copy link
Contributor

@scarf005 what happens if you run these three commands. (I'm pretty sure the same crash. I want to verify my understanding of when LANG is set and is not set).

# export LANG=ko_KR.UTF-8
# date
# cargo test --package chrono --test dateutils --features unstable-locales -- try_verify_against_date_command_format --exact --nocapture 

Would you please copy+paste the console output?

@scarf005
Copy link
Contributor Author

scarf005 commented May 28, 2023

@jtmoon79 sure. I've also updated issue body to be more descriptive.

with `LANG=ko_KR.UTF-8`
 ~/r/chrono   locale …  bash                                                                                                                                                                                     2023년 05월 28일 (일) 오후 01시 05분 44초scarf@TG02:~/repo/chrono$ export LANG=ko_KR.UTF-8
scarf@TG02:~/repo/chrono$ date
2023. 05. 28. (일) 13:05:49 KST
scarf@TG02:~/repo/chrono$ cargo test --package chrono --test dateutils --features unstable-locales -- try_verify_against_date_command_format --exact --nocapture 
   Compiling chrono v0.4.24 (/home/scarf/repo/chrono)
    Finished test [unoptimized + debuginfo] target(s) in 1.01s
     Running tests/dateutils.rs (target/debug/deps/dateutils-917f84c226dfcdb1)

running 1 test
thread 'try_verify_against_date_command_format' panicked at 'assertion failed: `(left == right)`
  left: `"d01 D01/01/70 F1970-01-01 H12 I12 j001 k12 l12 m01 M11 S13 T12:11:13 u4 U00 w4 W00 X12시 11분 13초 y70 Y1970 z+09:00\n"`,
 right: `"d01 D01/01/70 F1970-01-01 H12 I12 j001 k12 l12 m01 M11 S13 T12:11:13 u4 U00 w4 W00 X12:11:13 y70 Y1970 z+09:00\n"`', tests/dateutils.rs:121:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test try_verify_against_date_command_format ... FAILED

failures:

failures:
    try_verify_against_date_command_format

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s

error: test failed, to rerun pass `-p chrono --test dateutils`
scarf@TG02:~/repo/chrono$ 
with `LANG=c`

scarf@TG02:/repo/chrono$ export LANG=c
scarf@TG02:
/repo/chrono$ date
Sun May 28 13:06:42 KST 2023
scarf@TG02:~/repo/chrono$ cargo test --package chrono --test dateutils --features unstable-locales -- try_verify_against_date_command_format --exact --nocapture
Finished test [unoptimized + debuginfo] target(s) in 0.03s
Running tests/dateutils.rs (target/debug/deps/dateutils-917f84c226dfcdb1)

running 1 test
test try_verify_against_date_command_format ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.14s

scarf@TG02:~/repo/chrono$

while it could be solved by setting its env explicitly, but would it suffice to set its env explicitly to c?

@jtmoon79
Copy link
Contributor

while it could be solved by setting its env explicitly, but would it suffice to set its env explicitly to c?

This is a good fix.



Here is an off-hand idea for anyone to pick-up (not required for this Issue):
It would be good to also run the try_verify_against_date_command_format test with LANG intentionally set to other values, such as ko_KR.UTF-8.

  • For the github Actions tests, the locales would need to be installed and somehow a setting signals to the test case that these other LANG tests should be run.
  • For developers, these additional tests could simply be skipped. Or maybe some other check is done for what locales are available and so can be tested.

@jtmoon79
Copy link
Contributor

jtmoon79 commented May 28, 2023

Fails for me too using LANG=en_US.UTF-8. Using 656c941

$ echo $LANG
en_US.UTF-8

$ /usr/bin/date --version
date (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.

$ /usr/bin/date
Sat May 27 09:42:48 PM PDT 2023

$ cargo test try_verify_against_date_command_format -- --nocapture
    Finished test [unoptimized + debuginfo] target(s) in 0.07s
     Running unittests src/lib.rs (target/debug/deps/chrono-ab709be662cf80de)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 181 filtered out; finished in 0.00s

     Running tests/dateutils.rs (target/debug/deps/dateutils-94200521e6ba6b56)

running 1 test
thread 'try_verify_against_date_command_format' panicked at 'assertion failed: `(left == right)`
  left: `"d01 D01/01/70 F1970-01-01 H12 I12 j001 k12 l12 m01 M11 S13 T12:11:13 u4 U00 w4 W00 X12:11:13 PM y70 Y1970 z-08:00\n"`,
 right: `"d01 D01/01/70 F1970-01-01 H12 I12 j001 k12 l12 m01 M11 S13 T12:11:13 u4 U00 w4 W00 X12:11:13 y70 Y1970 z-08:00\n"`', tests/dateutils.rs:138:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test try_verify_against_date_command_format ... FAILED

failures:

failures:
    try_verify_against_date_command_format

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s

error: test failed, to rerun pass `--test dateutils`

@pitdicker
Copy link
Collaborator

Fixed in #1089.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants