Skip to content

Commit

Permalink
Add support for more languages
Browse files Browse the repository at this point in the history
This adds support for C 11 (built with clang), as well as adding an
explicit Python 2 language. This is to ease the transition from Python 2
to Python 3.
  • Loading branch information
lhchavez committed Dec 8, 2019
1 parent bd5a8e8 commit 818bd8b
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 25 deletions.
9 changes: 7 additions & 2 deletions common/literalinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ type LiteralRun struct {

func validateLanguage(lang string) error {
switch lang {
case "c", "cpp", "cpp11", "kj", "kp", "java", "py", "pas", "rb", "cat":
case "c", "c11-gcc", "c11-clang", "cpp", "cpp11", "cpp17-gcc", "cpp17-clang", "kj", "kp", "java", "py", "py2", "py3", "pas", "rb", "cat":
return nil
default:
return fmt.Errorf("invalid language %q", lang)
Expand Down Expand Up @@ -186,8 +186,13 @@ func validateInterface(interfaceName string) error {

// LanguageFileExtension returns the file extension for a particular language.
func LanguageFileExtension(language string) string {
if language == "cpp11" {
switch language {
case "cpp11", "cpp11-gcc", "cpp11-clang", "cpp17-gcc", "cpp17-clang":
return "cpp"
case "c", "c11-gcc", "c11-clang":
return "c"
case "py", "py2", "py3":
return "py"
}
return language
}
Expand Down
16 changes: 9 additions & 7 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ func extraParentFlags(language string) []string {
return []string{}
}

func targetName(language string, target string) string {
if language == "py" || language == "py2" || language == "py3" || language == "java" {
return fmt.Sprintf("%s_entry", target)
}
return target
}

func normalizedSourceFiles(
runRoot string,
lang string,
Expand Down Expand Up @@ -451,13 +458,11 @@ func Grade(
if interactive != nil {
ctx.Log.Info("libinteractive", "version", interactive.LibinteractiveVersion)
lang := interactive.ParentLang
target := interactive.Main
target := targetName(run.Language, interactive.Main)

if lang == "cpp" {
// Let's not make problemsetters be forced to use old languages.
lang = "cpp11"
} else if run.Language == "py" || run.Language == "java" {
target = fmt.Sprintf("%s_entry", target)
}

binaries = []*binary{
Expand Down Expand Up @@ -491,10 +496,7 @@ func Grade(
runResult.CompileError = &compileError
return runResult, nil
}
target := name
if run.Language == "py" || run.Language == "java" {
target = fmt.Sprintf("%s_entry", target)
}
target := targetName(run.Language, name)
binaries = append(
binaries,
&binary{
Expand Down
215 changes: 199 additions & 16 deletions runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func runGraderTests(t *testing.T, wrapper sandboxWrapper) {

runtests := []runnerTestCase{
{
"py",
"py2",
"print sum(map(int, raw_input().strip().split()))",
big.NewRat(1, 1),
"AC",
Expand All @@ -221,10 +221,23 @@ func runGraderTests(t *testing.T, wrapper sandboxWrapper) {
},
},
{
"py",
"ans = sum(map(int, raw_input().strip().split()))\n" +
"py3",
"print(sum(map(int, input().strip().split())))",
big.NewRat(1, 1),
"AC",
big.NewRat(1, 1),
expectedResult{"", "", &RunMetadata{Verdict: "OK"}},
map[string]expectedResult{
"0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1.0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1.1": {"5", "", &RunMetadata{Verdict: "OK"}},
},
},
{
"py3",
"ans = sum(map(int, input().strip().split()))\n" +
"assert ans <= 3\n" +
"print ans",
"print(ans)",
big.NewRat(1, 1),
"RTE",
big.NewRat(1, 4),
Expand All @@ -236,8 +249,8 @@ func runGraderTests(t *testing.T, wrapper sandboxWrapper) {
},
},
{
"py",
"print 3",
"py3",
"print(3)",
big.NewRat(1, 1),
"PA",
big.NewRat(1, 4),
Expand All @@ -249,8 +262,8 @@ func runGraderTests(t *testing.T, wrapper sandboxWrapper) {
},
},
{
"py",
"print 2",
"py3",
"print(2)",
big.NewRat(1, 1),
"WA",
big.NewRat(0, 1),
Expand All @@ -262,7 +275,7 @@ func runGraderTests(t *testing.T, wrapper sandboxWrapper) {
},
},
{
"py",
"py3",
"if",
big.NewRat(1, 1),
"CE",
Expand All @@ -278,7 +291,7 @@ func runGraderTests(t *testing.T, wrapper sandboxWrapper) {
map[string]expectedResult{},
},
{
"c",
"c11-gcc",
"#include <stdio.h>\nint main() { printf(\"3\\n\"); }",
big.NewRat(1, 1),
"PA",
Expand All @@ -291,7 +304,33 @@ func runGraderTests(t *testing.T, wrapper sandboxWrapper) {
},
},
{
"cpp",
"c11-clang",
"#include <stdio.h>\nint main() { printf(\"3\\n\"); }",
big.NewRat(1, 1),
"PA",
big.NewRat(1, 4),
expectedResult{"", "", &RunMetadata{Verdict: "OK"}},
map[string]expectedResult{
"0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1.0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1.1": {"3", "", &RunMetadata{Verdict: "OK"}},
},
},
{
"cpp17-gcc",
"#include <iostream>\nint main() { std::cout << \"3\\n\"; }",
big.NewRat(1, 1),
"PA",
big.NewRat(1, 4),
expectedResult{"", "", &RunMetadata{Verdict: "OK"}},
map[string]expectedResult{
"0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1.0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1.1": {"3", "", &RunMetadata{Verdict: "OK"}},
},
},
{
"cpp17-clang",
"#include <iostream>\nint main() { std::cout << \"3\\n\"; }",
big.NewRat(1, 1),
"PA",
Expand Down Expand Up @@ -604,7 +643,7 @@ func TestGradeLowMemOmegajail(t *testing.T) {

runtests := []runnerTestCase{
{
"c",
"c11-gcc",
"#include <stdio.h>\nint main() { printf(\"3\\n\"); }",
big.NewRat(1, 1),
"PA",
Expand All @@ -617,7 +656,7 @@ func TestGradeLowMemOmegajail(t *testing.T) {
},
},
{
"cpp",
"cpp17-gcc",
"#include <iostream>\nint main() { std::cout << \"3\\n\"; }",
big.NewRat(1, 1),
"PA",
Expand Down Expand Up @@ -888,7 +927,7 @@ func TestLibinteractive(t *testing.T) {
`,
},
ModuleName: "AplusB",
ParentLang: "cpp",
ParentLang: "cpp17-gcc",
},
},
ctx.Config.Runner.RuntimePath,
Expand All @@ -907,7 +946,7 @@ func TestLibinteractive(t *testing.T) {

runtests := []runnerTestCase{
{
"cpp",
"cpp17-gcc",
`
#include <iostream>
using namespace std;
Expand All @@ -932,7 +971,7 @@ func TestLibinteractive(t *testing.T) {
map[string]expectedResult{},
},
{
"cpp11",
"cpp17-clang",
`
#include "AplusB.h"
int sum(int A, int B) {
Expand All @@ -951,6 +990,66 @@ func TestLibinteractive(t *testing.T) {
"1": {"-1", "", &RunMetadata{Verdict: "OK"}},
},
},
{
"c",
`
#include "AplusB.h"
int sum(int A, int B) {
return A + B;
}
int identity(int x) {
return x;
}
`,
big.NewRat(1, 1),
"AC",
big.NewRat(1, 1),
expectedResult{"", "", &RunMetadata{Verdict: "OK"}},
map[string]expectedResult{
"0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1": {"5", "", &RunMetadata{Verdict: "OK"}},
},
},
{
"c11-gcc",
`
#include "AplusB.h"
int sum(int A, int B) {
return A + B;
}
int identity(int x) {
return x;
}
`,
big.NewRat(1, 1),
"AC",
big.NewRat(1, 1),
expectedResult{"", "", &RunMetadata{Verdict: "OK"}},
map[string]expectedResult{
"0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1": {"5", "", &RunMetadata{Verdict: "OK"}},
},
},
{
"c11-clang",
`
#include "AplusB.h"
int sum(int A, int B) {
return A + B;
}
int identity(int x) {
return x;
}
`,
big.NewRat(1, 1),
"AC",
big.NewRat(1, 1),
expectedResult{"", "", &RunMetadata{Verdict: "OK"}},
map[string]expectedResult{
"0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1": {"5", "", &RunMetadata{Verdict: "OK"}},
},
},
{
"cpp",
`
Expand All @@ -971,6 +1070,66 @@ func TestLibinteractive(t *testing.T) {
"1": {"5", "", &RunMetadata{Verdict: "OK"}},
},
},
{
"cpp11",
`
#include "AplusB.h"
int sum(int A, int B) {
return A + B;
}
int identity(int x) {
return x;
}
`,
big.NewRat(1, 1),
"AC",
big.NewRat(1, 1),
expectedResult{"", "", &RunMetadata{Verdict: "OK"}},
map[string]expectedResult{
"0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1": {"5", "", &RunMetadata{Verdict: "OK"}},
},
},
{
"cpp17-gcc",
`
#include "AplusB.h"
int sum(int A, int B) {
return A + B;
}
int identity(int x) {
return x;
}
`,
big.NewRat(1, 1),
"AC",
big.NewRat(1, 1),
expectedResult{"", "", &RunMetadata{Verdict: "OK"}},
map[string]expectedResult{
"0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1": {"5", "", &RunMetadata{Verdict: "OK"}},
},
},
{
"cpp17-clang",
`
#include "AplusB.h"
int sum(int A, int B) {
return A + B;
}
int identity(int x) {
return x;
}
`,
big.NewRat(1, 1),
"AC",
big.NewRat(1, 1),
expectedResult{"", "", &RunMetadata{Verdict: "OK"}},
map[string]expectedResult{
"0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1": {"5", "", &RunMetadata{Verdict: "OK"}},
},
},
{
"java",
`
Expand Down Expand Up @@ -1006,6 +1165,30 @@ func TestLibinteractive(t *testing.T) {
"1": {"5", "", &RunMetadata{Verdict: "OK"}},
},
},
{
"py2",
"def sum(A, B):\n return A + B\ndef identity(x):\n return x",
big.NewRat(1, 1),
"AC",
big.NewRat(1, 1),
expectedResult{"", "", &RunMetadata{Verdict: "OK"}},
map[string]expectedResult{
"0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1": {"5", "", &RunMetadata{Verdict: "OK"}},
},
},
{
"py3",
"def sum(A, B):\n return A + B\ndef identity(x):\n return x",
big.NewRat(1, 1),
"AC",
big.NewRat(1, 1),
expectedResult{"", "", &RunMetadata{Verdict: "OK"}},
map[string]expectedResult{
"0": {"3", "", &RunMetadata{Verdict: "OK"}},
"1": {"5", "", &RunMetadata{Verdict: "OK"}},
},
},
}
for idx, rte := range runtests {
t.Run(fmt.Sprintf("%d/%s %s", idx, rte.language, rte.expectedVerdict), func(t *testing.T) {
Expand Down

0 comments on commit 818bd8b

Please sign in to comment.