diff --git a/tests/test_nitc.nit b/tests/test_nitc.nit index e80379b..a2c8bb7 100644 --- a/tests/test_nitc.nit +++ b/tests/test_nitc.nit @@ -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", "john.doe@unknown.ld", "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 diff --git a/tests/test_pep.nit b/tests/test_pep.nit index 5fa2420..3dd4479 100644 --- a/tests/test_pep.nit +++ b/tests/test_pep.nit @@ -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", "john.doe@unknown.ld", "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