Skip to content
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

Let kdb get -v display if value comes from default #2499

Merged

Conversation

e01306821
Copy link
Contributor

src/tools/kdb/get.cpp
I've added the check after the final key-lookup inside the execute-method. If the printTrace-method is the better place for this please let me know and I'll find a way to retrieve the information there.
Close #2474

Checklist

Check relevant points but please do not remove entries.
For docu fixes, spell checking, and similar none of these points below
need to be checked.

  • I added unit tests
  • I ran all tests locally and everything went fine
  • affected documentation is fixed
  • I added code comments, logging, and assertions (see doc/CODING.md)
  • meta data is updated (e.g. README.md of plugins)

Review

@markus2330 please review my pull request

@sanssecours sanssecours removed their request for review March 16, 2019 07:21
Copy link
Member

@sanssecours sanssecours left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think I am the right person to review this pull request, since I usually do not work on anything related to the spec namespace. Anyway, as far as I can tell, the code looks good. I think it would be a good idea to create a Markdown Shell Recorder test in kdb-get.md, to make sure the feature works as intended. For an example, on how to do that please take a look at:

```sh
# Backup-and-Restore: user/tests/complete/examples
# Create the keys we use for the examples
kdb set user/tests/complete/examples/kdb-complete/level1 foo
kdb set user/tests/complete/examples/kdb-complete/lvl1/lvl2 bar
kdb set user/tests/complete/examples/kdb-complete/lvl1/lvl2/lvl3/lvl4/lvl5 fizz
kdb set user/tests/complete/examples/kdb-complete/buzz fizzBuzz
kdb set user/tests/complete/examples/kdb-complete/#array_1 asdf
kdb set user/tests/complete/examples/kdb-complete/% nothing
# list suggestions for namespaces starting with us, only the current level
kdb complete us --max-depth=1
#> user/
# list suggestions for namespaces starting with user, only the current level
kdb complete user --max-depth=1
#> user/
# list suggestions for the namespace user, only the next level as it ends with /
# note the difference to the previous example, which uses no trailing /
kdb complete user/ --max-depth=1
# STDOUT-REGEX: .+
# list all possible namespaces or mount points, only the current level
kdb complete --max-depth=1
# STDOUT-REGEX: .+
# list suggestions for /tests/complete/examples/kdb-complete, only the current level
kdb complete /tests/complete/examples/kdb-complete --max-depth=1
#> user/tests/complete/examples/kdb-complete/
# list suggestions for /tests/complete/examples/kdb-complete/, only the next level
# again, note the difference to the previous example which has no trailing /
kdb complete /tests/complete/examples/kdb-complete/ --max-depth=1
#> user/tests/complete/examples/kdb-complete/%
#> user/tests/complete/examples/kdb-complete/#array_1
#> user/tests/complete/examples/kdb-complete/buzz
#> user/tests/complete/examples/kdb-complete/level1
#> user/tests/complete/examples/kdb-complete/lvl1/
# list suggestions for /tests/complete/examples/kdb-complete which are minimum 2 levels
# away from that key, and maximum 4 levels away
kdb complete /tests/complete/examples/kdb-complete/ --min-depth=2 --max-depth=4
#> user/tests/complete/examples/kdb-complete/lvl1/lvl2/lvl3/
#> user/tests/complete/examples/kdb-complete/lvl1/lvl2/lvl3/lvl4/
kdb rm -r user/tests/complete/examples/kdb-complete
```

and:

add_msr_test (kdb_complete "${CMAKE_SOURCE_DIR}/doc/help/kdb-complete.md")

.

@@ -173,6 +173,7 @@ you up to date with the multi-language support provided by Elektra.

## Tools

- `kdb get -v` now displays if the resulting value is a default-value defined by the metadata of the key. _(Thomas Bretterbauer)_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the trailing space character in this line. After you do that the test testscr_check_formatting should not fail anymore.

@e01306821
Copy link
Contributor Author

Thanks for your review! I'll address your findings

Fixes ElektraInitiative#2474
Added release notes


Using char-array directly


Added markdown-tests and removed space in release-notes
@e01306821
Copy link
Contributor Author

I've added shell recorder tests for /doc/help/kdb-get.md which resulted in reformatting the existing examples.
The formatting-check fails because "kdb get -v" prints a trailing space-character after options:-output

Example-output:
...
searching dir/tests/get/examples/kdb-get/key, found: , options:
...

Therefore this test fails without this character. Should I ignore this failure in this case?

@markus2330
Copy link
Contributor

I think we can safely remove the space from the output (or even options: if there are none).

@sanssecours is this a bug in the Markdown formatter? Imho it should not reformat any source code.

@sanssecours
Copy link
Member

Should I ignore this failure in this case?

I think it should work, if you

.

@markus2330
Copy link
Contributor

Alternatively, we could simply not output "options" if there are none.

@e01306821
Copy link
Contributor Author

Thanks for your help!

I've removed the options-output if there are no options to print.

@markus2330 please review my pull request

@sanssecours
Copy link
Member

sanssecours commented Mar 19, 2019

is this a bug in the Markdown formatter?

I do not think so.

Imho it should not reformat any source code.

In my opinion removing trailing whitespace should be a standard feature of every formatting tool 😊. The nice thing is that prettier even reformats fenced code blocks, for supported languages such as YAML and JavaScript.

please review my pull request

I do not know, if you noticed it yet, but the test testshell_markdown_kdb_get fails in the build job debian-stable-full-ini. The cause of is the INI plugin, which adds keys in between levels. I think there are multiple options to fix the failing test:

  1. exclude the test testshell_markdown_kdb_get, if INI is the default storage plugin,
  2. mount a plugin that “behaves properly”, or
  3. adapt the MSR test in another way

.

def ctest(target = "Test", testName = "Testname") {

/*
We disable the test `testshell_markdown_kdb_get` if the storage plugin INI is used, because it adds keys in between levels which
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the proper location to disable the test is the CMake code, otherwise the test will still fail, if someone uses INI as default storage plugin and runs the test suite locally. Sorry if that was not clear from the suggestions in my previous comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also happy with the solution in this PR (if it works). I think people should not get the impression that the INI plugin works flawlessly, as it does not. Afaik nobody (except us on the build server) currently runs the tests with INI as default storage. I think soon it will be even okay to completely remove the INI-as-default tests, as we decided to use YAML and not INI as future default storage (for good reasons).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback!
First I'll try to figure out why my test still gets executed on debian-stable-full-ini. If I don't find my error, I'll look into the CMake code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix in the CMake code most likely is much easier as many such fixes already exist.

See doc/todo/TESTING for a list of disabled tests. Please also add your test into this list.

@e01306821
Copy link
Contributor Author

The test now requires the dump storage plugin to run. Is that an acceptable solution?
I'm however not sure why testmod_dbus fails now.

@sanssecours
Copy link
Member

The test now requires the dump storage plugin to run. Is that an acceptable solution?

It is, in my opinion 😊. It would be great, if you could mount the dump plugin at the start of the MSR test and unmount it at the end. This way you make sure that the test uses the correct storage plugin. For an example, on how to do this please take a look here.

I'm however not sure why testmod_dbus fails now.

That is a known problem. I restarted the failed build jobs.

@markus2330 markus2330 merged commit 2ad71f9 into ElektraInitiative:master Mar 22, 2019
@markus2330
Copy link
Contributor

Thank you very much for your contribution! Everything is now nice and clean!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kdb get -v should also display default values.
3 participants