swellaby / vscode-rust-test-adapter

Rust Test Explorer extension for VS Code
MIT License
56 stars 10 forks source link

toolchain-file in workspace not being picked up #87

Closed calebcartwright closed 4 years ago

calebcartwright commented 4 years ago

Originally posted by @JRAndreassen in https://github.com/swellaby/vscode-rust-test-adapter/issues/50#issuecomment-671556570

Hi, Thanks for getting back to me...

I have a project like:

+libs
 | -cargo.toml
 | + subprojA
 |     -  cargo.toml
 | + SubProjB
 |     -  cargo.toml
 |     -  toolchain

The libs\cargo.toml is a workspace:

[workspace]
members = [
     "subprojA"
    ,"subprojB"
]

exclude = [
    "subprojC",
]

subprojB has a "toolchain" file, which specifies that it should use the "nightly"

When the too issues the "cargo" command, it sets cwd to the parent "libs".. Which does not pick up the "toolchain" file in the sub directory...

When I call cargo from subprojB directory or when I delete the workspace cargo, it compiles correctly. So, my suspicion is that you would have to add the sub-project directory to the cwd before issuing the command.

Thanks JR

Originally posted by @JRAndreassen in https://github.com/swellaby/vscode-rust-test-adapter/issues/50#issuecomment-671556570

calebcartwright commented 4 years ago

@JRAndreassen

When the too issues the "cargo" command, it sets cwd to the parent "libs"..

Sorry, what is the (I presume) "tool" referring to here? In the case of your project, the extension will invoke the cargo metadata command from the libs workspace root to ensure all the explicit packages are detected. However, the cargo test ... commands will be invoked from libs/subprojA and then again from libs/subProjB for both test discovery and execution.

Which does not pick up the "toolchain" file in the sub directory...

Can you please provide more detail about the behavior/error/etc. you are experiencing?

calebcartwright commented 4 years ago

Also, is toolchain the literal name of the file you have in libs/subProjB directory? If so that's likely a problem, as the file is supposed to be named rust-toolchain.

https://github.com/rust-lang/rustup#the-toolchain-file

JRAndreassen commented 4 years ago

Sorry... New keyboard... So I "fat-finger" a lot...

It is called "rust-toolchain"

Here is the output from "Run Test", (I altered the "Microsoft.PowerShell_profile.ps1" for output

> Executing task: cargo test --package msgraph --lib -- sensor_msgraph::tests::get_calendars --exact --nocapture <
C:\Users\JR\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

    Directory: C:\Development\Rust\jra\libs

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        1/20/2020   9:38 PM                .vscode
d-----        7/27/2020   5:01 PM                moah_client
d-----        8/10/2020  12:35 PM                msgraph
d-----         8/9/2020   4:22 PM                target
d-----        4/28/2020   7:48 PM                TestMain
d-----         8/2/2020   1:58 PM                ToDos
-a----        7/26/2020   3:27 PM             73 .gitignore
-a----        8/10/2020  11:15 AM         117768 Cargo.lock
-a----         8/5/2020   9:22 AM            397 Cargo.toml

   Compiling graph-error v0.1.0 (C:\Development\Rust\rust_cargo_sources\graph-rs\graph-error)
error[E0554]: `#![feature]` may not be used on the stable release channel
 --> C:\Development\Rust\rust_cargo_sources\graph-rs\graph-error\src\lib.rs:1:1
  |
1 | #![feature(try_trait)]
  | ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0554`.
error: could not compile `graph-error`.

To learn more, run the command again with --verbose.
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command cargo test --package msgraph --lib -- sensor_msgraph::tests::get_calendars --exact --nocapture" terminated with exit code: 1.
    Directory: C:\Development\Rust\jra\libs\msgraph

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        8/10/2020  11:22 AM                logs
d-----         8/4/2020   1:09 PM                src
d-----        8/10/2020  12:39 PM                target
-a----        8/10/2020  12:35 PM         114979 Cargo.lock
-a----         8/9/2020   4:34 PM            863 Cargo.toml
-a----         8/8/2020   1:41 PM          43790 generated.rs
-a----         8/7/2020  12:51 PM              7 rust-toolchain
-a----         8/6/2020   1:34 PM           7780 Tidbits.txt

Content of "rust-toolchain": nightly

JRAndreassen commented 4 years ago

Here is what I get when I run the command in "libs":

PS C:\Development\Rust\jra\libs> cargo test --package msgraph --lib -- sensor_msgraph::tests::get_calendars --exact --nocapture 
   Compiling graph-error v0.1.0 (C:\Development\Rust\rust_cargo_sources\graph-rs\graph-error)                                                                                                                                                                        
error[E0554]: `#![feature]` may not be used on the stable release channel
 --> C:\Development\Rust\rust_cargo_sources\graph-rs\graph-error\src\lib.rs:1:1
  |
1 | #![feature(try_trait)]
  | ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0554`.
error: could not compile `graph-error`.

To learn more, run the command again with --verbose.

If I run it in the subdirectory:

PS C:\Development\Rust\jra\libs> cd .\msgraph\
PS C:\Development\Rust\jra\libs\msgraph> cargo test --package msgraph --lib -- sensor_msgraph::tests::get_calendars --exact --nocapture
   Compiling sabaki-rs v0.1.0 (C:\Development\Rust\jra\libs\sabaki-rs)
warning: value assigned to `next_link` is never read
  --> C:\Development\Rust\rust_cargo_sources\graph-rs\src\types\delta.rs:86:25
   |
86 |                         next_link = None;
   |                         ^^^^^^^^^
   |
   = note: `#[warn(unused_assignments)]` on by default
   = help: maybe it is overwritten before being read?

warning: 1 warning emitted

   Compiling msgraph v0.1.0 (C:\Development\Rust\jra\libs\msgraph)
[ snip warnings ...]
warning: 12 warnings emitted

    Finished test [unoptimized + debuginfo] target(s) in 11.22s
     Running C:\Development\Rust\jra\libs\target\debug\deps\msgraph-28b5e84dc960f7ab.exe

running 1 test
test sensor_msgraph::tests::get_calendars ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

PS C:\Development\Rust\jra\libs\msgraph> 
calebcartwright commented 4 years ago

Sorry, you are losing me here (I have no idea what Microsoft.PowerShell_profile.ps1 is :smile:) I get the sense you have a diagnosis for some issue you are seeing, but I don't really have much context and am trying to play catch up.

Within the context of the VS Code extension, can you please provide some basic info, like what you are doing (on project open, on workspace load, running a test suite, running a test case, etc.), and what, if any, output/error there is from VS Code in the Test Explorer pane?

JRAndreassen commented 4 years ago

No worries...

"Microsoft.PowerShell_profile.ps1" is the powershell script VSCode calls when it starts a new session / terminal. (like linux ".profile|.cshrc|...)

Synopsis: When the cargo.toml is a workspace... the cargo command "cargo test --package XXX --lib -- sensor_msgraph::tests::get_calendars --exact --nocapture" runs in the directory of the workspace. (In my case "libs") has to be executed in the package sub-directory(cwd = package subdirectory) where the "rust-toolchain" file is located or it is ignored. (In my case "libs\subprojB") I guess you could read the "rust-toolchain" file in the package sub-directory, but the cwd is probably easiest...


I have the projects:

+libs
 | -cargo.toml
 | + subprojA
 |     -  cargo.toml
 | + SubProjB
 |     -  cargo.toml
 |     -  rust-toolchain

there is a rust-toolchain file indicating that subprojB should use the "nightly" toolchain.

In vscode I open the folder "libs\SubprojB". [After a lengthy "cargo check" ] I get your handy:

    >Run Test | Debug
    #[test]
    fn get_calendars() {
    ...

If I hit "Run Test" I get:

   Compiling graph-error v0.1.0 (C:\Development\Rust\rust_cargo_sources\graph-rs\graph-error)
error[E0554]: `#![feature]` may not be used on the stable release channel
 --> C:\Development\Rust\rust_cargo_sources\graph-rs\graph-error\src\lib.rs:1:1
  |
1 | #![feature(try_trait)]
  | ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

For more information about this error, try `rustc --explain E0554`.
error: could not compile `graph-error`.

To learn more, run the command again with --verbose.
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command cargo test --package msgraph --lib -- sensor_msgraph::tests::get_calendars --exact --nocapture" terminated with exit code: 1.

error[E0554]: #![feature] may not be used on the stable release channel Indicating compiling with toolchain "stable" not "nightly"

If I hit "Debug" I get:

   Compiling graph-error v0.1.0 (C:\Development\Rust\rust_cargo_sources\graph-rs\graph-error)
error[E0554]: `#![feature]` may not be used on the stable release channel
 --> C:\Development\Rust\rust_cargo_sources\graph-rs\graph-error\src\lib.rs:1:1
  |
1 | #![feature(try_trait)]
  | ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0554`.
error: could not compile `graph-error`.

error[E0554]: #![feature] may not be used on the stable release channel Indicating compiling with toolchain "stable" not "nightly"

Clear as mud... I hope... :) Thanks JR

calebcartwright commented 4 years ago

In vscode I open the folder "libs\SubprojB". [After a lengthy "cargo check" ] I get your handy:

    >Run Test | Debug
    #[test]
    fn get_calendars() {
    ...

This extension, the Rust Test Explorer, does not add any CodeLens items :smile: . This extension only enables the Test Explorer pane:

image

Since you have those Run Test and Debug CodeLens items, that's going to either be coming from your usage of Rust Analyzer or usage of Rust Test Lens directly

JRAndreassen commented 4 years ago

Ach.. Soooo... Sorry about that... I'll re--post it there...

calebcartwright commented 4 years ago

No worries. Going to go ahead and close this, though if you do happen to test this extension and observe similar behavior then feel free to reach out :wink: