Skip to content

Commit

Permalink
tests: Fix config utilisation for SQL compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Bajolet <[email protected]>
  • Loading branch information
lbajolet committed Nov 1, 2016
1 parent 5fdef56 commit 8dc6474
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 102 deletions.
86 changes: 45 additions & 41 deletions tests/test_nitc.nit
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,56 @@ var opts = new AppOptions.from_args(args)
var config = new AppConfig.from_options(opts)

# clean bd
config.db.drop
#config.db.drop

# Load nit
config.load_track("tracks/nit")
#config.load_track("tracks/nit")

# Create a dummy user
var player = new Player("John", "Doe")
config.players.save player
with ctx = new DBContext do
# Create a dummy user
var player = new Player(ctx, "nit_doe", "Nit Doe", "[email protected]", "avatar.cx")
player.commit

# Run some submission on the missions
var mission = config.missions.find_all.first

print "Mission {mission} {mission.testsuite.length}"
var i = 0
for source in [
"""
""",
"""
echo Hello, World!
""",
"""
print "hello world"
""",
"""
class Hello
fun hi: String do return "Hello, World!"
end
print((new Hello).hi)
""",
"""
print "Hello, World!"
"""
] do
print "## Try source {i} ##"
var prog = new Submission(player, mission, source)
var runner = config.engine_map["nitc"]
runner.run(prog, config)
print "** {prog.status} errors={prog.test_errors}/{prog.results.length} size={prog.size_score or else "-"} time={prog.time_score or else "-"}"
var msg = prog.compilation.message
if msg != null then print "{msg}"
for res in prog.results do
var msg_test = res.error
if msg_test != null then print "test {res.testcase.number}: {msg_test}"
# Run some submission on the missions
var mission = ctx.mission_by_slug("nit:hello_world")
if mission == null then return

print "Mission {mission} {mission.testsuite.length}"
var i = 0
for source in [
"""
""",
"""
echo Hello, World!
""",
"""
print "hello world"
""",
"""
class Hello
fun hi: String do return "Hello, World!"
end
for e in prog.star_results do
print e
print((new Hello).hi)
""",
"""
print "Hello, World!"
"""
] do
print "## Try source {i} ##"
var prog = new Submission(ctx, player.id, mission.id, source)
var runner = config.engine_map["nitc"]
runner.run(prog)
print "** {prog.status} errors={prog.test_errors}/{prog.results.length} size={prog.size_score or else "-"} time={prog.time_score or else "-"}"
var msg = prog.compilation.message
if msg != null then print "{msg}"
for res in prog.results do
var msg_test = res.error
if msg_test != null then print "test {res.testcase.number}: {msg_test}"
end
for e in prog.star_results do
print e
end
i += 1
end
i += 1
end
125 changes: 64 additions & 61 deletions tests/test_pep.nit
Original file line number Diff line number Diff line change
Expand Up @@ -12,71 +12,74 @@ var opts = new AppOptions.from_args(args)
var config = new AppConfig.from_options(opts)

# clean bd
config.db.drop
#config.db.drop

# Load pep8
config.load_track("tracks/pep8")
#config.load_track("tracks/pep8")

# Create a dummy user
var player = new Player("John", "Doe")
config.players.save player
with ctx = new DBContext do
# Create a dummy user
var player = new Player(ctx, "pep_doe", "Pep Doe", "[email protected]", "avatar.cx")
player.commit

# Run some submission on the missions
var mission = config.missions.find_all.first
do
print "Mission {mission} {mission.testsuite.length}"
var i = 0
for source in [
"""
""",
"""
DECO 10,i
.END
""",
"""
DECI n,d
LDA n,d
ADDA 10,i
STA n,d
DECO n,d
STOP
n: .BLOCK 3
.END
""",
"""
DECI n,d
LDA n,d
ADDA 10,i
STA n,d
DECO n,d
STOP
n: .BLOCK 2
.END
""",
"""
DECI 0,d
LDA 0,d
ADDA 10,i
STA 0,d
DECO 0,d
STOP
.END
"""
] do
print "## Try source {i} ##"
var sub = new Submission(player, mission, source)
var runner = config.engine_map["pep8term"]
runner.run(sub, config)
print "** {sub.status} errors={sub.test_errors}/{sub.results.length} size={sub.size_score or else "-"} time={sub.time_score or else "-"}"
var msg = sub.compilation.message
if msg != null then print "{msg}"
for res in sub.results do
var msg_test = res.error
if msg_test != null then print "test {res.testcase.number}. {msg_test}"
# Run some submission on the missions
var mission = ctx.mission_by_slug("pep8:addition_simple")
if mission == null then return
do
print "Mission {mission} {mission.testsuite.length}"
var i = 0
for source in [
"""
""",
"""
DECO 10,i
.END
""",
"""
DECI n,d
LDA n,d
ADDA 10,i
STA n,d
DECO n,d
STOP
n: .BLOCK 3
.END
""",
"""
DECI n,d
LDA n,d
ADDA 10,i
STA n,d
DECO n,d
STOP
n: .BLOCK 2
.END
""",
"""
DECI 0,d
LDA 0,d
ADDA 10,i
STA 0,d
DECO 0,d
STOP
.END
"""
] do
print "## Try source {i} ##"
var sub = new Submission(ctx, player.id, mission.id, source)
var runner = config.engine_map["pep8term"]
runner.run(sub)
print "** {sub.status} errors={sub.test_errors}/{sub.results.length} size={sub.size_score or else "-"} time={sub.time_score or else "-"}"
var msg = sub.compilation.message
if msg != null then print "{msg}"
for res in sub.results do
var msg_test = res.error
if msg_test != null then print "test {res.testcase.number}. {msg_test}"
end
for e in sub.star_results do
print e
end
i += 1
end
for e in sub.star_results do
print e
end
i += 1
end
end

0 comments on commit 8dc6474

Please sign in to comment.