Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
2ec2d2d
move example buttons to the left
wilzbach Dec 24, 2016
3ac7e46
update ddox to 0.15.18
wilzbach Dec 24, 2016
5e3ad15
Use new DDOX_UNITTEST_HEADER macro to define custom behavior of unitt…
wilzbach Dec 24, 2016
fa4c156
Ddox view: include run_examples.js & fix body id to the module (as ddoc)
wilzbach Dec 24, 2016
8d18fa7
update js/run_examples code s.t. it supports ddox
wilzbach Dec 24, 2016
456a6a9
Ddox: Show exact source code links for multiple declarations
wilzbach Dec 27, 2016
8a50dd6
Merge remote-tracking branch 'upstream/stable' into merge_stable
MartinNowak Jan 7, 2017
7f7fb31
Merge pull request #1547 from MartinNowak/merge_stable
MartinNowak Jan 7, 2017
19f73b8
Fix typo
tchaloupka Jan 7, 2017
da52368
ddox runnable examples: use :last to avoid interference with inline text
wilzbach Jan 7, 2017
f0b75b2
Merge pull request #1532 from wilzbach/run-examples-ddox
andralex Jan 7, 2017
faff55e
Merge pull request #1548 from tchaloupka/patch-1
wilzbach Jan 7, 2017
3ed4ef3
Update runnable modules blacklist
wilzbach Jan 7, 2017
e22187e
Tweak D for C, C++ programmers
ntrel Jan 12, 2017
551af09
Make suggested edits
ntrel Jan 13, 2017
36ff85a
Merge remote-tracking branch 'upstream/stable' into merge_stable
MartinNowak Jan 15, 2017
f99d0fe
Merge pull request #1554 from MartinNowak/merge_stable
MartinNowak Jan 15, 2017
fc3d7e6
Merge remote-tracking branch 'upstream/stable' into merge_stable
MartinNowak Jan 18, 2017
1ec9c7c
Merge pull request #1556 from MartinNowak/merge_stable
MartinNowak Jan 18, 2017
005b5fc
Merge remote-tracking branch 'upstream/stable' into merge_stable
MartinNowak Jan 22, 2017
b7a4561
Merge pull request #1560 from MartinNowak/merge_stable
MartinNowak Jan 22, 2017
82f057b
Merge pull request #1552 from ntrel/ctod-docs
schuetzm Jan 26, 2017
c14b468
Use runnable examples for released docs
wilzbach Jan 28, 2017
6f30057
Update high-level vision link
wilzbach Feb 6, 2017
9bcdcac
add gnex into orgs
alphaKAI Jan 29, 2017
db1c287
Merge pull request #1562 from alphaKAI/add-org-gnex
wilzbach Feb 6, 2017
d170327
Merge remote-tracking branch 'upstream/stable' into merge_stable
MartinNowak Feb 8, 2017
8f42ea9
Merge pull request #1566 from MartinNowak/merge_stable
MartinNowak Feb 9, 2017
b376ace
Add RISCV32 and RISCV64 version identifiers
e-y-e Feb 8, 2017
69e7b93
posix.mak: Work around DMD bug manifesting on certain filesystems
CyberShadow Feb 11, 2017
71a3ea8
Merge pull request #1568 from CyberShadow/pull-20170211-192740
wilzbach Feb 11, 2017
97af8f6
Merge remote-tracking branch 'upstream/stable' into merge_stable
MartinNowak Feb 13, 2017
4ad4071
Merge pull request #1569 from MartinNowak/merge_stable
MartinNowak Feb 13, 2017
2b7ad8f
Merge pull request #1537 from wilzbach/fix-source-code-links-ddox
CyberShadow Feb 14, 2017
3f320ab
Merge pull request #1561 from wilzbach/activate-runnable-examples
andralex Feb 15, 2017
aadad76
Merge pull request #1550 from wilzbach/update-runnable-module-blacklist
andralex Feb 15, 2017
f49c346
Update FAQ: Shared does not cause memory barriers
jpf91 Feb 14, 2017
3d9c395
Merge pull request #1570 from jpf91/patch-6
andralex Feb 15, 2017
457e4a3
Enable runnable examples on releases docs
wilzbach Feb 15, 2017
ab5ba6b
Return editor instance from bootstrap function
wilzbach Jan 7, 2017
7e75b64
Support assert to writeln rewrite magic with ddox
wilzbach Jan 7, 2017
a6d6e58
Merge remote-tracking branch 'upstream/stable' into merge_stable
MartinNowak Feb 16, 2017
d732049
Merge pull request #1572 from MartinNowak/merge_stable
MartinNowak Feb 16, 2017
2d41071
Merge pull request #1571 from wilzbach/enable-runnable-examples
andralex Feb 17, 2017
71bd729
Merge pull request #1551 from wilzbach/ddox-writeln-rewrite-magic
wilzbach Feb 17, 2017
d488852
Merge pull request #1564 from wilzbach/update-highlevel-vision
DmitryOlshansky Feb 17, 2017
0fd2bde
Point user to std.array.byPair if compatibility with Tuple is desired.
Feb 17, 2017
d5f86f0
Update documentation to reflect new defaults for cycle detection
schveiguy Feb 17, 2017
81d4acb
Disable regex assert -> writeln rewrite logic (for now)
wilzbach Feb 18, 2017
d82ab8b
Run.js: make the output a pre area (-> allows auto-expand)
wilzbach Feb 18, 2017
c78ba9f
Merge pull request #1573 from quickfur/byPair
wilzbach Feb 18, 2017
c5ebd4d
Fix: Invisible input/textarea text for light-on-dark systems
Abscissa Feb 19, 2017
12b44d2
Merge pull request #1574 from schveiguy/patch-1
DmitryOlshansky Feb 20, 2017
166af2a
update putao github url
zoujiaqing Feb 9, 2017
6ed4925
Merge pull request #1567 from huntlabs/master
wilzbach Feb 20, 2017
52289a6
Merge pull request #1565 from e-y-e/riscv-version
DmitryOlshansky Feb 20, 2017
af1b24d
Merge pull request #1575 from wilzbach/improve-runnable
andralex Feb 20, 2017
156e9c6
Merge pull request #1576 from Abscissa/patch-1
CyberShadow Feb 20, 2017
9453d80
Extend and beautify the Phobos style guide
wilzbach Feb 21, 2017
c39aa29
Merge pull request #1578 from wilzbach/add-assert-style
andralex Feb 21, 2017
386c894
Fix Issue 17115 - Remove std.concurrencybase and std.stdiobase from t…
wilzbach Feb 22, 2017
a7e7c0b
Specify exact type of 501(c) organization
jcd Feb 25, 2017
aad1052
Merge pull request #1583 from jcd/patch-1
wilzbach Feb 26, 2017
a7232de
Add a conservative assert to writeln transformer
wilzbach Feb 22, 2017
3387076
Integrate assert_writeln_magic into Phobos-release build
wilzbach Feb 22, 2017
f1c041d
Bump DUB to 1.1.0 for single file support
wilzbach Feb 22, 2017
9d1dadf
set libdparse version to v0.7.0-beta.7
wilzbach Feb 23, 2017
30e7790
set _writeln stub to private
wilzbach Feb 23, 2017
49835ed
Add private comment before writeln to avoid any interference
wilzbach Feb 23, 2017
2e1e655
Use a temporary directory to store the writeln transformed Phobos code
wilzbach Feb 23, 2017
07da414
Add a soft fallback if no rsync is provided
wilzbach Feb 23, 2017
a7c7f34
Add assert_writeln postprocessing to the stable releases pages
wilzbach Feb 24, 2017
b361d73
Use .generated for Phobos transformation builds
wilzbach Feb 24, 2017
2bfe60b
Add pending_changelog target
wilzbach Jan 7, 2017
f092343
Merge pull request #1549 from wilzbach/add-pending-changelog-target
CyberShadow Feb 27, 2017
16c6bc4
Support --no-exact-source-links in dpl-docs
wilzbach Feb 27, 2017
5a584d8
Support a DIFFABLE mode that surpresses all potentially different infos
wilzbach Feb 27, 2017
c9b3bd3
Merge pull request #1588 from wilzbach/better-diff-mode
CyberShadow Feb 27, 2017
18062eb
Merge pull request #1582 from wilzbach/assert_writeln_magic
CyberShadow Feb 27, 2017
6649ffa
posix.mak: Use TMP environment variable for temporary directory
CyberShadow Feb 27, 2017
5e82fb2
Use nightly changelog theme
wilzbach Feb 27, 2017
89fb4ce
Add generated *_pre changelog files to .gitignore
wilzbach Feb 27, 2017
c49f07a
Make modlist.d generic
wilzbach Feb 22, 2017
64ef1ff
Merge pull request #1580 from wilzbach/make-module-lister-generic
CyberShadow Feb 27, 2017
1e042c7
Merge pull request #1589 from CyberShadow/pull-20170227-154459
wilzbach Feb 27, 2017
90f9ffa
Merge pull request #1579 from wilzbach/fix-17115
CyberShadow Feb 28, 2017
d4de91e
Mention the DWiki entry in the README
wilzbach Feb 28, 2017
e208a6b
Merge pull request #1591 from wilzbach/mention-dwiki
wilzbach Mar 1, 2017
d3dd43e
Added padding to links in Phobos book table
JackStouffer Mar 1, 2017
00aa0bb
Use pattern rules for the intermediate assert/writeln translation
wilzbach Feb 27, 2017
e20cfee
Add more comments to posix.mak
wilzbach Mar 1, 2017
83b47d6
Use osmodel.mak for dlang.org
wilzbach Mar 1, 2017
ca6ba64
Add tools and installer dir to the auto git cloned repos
wilzbach Mar 1, 2017
c9cf21e
write the assert_writeln_magic binary to the .generated folder
wilzbach Mar 1, 2017
c1e1666
Merge pull request #1590 from wilzbach/cleanup-makefile-patterns
wilzbach Mar 1, 2017
46a365b
Merge pull request #1593 from JackStouffer/booktable
wilzbach Mar 1, 2017
f854fb1
Enable Ddoc DMD release + Ddoc build of DMD docs
wilzbach Feb 22, 2017
e88d2c7
Add DMD to the verbatim output
wilzbach Feb 27, 2017
dbadbc3
Remove id.d exclusion + add comments
wilzbach Mar 1, 2017
6e22305
Use Phobos variables for DMD docs build
wilzbach Mar 1, 2017
4d86d70
Merge pull request #1581 from wilzbach/enable-dmd-doc-builds
andralex Mar 1, 2017
209e36b
DUB compile: use STABLE_DMD + bump to 2.072.2
wilzbach Mar 1, 2017
f68d5df
osmodel.mak: Mention tools + dlang.org repos in the update reminder
wilzbach Mar 2, 2017
4ec5cbf
Merge pull request #1594 from wilzbach/os-model-mention-tools-and-dla…
CyberShadow Mar 2, 2017
1897281
Fixed issues in C code examples and added modern C standard idioms (C…
schlupa Mar 2, 2017
c7f9fb7
Merge pull request #1586 from wilzbach/use-nightly-changelog-theme
MartinNowak Mar 2, 2017
83430bb
Footer: show always the current year and the D Language Foundation (#…
wilzbach Mar 2, 2017
04df1ca
Updated makefile to use dmd/generated/os/release/model/dmd
RazvanN7 Mar 3, 2017
696bf2b
Merge pull request #1598 from RazvanN7/master
dlang-bot Mar 3, 2017
b17fcc4
Merge pull request #1592 from wilzbach/dub-use-stable-dmd
MartinNowak Mar 3, 2017
42bfe1a
Remove "Call for submissions" from news (#1597)
wilzbach Mar 3, 2017
9612347
Merge remote-tracking branch 'upstream/stable' into merge_stable
MartinNowak Mar 4, 2017
262f061
Merge pull request #1599 from MartinNowak/merge_stable
MartinNowak Mar 4, 2017
03903b8
Make link padding only apply to more specific cases
adamdruppe Mar 5, 2017
af0e0eb
Merge pull request #1600 from adamdruppe/css
dlang-bot Mar 5, 2017
731eae5
Removed redundant DMD_GEN variable and replaced it's occurences with DMD
RazvanN7 Mar 6, 2017
44dd86f
Make links in 404 pages absolute
CyberShadow Mar 6, 2017
0e83ed3
Removed redundant DMD_GEN variable and replaced it's occurences with DMD
RazvanN7 Mar 6, 2017
631a307
Merge pull request #1602 from RazvanN7/Make_updates
dlang-bot Mar 6, 2017
1988da7
Merge pull request #1603 from CyberShadow/pull-20170306-121506
andralex Mar 8, 2017
0932846
Add style rule for Phobos about field declarations
JackStouffer Mar 8, 2017
f671f8b
Merge pull request #1605 from JackStouffer/phobos-style
dlang-bot Mar 8, 2017
f2f41aa
Update safed.dd
insideoutclub Mar 9, 2017
82314fa
Merge remote-tracking branch 'upstream/stable' into merge_stable
MartinNowak Mar 9, 2017
5a9e367
Merge pull request #1607 from MartinNowak/merge_stable
MartinNowak Mar 9, 2017
049ede3
changelog/2.073.2: Fix VER
CyberShadow Mar 10, 2017
f9e3069
Merge pull request #1608 from CyberShadow/pull-20170310-170409
wilzbach Mar 10, 2017
b415173
Merge pull request #1606 from insideoutclub/patch-1
wilzbach Mar 15, 2017
fb161b5
Merge remote-tracking branch 'upstream/stable' into merge_stable
MartinNowak Mar 22, 2017
39ae7fa
Merge pull request #1610 from MartinNowak/merge_stable
MartinNowak Mar 22, 2017
526586c
Merge remote-tracking branch 'upstream/master' into merge_master
MartinNowak Mar 22, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ modlist-release.ddoc

/d.tag
/.generated

# DUB binaries
/assert_writeln_magic

# Generated changelogs
changelog/*_pre.dd
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ documentation, and some articles.
* [Wiki](https://wiki.dlang.org/)

If you wish to contribute to the website or language documentation, please see
the [CONTRIBUTING.md file] (CONTRIBUTING.md).
the [CONTRIBUTING.md file](CONTRIBUTING.md) and [wiki entry](https://wiki.dlang.org/Contributing_to_dlang.org).
323 changes: 323 additions & 0 deletions assert_writeln_magic.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,323 @@
#!/usr/bin/env dub
/++
dub.sdl:
dependency "libdparse" version="0.7.0-beta.7"
name "assert_writeln_magic"
+/
/*
* Tries to convert `assert`'s into user-friendly `writeln` calls.
* The objective of this tool is to be conservative as
* broken example look a lot worse than a few statements
* that could have potentially been rewritten.
*
* - only EqualExpressions are "lowered"
* - static asserts are ignored
* - only single-line assers are rewritten
*
* Copyright (C) 2017 by D Language Foundation
*
* Author: Sebastian Wilzbach
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
// Written in the D programming language.

import dparse.ast;
import std.algorithm;
import std.conv;
import std.experimental.logger;
import std.range;
import std.stdio;
import std.typecons;

private string formatNode(T)(const T t)
{
import dparse.formatter;
import std.array : appender;

auto writer = appender!string();
auto formatter = new Formatter!(typeof(writer))(writer);
formatter.format(t);
return writer.data;
}

class TestVisitor : ASTVisitor
{
import dparse.lexer : tok, Token;

this(string fileName, string destFile)
{
this.fileName = fileName;
fl = FileLines(fileName, destFile);
}

alias visit = ASTVisitor.visit;

override void visit(const Unittest test)
{
resetTestState();
inTest = true;
scope(exit) inTest = false;
test.accept(this);

processLastAssert();
}

override void visit(const EqualExpression expr)
{
enum eqToken = tok!"==";
if (inAssert && expr.operator == eqToken && expr.left !is null && expr.right !is null)
lastEqualExpression = expr;
}

override void visit(const AssertExpression expr)
{
if (inFunctionCall)
return;

lastAssert = expr;
inAssert = true;
expr.accept(this);
inAssert = false;
fromAssert = true;
}

// for now static asserts are ignored
override void visit(const StaticAssertStatement expr)
{
fromStaticAssert = true;
expr.accept(this);
}

/**
The following code (in std.concurrency) leads to false positives:

assertNotThrown!AssertError(assert(receiveOnly!int() == i));

Hence we simply ignore all asserts in function calls.
*/
override void visit(const FunctionCallExpression expr)
{
inFunctionCall = true;
expr.accept(this);
inFunctionCall = false;
}

/// A single line
override void visit(const DeclarationOrStatement expr)
{
processLastAssert();
expr.accept(this);
}

void processLastAssert()
{
import std.uni : isWhite;
import std.format : format;

if (fromAssert && !fromStaticAssert &&
lastEqualExpression !is null && lastAssert !is null)
{
auto e = lastEqualExpression;
if (e.left !is null && e.right !is null)
{
// libdparse starts the line count with 1
auto lineNr = lastAssert.line - 1;

// only replace single-line expressions (for now)
if (fl[lineNr].endsWith(";"))
{
auto wsLen = fl[lineNr].countUntil!(u => !u.isWhite);
auto indent = fl[lineNr][0 .. wsLen];

if (fl[lineNr][wsLen .. $].startsWith("assert", "static assert"))
{
auto left = lastEqualExpression.left.formatNode;
auto right = lastEqualExpression.right.formatNode;

if (left.length + right.length > 80)
fl[lineNr] = format("%s// %s\n%swriteln(%s);", indent, right, indent, left);
else
fl[lineNr] = format("%swriteln(%s); // %s", indent, left, right);

//writefln("line: %d, column: %d", lastAssert.line, lastAssert.column);
}
}
}
}
resetTestState();
}

private:

void resetTestState()
{
fromAssert = false;
fromStaticAssert = false;
lastEqualExpression = null;
lastAssert = null;
}

/// within in the node
bool inTest;
bool inAssert;
bool inFunctionCall;

/// at a sibling after the node was seen, but the upper parent hasn't been reached yet
bool fromAssert;
bool fromStaticAssert;

Rebindable!(const AssertExpression) lastAssert;
Rebindable!(const EqualExpression) lastEqualExpression;

string fileName;
FileLines fl;
}

void parseFile(string fileName, string destFile)
{
import dparse.lexer;
import dparse.parser : parseModule;
import dparse.rollback_allocator : RollbackAllocator;
import std.array : uninitializedArray;

auto inFile = File(fileName);
if (inFile.size == 0)
warningf("%s is empty", inFile.name);

ubyte[] sourceCode = uninitializedArray!(ubyte[])(to!size_t(inFile.size));
inFile.rawRead(sourceCode);
LexerConfig config;
auto cache = StringCache(StringCache.defaultBucketCount);
const(Token)[] tokens = getTokensForParser(sourceCode, config, &cache).array;

RollbackAllocator rba;
auto m = parseModule(tokens, fileName, &rba);
auto visitor = new TestVisitor(fileName, destFile);
visitor.visit(m);
delete visitor;
}

// Modify a path under oldBase to a new path with the same subpath under newBase.
// E.g.: `/foo/bar`.rebasePath(`/foo`, `/quux`) == `/quux/bar`
string rebasePath(string path, string oldBase, string newBase)
{
import std.path : absolutePath, buildPath, relativePath;
return buildPath(newBase, path.absolutePath.relativePath(oldBase.absolutePath));
}

void main(string[] args)
{
import std.file;
import std.getopt;
import std.path;

string inputDir, outputDir;
string[] ignoredFiles;

auto helpInfo = getopt(args, config.required,
"inputdir|i", "Folder to start the recursive search for unittest blocks (can be a single file)", &inputDir,
"outputdir|o", "Alternative folder to use as output (can be a single file)", &outputDir,
"ignore", "List of files to exclude (partial matching is supported)", &ignoredFiles);

if (helpInfo.helpWanted)
{
return defaultGetoptPrinter(`assert_writeln_magic
Tries to lower EqualExpression in AssertExpressions of Unittest blocks to commented writeln calls.
`, helpInfo.options);
}

inputDir = inputDir.asNormalizedPath.array;

DirEntry[] files;

// inputDir as default output directory
if (!outputDir.length)
outputDir = inputDir;

if (inputDir.isFile)
{
files = [DirEntry(inputDir)];
inputDir = "";
}
else
{
files = dirEntries(inputDir, SpanMode.depth).filter!(
a => a.name.endsWith(".d") && !a.name.canFind(".git")).array;
}

foreach (file; files)
{
if (!ignoredFiles.any!(x => file.name.canFind(x)))
{
// single files
if (inputDir.length == 0)
parseFile(file.name, outputDir);
else
parseFile(file.name, file.name.rebasePath(inputDir, outputDir));
}
}
}

/**
A simple line-based in-memory representation of a file.
- will automatically write all changes when the object is destructed
- will use a temporary file to do safe, whole file swaps
*/
struct FileLines
{
import std.array, std.file, std.path;

string[] lines;
string destFile;
bool overwriteInputFile;
bool hasWrittenChanges;

this(string inputFile, string destFile)
{
stderr.writefln("%s -> %s", inputFile, destFile);
this.overwriteInputFile = inputFile == destFile;
this.destFile = destFile;
lines = File(inputFile).byLineCopy.array;

destFile.dirName.mkdirRecurse;
}

// dumps all changes
~this()
{
if (overwriteInputFile)
{
if (hasWrittenChanges)
{
auto tmpFile = File(destFile ~ ".tmp", "w");
writeLinesToFile(tmpFile);
tmpFile.close;
tmpFile.name.rename(destFile);
}
}
else
{
writeLinesToFile(File(destFile, "w"));
}
}

// writes all changes to a random, temporary file
void writeLinesToFile(File outFile) {
// dump file
foreach (line; lines)
outFile.writeln(line);
// within the docs we automatically inject std.stdio (hence we need to do the same here)
// writeln needs to be @nogc, @safe, pure and nothrow (we just fake it)
outFile.writeln("// \nprivate void writeln(T)(T l) { }");
outFile.flush;
}

string opIndex(size_t i) { return lines[i]; }
void opIndexAssign(string line, size_t i) {
hasWrittenChanges = true;
lines[i] = line;
}
}
4 changes: 2 additions & 2 deletions changelog/2.073.0.dd
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ $(LI $(LNAME2 std-algorithm-searching-maxindex,Added `std.algorithm.searching.ma
-------
import std.algorithm.searching : maxIndex;
int[] a = [5, 4, 2, 1, 9, 10];
assert(a.minIndex == 5);
assert(a.maxIndex == 5);

int[] a;
assert(a.minIndex == -1);
assert(a.maxIndex == -1);
-------
)

Expand Down
2 changes: 1 addition & 1 deletion changelog/2.073.2.dd
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ $(LI $(BUGZILLA 17198): rdmd does not recompile when --extra-file is added)
)
$(CHANGELOG_NAV_LAST 2.073.1)
Macros:
VER=LATEST
VER=2.073.2
TITLE=Change Log: $(VER)
9 changes: 9 additions & 0 deletions changelog/changelog.ddoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ $(SMALL released $1, $2)
$4
)

NIGHTLY_VERSION=
$(DIVC version,
$(P
$(B $(LARGE $(LINK2 http://nightlies.dlang.org, Download D nightlies)))$(BR)
$(SMALL $1)
)
$4
)

BUGZILLA = <a href="https://issues.dlang.org/show_bug.cgi?id=$0">Bugzilla $0</a>
CPPBUGZILLA = <a href="http://bugzilla.digitalmars.com/issues/show_bug.cgi?id=$0">Bugzilla $0</a>
DSTRESS = dstress $0
Expand Down
Loading