File tree Expand file tree Collapse file tree 4 files changed +88
-0
lines changed Expand file tree Collapse file tree 4 files changed +88
-0
lines changed Original file line number Diff line number Diff line change
1
+ langauge : cpp
2
+ compiler : gcc
3
+ dist : trusty
4
+
5
+ before_script :
6
+ - cd test
7
+ script :
8
+ - ./test.sh
Original file line number Diff line number Diff line change
1
+ rm * .h
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python3
2
+ import re
3
+ import os
4
+
5
+ def write_snippet (name , lines ):
6
+ file_name = '{}.h' .format (name )
7
+ with open (file_name , 'w' ) as f :
8
+ for line in lines :
9
+ f .write (line )
10
+
11
+ def extract_tests (filepath ):
12
+ filepath_short = os .path .basename (filepath )
13
+ article_name = filepath_short .split ('.' )[0 ]
14
+
15
+ snippet_start = re .compile (r"^```cpp\s+(\S+)$" )
16
+ snippet_end = re .compile (r"^```$" )
17
+
18
+ with open (filepath ) as f :
19
+ in_snippet = False ;
20
+ for line in f :
21
+ m_start = snippet_start .match (line )
22
+ m_end = snippet_end .match (line )
23
+
24
+ if in_snippet and m_end :
25
+ in_snippet = False
26
+ write_snippet (snippet_name , lines )
27
+
28
+ if in_snippet :
29
+ lines .append (line )
30
+ elif m_start :
31
+ snippet_name = m_start .group (1 )
32
+ lines = []
33
+ in_snippet = True
34
+
35
+
36
+ if __name__ == '__main__' :
37
+ for subdir , dirs , files in os .walk ('../src/' ):
38
+ for filename in files :
39
+ if filename .endswith (".md" ):
40
+ extract_tests (os .path .join (subdir , filename ))
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ python extract_snippets.py
3
+
4
+ if [ -z " $CXX " ];
5
+ then
6
+ CXX=g++
7
+ fi
8
+
9
+ TESTS=0
10
+ SUCCESS=0
11
+ for cppfile in * .cpp;
12
+ do
13
+ TESTS=$(( TESTS + 1 ))
14
+ $CXX -std=c++11 $cppfile -o $cppfile .out
15
+ COMPILATION=$?
16
+ if [ $COMPILATION -eq 0 ];
17
+ then
18
+ ./$cppfile .out
19
+ TEST_SUCCESS=$?
20
+ if [ $TEST_SUCCESS -eq 0 ];
21
+ then
22
+ SUCCESS=$(( SUCCESS + 1 ))
23
+ else
24
+ echo " Test $cppfile failed!"
25
+ fi
26
+ else
27
+ echo " Error while compiling $cppfile !"
28
+ fi
29
+
30
+ rm $cppfile .out
31
+ done
32
+
33
+ echo " $SUCCESS / $TESTS tests were successful."
34
+ if [ $SUCCESS -eq $TESTS ];
35
+ then
36
+ exit 0
37
+ else
38
+ exit 1
39
+ fi
You can’t perform that action at this time.
0 commit comments