Jim Lynch Codes
  • Blog
  • About Jim

Writings about one coder's stories & experiences.

Run Cargo In Watch Mode With Cargo-Watch!

5/8/2020

0 Comments

 
Some people despise developing with unit tests, but I prefer to use them and leverage them to the allow me to quickly push new code and be more confident that it works! I love doing TDD (test-driven development) which inherently involves continuously re-running the tests, and regardless of what language you are coding in, being able to run your tests in "watch mode" makes TDD faster and easier than without it!

TDD For Rust Development

Cargo is basically THE command-line tool for day-to-day Rust development. It takes care of being the package manager for Rust libraries, compiling the Rust code down to binary, and running the tests. The default command to run tests with cargo is just "test". 
cargo test

I was actually rather confused that a simple -w or --watch on the end just gave me errors that they were unrecognized flags. Shoutout to my friends on Reddit for responding to me question on this, and it turns out in Cargo land there is a completely different tool, cargo-watch. 

But it's rather easy to install:
cargo install cargo-watch

Yay! Now you should be able to use it! This library actually integrates into cargo, and our first command is still cargo, but then we call watch, followed by the "-x" and the command we want it to rerun, which in this case is just test. 

Phew, so when we put it all together it looks like this:
cargo watch -x test

Interestingly, it seems that it also works when I use cargo-watch directly:
cargo-watch -x test

If you are curious about this mystery like me, feel free to check out and comment on this Github issue about this very thing.

Try It Out On Exercism

Downloading, solving, and submitting the exercises on Exercism.io is a great way to get started with a simple Rust project that already has unit tests setup for you. You can even set up the Exercism projects in your own Github repo as described in this blog post here. 

Happy Coding!

If you have any questions or just want to say hi feel free to hit me up on Twitter @JimLynchCodes, YouTube @JimLynchCodes, or in the comments below! 
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    ​Author

    Picture
    The posts on this site are written and maintained by Jim Lynch. About Jim...
    Picture
    Follow @JimLynchCodes
    Follow @JimLynchCodes

    Categories

    All
    Actionscript 3
    Angular
    AngularJS
    Automated Testing
    AWS Lambda
    Behavior Driven Development
    Blockchain
    Blogging
    Business Building
    C#
    C / C++
    ClojureScript / Clojure
    Coding
    Community Service
    CS Philosophy
    Css / Scss
    Dev Ops
    Firebase
    Fitness
    Flash
    Front End
    Functional Programming
    Git
    Go Lang
    Haskell
    Illustrations
    Investing
    Java
    Javascript
    Lean
    Life
    Linux
    Logic Pro
    Music
    Node.js
    Planning
    Productivity
    Professionalism
    Python
    React
    Redux / Ngrx
    Refactoring
    Reusable Components
    Rust
    Security
    Serverless
    Shell Scripting
    Swift
    Test Driven Development
    Things
    TypeScript
    Useful Sites
    Useful Tools
    Video
    Website Development
    WebStorm
    Writing

    Archives

    March 2023
    August 2021
    February 2021
    January 2021
    October 2020
    September 2020
    May 2020
    April 2020
    February 2020
    January 2020
    December 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015

    RSS Feed

  • Blog
  • About Jim
JimLynchCodes © 2023