-
-
Notifications
You must be signed in to change notification settings - Fork 387
Edit & run examples from unittests #1297
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
Conversation
60b6cd1 to
0adb6a9
Compare
css/style.css
Outdated
| /* Style for the example run buttons on the Phobos library documentation */ | ||
| .d_example_buttons { | ||
| text-align: right; | ||
| } No newline at end of file |
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.
new line here please
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.
may I ask for the motivation?
|
Why is there so much new JS code? Can't the front page code be reused? |
|
Should this not be enabled only for Phobos pages? |
|
As I mentioned at DConf, this should only be enabled for documented unittests (runnable examples). This may need a small compiler patch to allow distinguishing the two. A lot of the non-unittest examples are nonsensical out of context (see e.g. std.file.timeLastModified). |
| @@ -0,0 +1,159 @@ | |||
| $(document).ready(function() | |||
| { | |||
| if ($('body')[0].id == "Home") | |||
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.
document.getElementsByTagName('body')[0].id == "Home"
I'm all for jQuery for when it abstracts differences between browsers, but for the simple stuff let's stick with plain JS.
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.
If jQuery is already in use then there is no reason not to use all of it.
@CyberShadow We really shouldn't. I know I added some code to the site that used JQuery, but I recently changed my mind on this. Just run this code in your console on the dlang.org home and look at the performance: My results For a few extra keystrokes you suddenly get 3x faster. |
|
Last I checked we had no pages with hundreds of thousands of runnable examples on them. Profile then optimize. What you are suggesting is premature optimization. |
|
|
||
| // only for std at the moment | ||
| if(!$('body').hasClass("std")) | ||
| return; |
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.
This enables the tests only on phobos
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.
Would be nice to avoid including the JS file at all on other pages, so there's no useless impact on load speed.
|
On Fri, May 13, 2016 at 07:53:06AM -0700, Vladimir Panteleev wrote:
If it is trivial to use the better way, you might as well just do it |
No, we don't. But that doesn't mean that we should be consciously using code that is slower in order to save like, ten characters.
These things add up. |
|
I'm going to have to ask you to kindly stop it with the bullshit.
If you want to make a positive contribution, you could try rewriting Otherwise, I suggest you refrain from such future criticism, because the only impact you're making is aggravating contributors who are actually trying to make a positive change. |
|
Dude,
I'm not asking for much here. I'm asking that thirty seconds be taken to use the faster version. And if you disagree with me, you're the one with merge rights at the end of the day. |
|
I see my point did not get through. It is not at all faster, in this case. The only effect such a change would have is make the code longer and more inconsistent. |
That would be great to have. Can we just have two separate css classes maybe? |
0adb6a9 to
8c2bdaf
Compare
|
I agree with CyberShadow. Getting rid of jQuery altogether can be worthwhile, but only because it would be one dependency fewer, not because |
js/run_examples.js
Outdated
| + '</div>' | ||
| + '</div>' | ||
| ); | ||
| console.log(orig); |
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.
Won't it break on IE?
IIRC IE doesn't like console. too much ;)
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.
Won't it break on IE?
IIRC IE doesn't like console. too much ;)
Oh that was just for testing - will be removed soon. Sorry about that.
What do you mean by this? |
s.t. like |
|
Hm - dpaste uses the newest stable DMD for any request from dlang.org How would you annotate specific unittest/example to run with different compiler version? |
Oh I didn't know that. That's great!
Have you tried user-defined attributes. |
That is not right. If it's a Phobos function, then use the version from which that code comes from, no? |
Yeah - as I said dpaste uses newest-dmd available for dlang.org's examples. Same goes for phobos. The only thing worth changing probably would be phobos' prerelease docs - there we probably should use nightly builds of DMD @ Dpaste. I was asking mostly out of curiosity - I though that maybe @wilzbach has got an idea how we could annotate code examples somehow - so for example we could get rid of MD5 sums co-related with examples on the main page. I had an idea that maybe we could use comments in code examples. // @input: Mercury\nVenus\nEarth\nMars\nJupiter\nSaturn\nUranus\nNeptune
// @args: foo bar if needed
// Sort lines
import std.stdio, std.array, std.algorithm;
void main()
{
stdin
.byLineCopy
.array
.sort!((a, b) => a > b) // descending order
.each!writeln;
}Anyways - sorry for the off-topic. Back to the case: From what I can see now mostly there are self-contained assertions and so on and the missing bits like std.base64 should be just corrected to either provide imports, stdin etc or re-arrange example entirely. @wilzbach btw if you need anything on dpaste part - feel free to ping me. It will be open-sourced very soon but meanwhile I can help ASAP with any requirments. |
|
Great! |
5b7be7c to
cf8167b
Compare
a3b5d47 to
af2a4f1
Compare
Would this strategy work? (I am bit spare on time atm) |
|
Okay I managed to find some time to revive this PR. As discussed above to ensure that we won't introduce regressions and verify the runnability of existing snippets, we do need to run them :) |
andralex
left a comment
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.
LGTM, make sure you fix the ddoc tester
d36a9c7 to
752f43d
Compare
752f43d to
c1d18f4
Compare
|
Okay with dlang/phobos#4943 I this is finally in a usuable state :)
|
|
Great. About 1 - where is that list of modules for which this is enabled? And what to do to expand it? |
There's a hard-coded exclusion list: https://github.com/dlang/phobos/blob/master/posix.mak#L523 This PR contains a copy of it
Simple: remove a module from the exclusion list, have a look at the missing imports, make a PR. |
e.g. dlang/phobos#4966 @andralex Unfortunately I can't merge stuff here. Is anything blocking this experiment? edit: for convenience here's a preview link ("run" doesn't work here as dtest isn't allowed in the CORS settings of dpaste) |
|
This is awesome! FWIW @CyberShadow I saw a confusing message in the log of your doc builder: Yet the build was successful. |
|
cool cool cool thanks @wilzbach |
Yep, those are normal. Digger checks whether a cache entry exists by asking git to describe it, and git prints that to stderr when it doesn't (i.e. on a cache miss). |
|
@wilzbach saw the list thx, if you work on it great, if you stop at a point please put the balance of it in bugzilla. Thanks! |
Yeah it's online :) https://dlang.org/phobos-prerelease/std_algorithm_searching.html#.minElement
https://issues.dlang.org/show_bug.cgi?id=16984 (extend list of runnable modules on dlang.org) |
|
Cool! Just tried one, it works!! How about enabling everything for ddox e.g. https://dlang.org/library-prerelease/std/algorithm/iteration/cache.html, is this easy? cc @s-ludwig |
Started a discussion: |
@nazriel do you also maintain a copy of the latest nightly release? |
Hey all,
I wanted to be able to execute the examples directly from the documentation for a long time. It turns out, it's not that hard ;-)
The current module and
write,writelnare imported. It might be that a couple of tests depend on the private imports in a module, but this is discouraged anyways as the public documented unittests should really only need the current module imported. I tested it randomly with a couple of modules and so far everything seems to work well.This feature is experimental and I would love feedback on it.
As dpaste requires CORS and the origin must be dlang.org, you have to trick a bit to test it.
If you happen to use pdns, it as easy as
pdnsd-ctl add a 127.0.0.1 dlang.orgthough.Therefore here are some images as impressions:
writeln works too:
@CyberShadow: maybe we can even send the D version to DPaste so we never run into troubles of library mismatches?
Edit: maybe @CyberShadow can add DAutoTest to the origin whitelist of DPaste?