Skip to content

Improve code quality (smaller more tested functions)#343

Merged
tolik518 merged 14 commits into
tolik518:masterfrom
Aras14HD:improve-code-quality
Jun 10, 2026
Merged

Improve code quality (smaller more tested functions)#343
tolik518 merged 14 commits into
tolik518:masterfrom
Aras14HD:improve-code-quality

Conversation

@Aras14HD

@Aras14HD Aras14HD commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

This Pull has three major aspects:

  • More streamlined integration test definition (macro)
  • Smaller functions (split up very large functions or untestable into parts)
  • More tests (for reddit main and discord Handler)

For the splitting and testing I oriented myself loosely on cargo-crap. I found that in many cases the functions were truly so large, that they became hard to read (parse, calculate_appropriate_factorial) and some did improve in readability a bit (get_reply, format).

Splitting main allowed testing of more parts, which already proved beneficial: I found, that you could not set some commands through the SUBREDDITS env var, now the test is set up in a way, that it can't be missed.

Testing discord introduced a lot of #[cfg(test)] and #[cfg(not(test))]s (serenity is very intrusive and hard to test with), which does decrease readability, but means, that it will be actually significantly tested.

Sparating out any logic, that does not need to rely on serenity instead also removed these attribute macros (only the ones disabling saving/loading the config remain).

It is a very large refactor, so I would hold off on making significant PRs before this is merged or closed.

@tolik518 tolik518 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thats a huge change! Thank you! I skimmed through the changes and found only one issue right away: the Discord tests appear to go against the live discord server. That could make the tests flaky if the discord server is unavailable.

Also I commented a change that was already introduced earlier

Comment thread factorion-lib/src/comment.rs
Comment thread factorion-bot-discord/src/discord_api.rs Outdated
@Aras14HD Aras14HD force-pushed the improve-code-quality branch from 44a8cc1 to 769f6a5 Compare June 7, 2026 13:32
@Aras14HD Aras14HD force-pushed the improve-code-quality branch from 6bd8e6b to 1147093 Compare June 7, 2026 13:38
@tolik518

tolik518 commented Jun 7, 2026

Copy link
Copy Markdown
Owner

I'll review the changes some time next week, thank you :)

@tolik518

tolik518 commented Jun 9, 2026

Copy link
Copy Markdown
Owner

I haven't found any obvious issues with the changes, thanks :)

@tolik518 tolik518 merged commit 104aec3 into tolik518:master Jun 10, 2026
6 checks passed
@Aras14HD Aras14HD deleted the improve-code-quality branch June 11, 2026 17:15
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.

2 participants