ferrous-systems / rust-training

Learning materials for the Rust Training courses by Ferrous Systems
127 stars 16 forks source link

make mdbook test pass by not opening local files or running shell scripts on windows #145

Closed miguelraz closed 3 months ago

miguelraz commented 3 months ago

Running mdbook test without these changes fails and is very noisy. We should just toggle the ignore feature in those blocks.

jonathanpallant commented 3 months ago

Ah. I forgot about Windows users.

It's a bit sad we have to ignore the tests in the Linux CI. Perhaps there are commands we could use that work for both kinds of OS?

miguelraz commented 3 months ago

I couldn't find an easy shared command (with shared flags!) between Powershell and Unix. Confusingly, Powershell does run ls, but won't spawn a command named ls.

Alternatively, we can branch on the OS and write a

Command::new("Get-Child") // this is an `ls- la` in Windows
    .args(&["-Force"])
    .spawn()
    .expect("Get-Child command failed to start");

but it adds a bit more noise to the example that I think is warranted.

jonathanpallant commented 3 months ago

How about if we leave the code as-is, but rename the function from main to example. Then the code will compile (and it should compile fine on windows too), but running the test won't actually execute the code. But if we want to run the example in the playground, we click "RUN" and rename the function from example to main.

This will also stop a test run from creating files like lunch.txt.

miguelraz commented 3 months ago

That's solid. Will change it in a bit.