-
Notifications
You must be signed in to change notification settings - Fork 97
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
Update test callable discovery to work within the language service #2095
Open
sezna
wants to merge
62
commits into
main
Choose a base branch
from
alex/track_test_changes_in_ls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
b79c31e
initial work on testing
sezna 1c09783
Merge branch 'main' of github.com:microsoft/qsharp into alex/testHarness
sezna 54eb209
progress on test explorer
sezna e6a0941
test collection works
sezna 0495a6d
tests run
sezna eae1b4d
add todos
sezna 759036f
switching to namespaces included with callable names
sezna cec4bf9
scoped test names
sezna ad7d3e2
deduplicate parent items
sezna d9f288d
make running child items work
sezna 9ec9f41
auto-refresh test cases
sezna a03ed14
wip -- checkpoint
sezna c11476a
wip
sezna b247c35
Remove codelens stuff
sezna e75f65b
update libraries to use new testing harness
sezna 131a341
remove bad imports
sezna b52ad25
document some functions
sezna 180368e
Add comment
sezna e960916
Remove todos
sezna 7d2aadc
Fix nested tests
sezna ac8bfd7
initial round of PR feedback
sezna c22d14d
move discovery of test items into compiler layer
sezna 5a28ef1
Use a pass to detect test attribute errors and report them nicely
sezna 16a2aed
use getActiveProgram
sezna 214097c
remove unnecessary api in main.ts
sezna adbc4b2
Fmt
sezna 5b6a1f8
fix lints
sezna 7cee532
update tests
sezna be64105
filter out invalid test items
sezna e34b7d2
Merge branch 'main' of github.com:microsoft/qsharp into alex/testHarness
sezna fa1ca42
wip: start to add locations to the return type for test callables
sezna 790c29b
get spans/ranges hooked up
sezna 9d0190c
abstract compiler worker generation into a common singleton worker
sezna 38e0f4b
wipz
sezna 43f4e17
use updateDocument events for test discovery
sezna bcd6d34
it works, but i'd rather not have the tests collapse on auto refresh
sezna 5421cb2
Fmt
sezna 804fb0b
rename Vscode to VsCode
sezna ffab724
rename collectTestCallables to getTestCallables
sezna cca48b5
switch to debug event target; remove unnecessary result
sezna eea9581
rename test explorer to test discovery
sezna 540de0b
fmt
sezna f171141
update tests for test attribute
sezna 8e3c9a4
wip
sezna f18dc39
wip: refactor: it works
sezna cf35b19
Remove comment
sezna 36abbd1
wip
sezna bf8b277
wip
sezna ff31000
individual test parity tracking works
sezna b72ca75
Rename from parity to version
sezna f52330d
pull test explorer out into its own file
sezna 865cce1
lint fixes
sezna 1f88c97
rust lint updates
sezna e0347c6
update expect test
sezna 468345b
update test case for new test callables
sezna 00d5f4f
basics.js test
sezna 57bc6c1
add basics.js tests
sezna d1267c4
undo common compiler worker
sezna 8255955
Merge branch 'main' of github.com:microsoft/qsharp into alex/testHarness
sezna 007a76d
Merge branch 'alex/testHarness' of github.com:microsoft/qsharp into a…
sezna 1d5ef8e
Fix output
sezna 6ca81d0
mid PR review feedback
sezna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
use miette::Diagnostic; | ||
use qsc_data_structures::span::Span; | ||
use qsc_hir::{hir::Attr, visit::Visitor}; | ||
use thiserror::Error; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
#[derive(Clone, Debug, Diagnostic, Error)] | ||
pub enum TestAttributeError { | ||
#[error("test callables cannot take arguments")] | ||
CallableHasParameters(#[label] Span), | ||
#[error("test callables cannot have type parameters")] | ||
CallableHasTypeParameters(#[label] Span), | ||
} | ||
|
||
pub(crate) fn validate_test_attributes( | ||
package: &mut qsc_hir::hir::Package, | ||
) -> Vec<TestAttributeError> { | ||
let mut validator = TestAttributeValidator { errors: Vec::new() }; | ||
validator.visit_package(package); | ||
validator.errors | ||
} | ||
|
||
struct TestAttributeValidator { | ||
errors: Vec<TestAttributeError>, | ||
} | ||
|
||
impl<'a> Visitor<'a> for TestAttributeValidator { | ||
fn visit_callable_decl(&mut self, decl: &'a qsc_hir::hir::CallableDecl) { | ||
if decl.attrs.iter().any(|attr| matches!(attr, Attr::Test)) { | ||
if !decl.generics.is_empty() { | ||
self.errors | ||
.push(TestAttributeError::CallableHasTypeParameters( | ||
decl.name.span, | ||
)); | ||
} | ||
if decl.input.ty != qsc_hir::ty::Ty::UNIT { | ||
self.errors | ||
.push(TestAttributeError::CallableHasParameters(decl.name.span)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
use expect_test::{expect, Expect}; | ||
use indoc::indoc; | ||
use qsc_data_structures::{language_features::LanguageFeatures, target::TargetCapabilityFlags}; | ||
use qsc_frontend::compile::{self, compile, PackageStore, SourceMap}; | ||
use qsc_hir::{validate::Validator, visit::Visitor}; | ||
|
||
use crate::test_attribute::validate_test_attributes; | ||
|
||
fn check(file: &str, expect: &Expect) { | ||
let store = PackageStore::new(compile::core()); | ||
let sources = SourceMap::new([("test".into(), file.into())], None); | ||
let mut unit = compile( | ||
&store, | ||
&[], | ||
sources, | ||
TargetCapabilityFlags::all(), | ||
LanguageFeatures::default(), | ||
); | ||
assert!(unit.errors.is_empty(), "{:?}", unit.errors); | ||
|
||
let errors = validate_test_attributes(&mut unit.package); | ||
Validator::default().visit_package(&unit.package); | ||
if errors.is_empty() { | ||
expect.assert_eq(&unit.package.to_string()); | ||
} else { | ||
expect.assert_debug_eq(&errors); | ||
} | ||
} | ||
|
||
#[test] | ||
fn callable_cant_have_params() { | ||
check( | ||
indoc! {" | ||
namespace test { | ||
@Test() | ||
operation A(q : Qubit) : Unit { | ||
|
||
} | ||
} | ||
"}, | ||
&expect![[r#" | ||
[ | ||
CallableHasParameters( | ||
Span { | ||
lo: 43, | ||
hi: 44, | ||
}, | ||
), | ||
] | ||
"#]], | ||
); | ||
} | ||
|
||
#[test] | ||
fn callable_cant_have_type_params() { | ||
check( | ||
indoc! {" | ||
namespace test { | ||
@Test() | ||
operation A<'T>() : Unit { | ||
|
||
} | ||
} | ||
"}, | ||
&expect![[r#" | ||
[ | ||
CallableHasTypeParameters( | ||
Span { | ||
lo: 43, | ||
hi: 44, | ||
}, | ||
), | ||
] | ||
"#]], | ||
); | ||
} | ||
|
||
#[test] | ||
fn callable_is_valid_test_callable() { | ||
check( | ||
indoc! {" | ||
namespace test { | ||
@Test() | ||
operation A() : Unit { | ||
|
||
} | ||
} | ||
"}, | ||
&expect![[r#" | ||
Package: | ||
Item 0 [0-64] (Public): | ||
Namespace (Ident 5 [10-14] "test"): Item 1 | ||
Item 1 [21-62] (Internal): | ||
Parent: 0 | ||
Test | ||
Callable 0 [33-62] (operation): | ||
name: Ident 1 [43-44] "A" | ||
input: Pat 2 [44-46] [Type Unit]: Unit | ||
output: Unit | ||
functors: empty set | ||
body: SpecDecl 3 [33-62]: Impl: | ||
Block 4 [54-62]: <empty> | ||
adj: <none> | ||
ctl: <none> | ||
ctl-adj: <none>"#]], | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of just the name, could you use the whole signature's span, so that the squiggles appear below the problematic code and not the name?
And now that I wrote that... I realize there may not be an easy way to get that span from the AST. I think I hit this issue before. Hmm...