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

Port utils::convert_text() and UTF-8 <-> locale converters to Rust #1455

Merged
merged 12 commits into from Feb 1, 2021

Conversation

Minoru
Copy link
Member

@Minoru Minoru commented Jan 28, 2021

This is another stepping stone to #1344.

I had to add my own bindings for iconv() because my PR to the libc crate is stuck due to linking issues of macOS. In Newsboat, I have more control over the build process than I have in the libc crate, so I managed to overcome those issues here; but we should switch to libc bindings once that PR is merged.

There are also some trouble with tests. #1443 added tests that require some locales to be present. Users and distro's build machines probably don't have those, so I put in checks to skip those tests. I couldn't transfer this trick to Rust directly, so Rust uses a slightly different scheme. More on that in the commit message to 7ec21f9

A commit message is not a good place for docs, so I also brushed up the hacker's guide a bit: marked most sections as outdated, but updated the one on tests. I don't yet have a plan on how to fully restore the hacker's guide, and what I actually want out of that document, but it's a start.

Reviews are welcome! Don't be afraid of large number of changes — it's the usual "rewrite in C++, port tests" stuff, nothing hardcore. I'll merge this in three days if no issues are raised.

I don't see a way to make the testing any more thorough, as we're
basically testing the platform's support for transliteration — there is
nothing our tests can do to enable or disable that support.
They all pass, even with a dummy implementation that just returns
`tocode`. I'll ameliorate that in the next commit.
This test currently fails, because Rust has a dummy implementation.
As a reminder: we can't rely on conventional tests here because
translit() is platform-independent, and there's no fixed known-good
output for any given input. But we can compare two implementations to
see if they behave the same — which is exactly what the test is doing.
The "comparison test" which compares results of C++ and Rust
implementations now pass, and will be removed in the next commit.

This commit passed the CI, i.e. it works not just on my Linux machine,
but also on Ubuntu Linux with various compilers, two macOS versions, and
two FreeBSD versions.
The inner call to iconv_open() creates a separate iconv_t value which is
never deallocated. The impact of this is minuscule, since Newsboat runs
through this code path at most once, but it's still nice to plug this
little leak.
@coveralls
Copy link

coveralls commented Jan 28, 2021

Coverage Status

Coverage increased (+0.3%) to 58.808% when pulling 4555cc2 on feature/rust-convert_text into 3a422e3 on master.

Copy link
Contributor

@der-lyse der-lyse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

doc/internal/hackers-guide.asciidoc Show resolved Hide resolved
doc/internal/hackers-guide.asciidoc Outdated Show resolved Hide resolved
Unlike C++ tests, Rust tests don't show output if they pass. As
a result, the user won't see warnings about the tests that are skipped
due to missing locales. The next commit will fix that.
As mentioned in the previous commit, Rust doesn't display stdout of
tests which passed. As a result, we can't print a warning if we
conditionally skip a test.

An interested user can run `cargo test -- --show-output` and see if
there are any warnings. But this is even worse than our C++ approach: in
C++ it's sufficient to *look* at the output, but with Rust we'd have to
*explicitly ask* for that output.

So this commit moves the decision up, to the *invocation of Make*: `make
check` (and `make ci-check`) runs all the tests *except* the ones that
need locales, while `make NEWSBOAT_RUN_IGNORED_TESTS=1 check` runs
*everything* (ditto for `ci-check`). This way, users and package
builders can continue to run `make check` even if they don't have all
the locales, and our CI can run a more strict version that checks
everything.
It's not a user-facing documentation.
Most of it is (rightfully) marked as outdated, but the section on tests
explains the purpose of `NEWSBOAT_RUN_IGNORED_TESTS` variable that
I introduced a few commits ago.
@Minoru Minoru merged commit 470620c into master Feb 1, 2021
@Minoru Minoru deleted the feature/rust-convert_text branch February 1, 2021 22:41
@Minoru Minoru added this to the 2.23 milestone Mar 21, 2021
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

Successfully merging this pull request may close these issues.

None yet

3 participants