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

painless doc examples could be tested better #18961

Closed
rmuir opened this issue Jun 19, 2016 · 7 comments
Closed

painless doc examples could be tested better #18961

rmuir opened this issue Jun 19, 2016 · 7 comments
Labels
>bug >docs General docs changes >test Issues or PRs that are addressing/adding tests

Comments

@rmuir
Copy link
Contributor

rmuir commented Jun 19, 2016

I want to revamp this doc, i really do. But right now the examples in there aren't really being tested. I can put garbage methods in scripts and nothing fails. Perhaps its only compiling them and not actually running them against any documents, I don't know...

@rmuir rmuir added >bug >docs General docs changes >test Issues or PRs that are addressing/adding tests labels Jun 19, 2016
@nik9000
Copy link
Member

nik9000 commented Jun 19, 2016

It depends.... I can have a look at this on Monday probably.
On Jun 19, 2016 2:43 PM, "Robert Muir" [email protected] wrote:

I want to revamp this doc, i really do. But right now the examples in
there aren't really being tested. I can put garbage methods in scripts and
nothing fails. Perhaps its only compiling them and not actually running
them against any documents, I don't know...


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#18961, or mute the
thread
https://github.com/notifications/unsubscribe/AANLooD47dTKWuHY_KDuEshfsNFNLEk7ks5qNY3MgaJpZM4I5OUr
.

@rmuir
Copy link
Contributor Author

rmuir commented Jun 19, 2016

Thanks... It may be a simple bug in the examples themselves. Generated yaml seemed ok but no expert... I just have the feeling no actual docs are being hit

@rmuir
Copy link
Contributor Author

rmuir commented Jun 20, 2016

here is an example of what i'm trying that isn't provoking any fail. Of course this will compile, but if it were actually to run on any document it would crap out:

--- a/docs/reference/modules/scripting/painless.asciidoc
+++ b/docs/reference/modules/scripting/painless.asciidoc
@@ -109,7 +109,7 @@ GET hockey/_search
     "total_goals": {
       "script": {
         "lang": "painless",
-        "inline": "int total = 0; for (int i = 0; i < doc['goals'].length; ++i) { total += doc['goals'][i]; } return total;"
+        "inline": "doc['goals'].bogusMethod()"
       }
     }
   }

Since we have a lot of dynamic functionality i want it to catch me if i screw up. Part of the problem I think is that our examples are too lenient? I imagine having a lot of these to explain various syntax and stuff like that... Is there another way to encode checks other than //TESTRESPONSE ? Or another way to put it, a way to do //TESTRESPONSE but without it being user-visible in the docs?

@clintongormley
Copy link
Contributor

Or another way to put it, a way to do //TESTRESPONSE but without it being user-visible in the docs?

Yes, use comment blocks:

////////////////////
None of this is visible:

[source,js]
---------------
PUT foo/bar/1
{ "foo": 5 }
---------------
// TEST
////////////////////

This example is visible:

[source,js]
---------------
GET foo/_search
{
  "script_fields": {
    "my_field": {
      "script": {
        "lang": "painless",
        "inline": "doc['foo'].value+1"
      }
    }
  }
}
---------------
// CONSOLE
// TEST[continued]

////////////////////
The response can be hidden as well

[source,js]
---------------
{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "foo",
        "_type": "bar",
        "_id": "1",
        "_score": 1,
        "fields": {
          "my_field": [
            6
          ]
        }
      }
    ]
  }
}
---------------
// TESTRESPONSE[s/"took".*/"took": "$body.took",/]
////////////////////

@rmuir
Copy link
Contributor Author

rmuir commented Jun 20, 2016

thanks @clintongormley

@nik9000
Copy link
Member

nik9000 commented Jun 21, 2016

I merged #18979 which might make the comments not a required thing for painless. You bogusMethod example fails now. I'm going to close this because I think it is enough. If not, open it again.

@nik9000 nik9000 closed this as completed Jun 21, 2016
@rmuir
Copy link
Contributor Author

rmuir commented Jun 21, 2016

@nik9000 thanks a lot for looking into this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug >docs General docs changes >test Issues or PRs that are addressing/adding tests
Projects
None yet
Development

No branches or pull requests

3 participants