diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-01-20 18:05:07 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-01-20 19:56:06 -0800 |
| commit | 327c8bc7335e24633b24e7bfdbb23f76078c886f (patch) | |
| tree | 632e8c3efc2c3463afd811a556ea98fa7f6d5e83 /src | |
| parent | ba5cc236f7596148ad560b0bb651d82d15f0fc7f (diff) | |
| download | rust-327c8bc7335e24633b24e7bfdbb23f76078c886f.tar.gz rust-327c8bc7335e24633b24e7bfdbb23f76078c886f.zip | |
build: Run tutorial tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/etc/extract-tests.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/etc/extract-tests.py b/src/etc/extract-tests.py new file mode 100644 index 00000000000..32fc25a685a --- /dev/null +++ b/src/etc/extract-tests.py @@ -0,0 +1,63 @@ +# Script for extracting compilable fragments from markdown +# documentation. See prep.js for a description of the format +# recognized by this tool. Expects a directory fragements/ to exist +# under the current directory, and writes the fragments in there as +# individual .rs files. + +import sys, re; + +if len(sys.argv) < 3: + print("Please provide an input filename") + sys.exit(1) + +filename = sys.argv[1] +dest = sys.argv[2] +f = open(filename) +lines = f.readlines() +f.close() + +cur = 0 +line = "" +chapter = "" +chapter_n = 0 + +while cur < len(lines): + line = lines[cur] + cur += 1 + chap = re.match("# (.*)", line); + if chap: + chapter = re.sub(r"\W", "_", chap.group(1)).lower() + chapter_n = 1 + elif re.match("~~~", line): + block = "" + ignore = False + xfail = False + while cur < len(lines): + line = lines[cur] + cur += 1 + if re.match(r"\s*## (notrust|ignore)", line): + ignore = True + elif re.match(r"\s*## xfail-test", line): + xfail = True + elif re.match("~~~", line): + break + else: + block += re.sub("^# ", "", line) + if not ignore: + if not re.search(r"\bfn main\b", block): + if re.search( + r"(^|\n) *(native|use|mod|import|export)\b", block): + block += "\nfn main() {}\n" + else: + block = "fn main() {\n" + block + "\n}\n" + if not re.search(r"\buse std\b", block): + block = "use std;\n" + block; + if xfail: + block = "// xfail-test\n" + block + filename = (dest + "/" + str(chapter) + + "_" + str(chapter_n) + ".rs") + chapter_n += 1 + f = open(filename, 'w') + f.write(block) + f.close() + |
