-
Notifications
You must be signed in to change notification settings - Fork 16
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
test: add test for toolchain path setup #96
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a015b5c
test: add test for toolchain path setup
ttytm 5723f37
test custom path setup
ttytm 8e9bc5f
fmt
ttytm 46c023f
include redirected log prints
ttytm 40d4237
use toml string literals to not run into deserialization issues on wi…
ttytm 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module server | ||
|
||
import os | ||
import lsp | ||
import loglib as _ // import to use __global `logger` | ||
|
||
const default_vexe = @VEXE | ||
const default_vroot = os.dir(default_vexe) | ||
const default_vlib_root = os.join_path(default_vroot, 'vlib') | ||
const default_vmodules_root = os.vmodules_dir() | ||
|
||
fn test_setup_default_vpaths() { | ||
mut ls := LanguageServer{} | ||
ls.setup() | ||
assert ls.paths.vexe == server.default_vexe | ||
assert ls.paths.vroot == server.default_vroot | ||
assert ls.paths.vlib_root == server.default_vlib_root | ||
assert ls.paths.vmodules_root == server.default_vmodules_root | ||
} | ||
|
||
fn test_setup_custom_vpaths() { | ||
custom_root := os.join_path(os.vtmp_dir(), 'v-analyzer-setup-test') | ||
custom_root_uri := lsp.document_uri_from_path(custom_root) | ||
cfg_dir_path := os.join_path(custom_root, '.v-analyzer') | ||
cfg_path := os.join_path(cfg_dir_path, 'config.toml') | ||
os.mkdir_all(cfg_dir_path)! | ||
defer { | ||
os.rmdir_all(cfg_dir_path) or {} | ||
} | ||
|
||
// Test custom_vroot with missing toolchain ================================== | ||
// Use single quotes for literal strings so that paths keep working on Windows. | ||
mut cfg_toml := "custom_vroot = '${custom_root}'" | ||
os.write_file(cfg_path, cfg_toml)! | ||
|
||
// Set output(io.Writer) for global loglib logger. | ||
log_file_path := os.join_path(custom_root, 'log') | ||
os.write_file(log_file_path, '')! | ||
mut log_file := os.open_append(os.join_path(custom_root, 'log'))! | ||
logger.out = log_file | ||
|
||
// Run setup | ||
mut ls := LanguageServer{} | ||
ls.root_uri = custom_root_uri | ||
ls.setup() | ||
|
||
log_file.close() | ||
mut log_out := os.read_file(log_file_path)! | ||
println('Testlog custom_vroot missing toolchain:') | ||
println(log_out.trim_space()) | ||
assert log_out.contains('Find custom VROOT path') | ||
assert log_out.contains('Using "${custom_root}" as toolchain') | ||
assert log_out.contains('Failed to find standard library path') | ||
|
||
// Test custom_vroot with existing toolchain ================================= | ||
cfg_toml = "custom_vroot = '${server.default_vroot}'" | ||
os.write_file(cfg_path, cfg_toml)! | ||
os.write_file(log_file_path, '')! | ||
log_file = os.open_append(os.join_path(custom_root, 'log'))! | ||
logger.out = log_file | ||
|
||
ls = LanguageServer{} | ||
ls.root_uri = custom_root_uri | ||
ls.setup() | ||
|
||
log_file.close() | ||
log_out = os.read_file(log_file_path)! | ||
println('Testlog custom_vroot existing toolchain:') | ||
println(log_out.trim_space()) | ||
assert log_out.contains('Find custom VROOT path') | ||
assert log_out.contains('Using "${server.default_vroot}" as toolchain') | ||
assert !log_out.contains('Failed to find standard library path') | ||
} |
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.
imho that is a good idea in general (for logging), not just in tests.
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.
I agree