示例#1
0
from coderunner import test, Cpp, main

test(Cpp,
     "raii.cpp",
     """
scenario1: normal case
try to open
open
try to use
use
close


scenario2: failed to open
try to open
throw
exception caught: error on open


scenario3: opened, but failed to use
try to open
open
try to use
throw
close
exception caught: error on use
""",
     is_file=True)

main()
示例#2
0
# -*- encoding: utf-8 -*-
"""
Trap zero division error
"""
from coderunner import test, Cpp, main

test(Cpp, "zero_division.cpp", is_file=True, is_embedded_output=True, ignore_warning=True)

main()
示例#3
0
# -*- encoding: utf-8 -*-
"""
Test of similar feature
- Python's with-statement
- Java7's try-with-resource
- C#'s using-statement
"""
from coderunner import test, Python, Java7, CSharp, main

test(Java7, "TryWithResource.java", is_file=True, is_embedded_output=True)
test(CSharp, "Using.cs", is_file=True, is_embedded_output=True)
test(Python, "with_statement.py", is_file=True, is_embedded_output=True)
test(Python, "with_statement2.py", is_file=True, is_embedded_output=True)


main()
示例#4
0
from coderunner import test, Cpp, main

test(Cpp, "raii.cpp", """
scenario1: normal case
try to open
open
try to use
use
close


scenario2: failed to open
try to open
throw
exception caught: error on open


scenario3: opened, but failed to use
try to open
open
try to use
throw
close
exception caught: error on use
""", is_file=True)

main()
示例#5
0
from coderunner import test, Cpp, main

test(Cpp, "embedded_output.cpp", is_file=True, is_embedded_output=True)
test(Cpp, "multi_embed.cpp", is_file=True, is_embedded_output=True)

main()
示例#6
0
# -*- encoding: utf-8 -*-
"""
Samples to cause error
"""
from coderunner import test, Python, main

test(Python, """
def good_function():
    global x
    x = 1
""", """
""")

test(
    Python, """
def bad_function():
    global x = 1
""", """
  File "tmp.py", line 2
    global x = 1
             ^
SyntaxError: invalid syntax
""")

test(Python, """
x = 1
def good_function():
    print x
""", """
""")
示例#7
0
from coderunner import test, Python, main

test(Python, "print 1", "1")

main()
示例#8
0
# -*- encoding: utf-8 -*-
from coderunner import test, Perl, LangC, Python, Ruby, Cpp, main

test(Ruby, "module_inheritance.rb", """
hello
hello
""", is_file=True)

test(Ruby, "mixin.rb", """
bar!
""", is_file=True)

test(Perl, "reenter.pl", """
0
""", is_file=True)

test(Python, "oldclass.py", """
base
D2
base
""", is_file=True)

test(Python, "pack.py", """
スズメ: 1匹
スズメ: 2匹
カラス: 1匹
スズメ: 3匹
""", is_file=True)

test(Cpp,
     "iter.cpp",
示例#9
0
# -*- encoding: utf-8 -*-
"""
Different betwern Python2.* and Python3.*
"""
from coderunner import test, Python27, Python30, main
"""
Print Is A Function
"""

test(Python27, """
print "hello"
""", """
hello
""")

test(
    Python30, """
print "hello"
""", """
  File "tmp.py", line 1
    print "hello"
                ^
SyntaxError: invalid syntax
""")

test(Python30, """
print("hello")
""", """
hello
""")
"""
示例#10
0
from coderunner import test, Perl, main

test(Perl, "dynamic.pl", """
yobu-local
""", is_file=True)

test(Perl, "static.pl", """
global
""", is_file=True)

main()
示例#11
0
# -*- encoding: utf-8 -*-
"""
Samples to cause error
"""
from coderunner import test, Python, main

test(Python, """
def good_function():
    global x
    x = 1
""", """
""")

test(Python, """
def bad_function():
    global x = 1
""", """
  File "tmp.py", line 2
    global x = 1
             ^
SyntaxError: invalid syntax
""")

test(Python, """
x = 1
def good_function():
    print x
""", """
""")

test(Python, """
示例#12
0
# -*- encoding: utf-8 -*-
"""
Samples to cause error
"""
from coderunner import test, Python, main

test(
    Python,
    """
if true:
print 1
""",
    """
  File "tmp.py", line 2
    print 1
        ^
IndentationError: expected an indented block
""",
)

test(
    Python,
    """
if true:
    print 1
   print 2
""",
    """
  File "tmp.py", line 3
    print 2
          ^
示例#13
0
from coderunner import test, Clojure, main

test(Clojure, "stm.clj", is_file=True, is_embedded_output=True)
test(Clojure, "stm2.clj", is_file=True, is_embedded_output=True)
test(Clojure, "var.clj", is_file=True, is_embedded_output=True)
test(Clojure, "atom.clj", is_file=True, is_embedded_output=True)

main()
示例#14
0
# -*- encoding: utf-8 -*-
from coderunner import test, Perl, LangC, Python, Ruby, Cpp, main


test(Ruby, "module_inheritance.rb", """
hello
hello
""", is_file=True)

test(Ruby, "mixin.rb", """
bar!
""", is_file=True)

test(Perl, "reenter.pl", """
0
""", is_file=True)

test(Python, "oldclass.py", """
base
D2
base
""", is_file=True)

test(Python, "pack.py", """
スズメ: 1匹
スズメ: 2匹
カラス: 1匹
スズメ: 3匹
""", is_file=True)

test(Cpp, "iter.cpp", """
示例#15
0
# -*- encoding: utf-8 -*-
"""
Samples to cause error
"""
from coderunner import test, Python, main

test(Python, """
if true:
print 1
""", """
  File "tmp.py", line 2
    print 1
        ^
IndentationError: expected an indented block
""")

test(Python, """
if true:
    print 1
   print 2
""", """
  File "tmp.py", line 3
    print 2
          ^
IndentationError: unindent does not match any outer indentation level
""")

test(Python, """
# -*- encoding: utf-8 -*-
if true:
 print 1 # unicode space character
示例#16
0
from coderunner import test, LangC, main

test(LangC, "main.c", is_file=True, is_embedded_output=True)
test(LangC, "float_as_int.c", is_file=True, is_embedded_output=True)
test(LangC, "add.c", is_file=True, is_embedded_output=True)

main()
示例#17
0
"""
dontcare feature

Following Perl code prints something like "HASH(0x7fc5a9003ea0)" but if changes.
We need to ignore the change.
"""
from coderunner import test, Perl, main


test(
    Perl,
    """
$x = {};
print "$x\n";
""",
    """
HASH(0x7fc5a9003ea0)
""",
)

main()
示例#18
0
from coderunner import test, Cpp, main

test(Cpp, "virtual.cpp", """
Base
Base
""", is_file=True)
test(Cpp,
     "virtual.cpp",
     """
B
Base
""",
     is_file=True,
     extra_option=["-DVIRTUAL"])

main()
示例#19
0
# -*- encoding: utf-8 -*-
from coderunner import test, Python, main

test(Python, "recursive.py", """
15
""", is_file=True)

main()
示例#20
0
# -*- encoding: utf-8 -*-
"""
Different betwern Python2.* and Python3.*
"""
from coderunner import test, Python27, Python30, main

"""
Print Is A Function
"""

test(Python27, """
print "hello"
""", """
hello
""")

test(Python30, """
print "hello"
""", """
  File "tmp.py", line 1
    print "hello"
                ^
SyntaxError: invalid syntax
""")

test(Python30, """
print("hello")
""", """
hello
""")
示例#21
0
# -*- encoding: utf-8 -*-
import sys
from coderunner import test, LangC, Java, main

test(LangC,
     "no_for.c",
     """
use_for
0
1
2
3
4
not_use_for
0
1
2
3
4
""",
     is_file=True)

test(LangC,
     "no_while.c",
     """
use_while
5
4
3
2
1
示例#22
0
# -*- encoding: utf-8 -*-
import sys
from coderunner import test, LangC, Java, main

test(LangC, "no_for.c", """
use_for
0
1
2
3
4
not_use_for
0
1
2
3
4
""", is_file=True)

test(LangC, "no_while.c", """
use_while
5
4
3
2
1
not_use_while
5
4
3
2
示例#23
0
"""
dontcare feature

Following Perl code prints something like "HASH(0x7fc5a9003ea0)" but if changes.
We need to ignore the change.
"""
from coderunner import test, Perl, main

test(Perl, """
$x = {};
print "$x\n";
""", """
HASH(0x7fc5a9003ea0)
""")

main()
示例#24
0
from coderunner import test, Cpp, main

test(Cpp, "virtual.cpp", """
Base
Base
""", is_file=True)
test(Cpp, "virtual.cpp", """
B
Base
""", is_file=True, extra_option=["-DVIRTUAL"])

main()