# Contribution help - Unit testing indexStoreDB

**URL:** <https://forums.swift.org/t/contribution-help-unit-testing-indexstoredb/26264>\
**Category:** SourceKit-LSP\
**Tags:** sourcekit-lsp, contributing\
**Created:** [June 25, 2019, 1:15am UTC](https://forums.swift.org/t/contribution-help-unit-testing-indexstoredb/26264 "2019-06-25T01:15:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![literalpie](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/literalpie/32/8290_2.png) [@literalpie](https://forums.swift.org/u/literalpie)\
**Post date:** [June 25, 2019, 1:15am UTC](https://forums.swift.org/t/contribution-help-unit-testing-indexstoredb/26264/1 "2019-06-25T01:15:10Z")

</div>

I might be interested in tackling [this](https://bugs.swift.org/browse/SR-10806?jql=labels%20%3D%20StarterBug%20AND%20text%20~%20%22sourcekit-lsp%22) starterBug. If the first step is exposing the functionality from indexstore-db, I could use some guidance on how to test the functionality. There are only a few unit tests and they do not create a DB or an indexStoreLibrary. Is there an easy way to do this

Whether its with a unit test or not, I am mostly just looking for a way to easily see the result of a function in `IndexStoreDB`.

---

<div class="post-metadata">

**Author:** ![blangmuir](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/blangmuir/32/277_2.png) [@blangmuir](https://forums.swift.org/u/blangmuir)\
**Post date:** [June 25, 2019, 5:53pm UTC](https://forums.swift.org/t/contribution-help-unit-testing-indexstoredb/26264/2 "2019-06-25T17:53:35Z")

</div>

There is no infrastructure to test the DB right now. This is something I'm keenly aware of and want to improve soon, but it's probably beyond the scope of a starter bug. I'm okay with exposing these existing functions without adding tests.

> Whether its with a unit test or not, I am mostly just looking for a way to easily see the result of a function in `IndexStoreDB` .

For now the easiest way may be to log them from inside sourcekit-lsp.

---

<div class="post-metadata">

**Author:** ![literalpie](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/literalpie/32/8290_2.png) [@literalpie](https://forums.swift.org/u/literalpie)\
**Post date:** [June 26, 2019, 11:45am UTC](https://forums.swift.org/t/contribution-help-unit-testing-indexstoredb/26264/3 "2019-06-26T11:45:20Z")

</div>

Okay, thank you for your response!

Based on that, I started working on the lsp project first. I created a symbolsRequest TextDocumentRequest struct and added the necessary plumbing so that the following code works in a test:

```swift
let resp = try! sk.sendSync(SymbolsRequest(
            textDocument: TextDocumentIdentifier(url),
            position: Position(line: 0, utf16index: 0)))

```

However, I'm still not sure how I would test the result of something that uses indexDB. None of the unit tests seem to use index even in the lsp project, and when running the project for real, I don't know how to see the logs.

In VSCode, I'm seeing logs such as

> [Trace - 7:41:51 AM] Received notification 'textDocument/publishDiagnostics'.

But I suspect that that's coming from the VSCode extension (Typescript) rather than the Swift server.

---

<div class="post-metadata">

**Author:** ![literalpie](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/literalpie/32/8290_2.png) [@literalpie](https://forums.swift.org/u/literalpie)\
**Post date:** [June 26, 2019, 11:59am UTC](https://forums.swift.org/t/contribution-help-unit-testing-indexstoredb/26264/4 "2019-06-26T11:59:28Z")

</div>

Also, if it seems like I am on the wrong track and the issue would be best left for someone else, please let me know! I don't want to waste your time if I'm unlikely to be successful

---

<div class="post-metadata">

**Author:** ![blangmuir](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/blangmuir/32/277_2.png) [@blangmuir](https://forums.swift.org/u/blangmuir)\
**Post date:** [June 26, 2019, 3:47pm UTC](https://forums.swift.org/t/contribution-help-unit-testing-indexstoredb/26264/5 "2019-06-26T15:47:19Z")

</div>

> [@literalpie](#):
>
> However, I'm still not sure how I would test the result of something that uses indexDB. None of the unit tests seem to use index even in the lsp project

This is the same problem as it is for indexstore-db. Definitely something I want to fix soon.

> I don't know how to see the logs.

You can run VSCode with the env var SOURCEKIT\_LOGGING set to a log level. See `LogLevel` for the values, but you probably want "info".

```swift
SOURCEKIT_LOGGING=info code /path/to/project

```

Then open the console in VSCode, and choose Output of "SourceKit Language Server". I think it only shows up after the first log message is printed.

---

<div class="post-metadata">

**Author:** ![literalpie](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/literalpie/32/8290_2.png) [@literalpie](https://forums.swift.org/u/literalpie)\
**Post date:** [June 27, 2019, 1:48am UTC](https://forums.swift.org/t/contribution-help-unit-testing-indexstoredb/26264/6 "2019-06-27T01:48:10Z")

</div>

Yes, that is exactly what I needed! Thank you so much!

It seems like the environment variable is different than the logging setting that you can set in VSCode settings even though the logs end up in the same place. Not what I expected, but I'll take it!

It's also seems to only work with `log` and not `print`.

---

<div class="post-metadata">

**Author:** ![blangmuir](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/blangmuir/32/277_2.png) [@blangmuir](https://forums.swift.org/u/blangmuir)\
**Post date:** [June 27, 2019, 3:52am UTC](https://forums.swift.org/t/contribution-help-unit-testing-indexstoredb/26264/7 "2019-06-27T03:52:59Z")

</div>

The setting is mostly about tracing the requests and/or responses, not about informational logging from inside the service. I'd like to do some more work on how we categorize logs to be more useful, and then we could expose it in a more useful way from the settings.

The way that we communicate with the editor is to send jsonrpc packets over stdout/stdin. Printing to _stdout_ will interfere with that, so don't do that 😉 If you print to _stderr_ the editor may or may not capture that - in vscode I think it would work.
