Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executors: add version checks to self-tests #1109

Merged
merged 2 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dmoj/executors/C.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ class Executor(GCCExecutor):
test_program = """
#include <stdio.h>

#if __STDC_VERSION__ == 199901
int main() {
int ch;
while ((ch = getchar()) != EOF)
putchar(ch);
return 0;
}
#endif
"""
2 changes: 2 additions & 0 deletions dmoj/executors/C11.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ class Executor(GCCExecutor):
test_program = """
#include <stdio.h>

#if __STDC_VERSION__ == 201112
int main() {
int ch;
while ((ch = getchar()) != EOF)
putchar(ch);
return 0;
}
#endif
"""
4 changes: 2 additions & 2 deletions dmoj/executors/CLANGX.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dmoj.executors.CPP11 import Executor as CPP11Executor
from dmoj.executors.CPP14 import Executor as CPP14Executor
from dmoj.executors.clang_executor import ClangExecutor


class Executor(ClangExecutor, CPP11Executor):
class Executor(ClangExecutor, CPP14Executor):
command = 'clang++'
command_paths = ['clang++-%s' % i for i in ['3.9', '3.8', '3.7', '3.6', '3.5']] + ['clang++']
8 changes: 4 additions & 4 deletions dmoj/executors/CPP03.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from typing import Optional

from .gcc_executor import GCCExecutor


class Executor(GCCExecutor):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that the C++03 executor is used as a "cpp_executor" of sorts is pretty yucky; we should just make a dedicated one at some point.

command = 'g++'
std: Optional[str] = None
std: str = 'c++03'
ext = 'cpp'
test_program = """
#include <iostream>

#if __cplusplus >= 199711 && __cplusplus < 201103
int main() {
std::cout << std::cin.rdbuf();
return 0;
}
#endif
"""

def get_flags(self):
return (['-std=%s' % self.std] if self.std else []) + super().get_flags()
return ([f'-std={self.std}']) + super().get_flags()
2 changes: 2 additions & 0 deletions dmoj/executors/CPP11.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ class Executor(CPPExecutor):
test_program = """
#include <iostream>

#if __cplusplus == 201103
int main() {
auto input = std::cin.rdbuf();
std::cout << input;
return 0;
}
#endif
"""
2 changes: 2 additions & 0 deletions dmoj/executors/CPP14.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ class Executor(CPPExecutor):
return std::cin.rdbuf();
}

#if __cplusplus == 201402
int main() {
std::cout << input();
return 0;
}
#endif
"""
2 changes: 2 additions & 0 deletions dmoj/executors/CPP17.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ class Executor(CPPExecutor):
test_program = """
#include <iostream>

#if __cplusplus == 201703
int main() {
float literal = 0x3.ABCp-10;
auto input = std::cin.rdbuf();
std::cout << input;
return 0;
}
#endif
"""
2 changes: 2 additions & 0 deletions dmoj/executors/CPP20.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ class Executor(CPPExecutor):
test_program = """
#include <iostream>

#if __cplusplus == 202002
int main() {
std::strong_ordering comparison = 1 <=> 2;
auto input = std::cin.rdbuf();
std::cout << input;
return 0;
}
#endif
"""
6 changes: 5 additions & 1 deletion dmoj/executors/PY2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
class Executor(PythonExecutor):
command = 'python'
command_paths = ['python2.7', 'python2', 'python']
test_program = "print __import__('sys').stdin.read()"
test_program = """
import sys
if sys.version_info.major == 2:
print sys.stdin.read()
"""
6 changes: 5 additions & 1 deletion dmoj/executors/PY3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
class Executor(PythonExecutor):
command = 'python3'
command_paths = ['python%s' % i for i in ['3.6', '3.5', '3.4', '3.3', '3.2', '3.1', '3']]
test_program = "print(__import__('sys').stdin.read(), end='')"
test_program = """
import sys
if sys.version_info.major == 3:
print(sys.stdin.read(), end='')
"""
6 changes: 5 additions & 1 deletion dmoj/executors/PYPY.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

class Executor(PythonExecutor):
command = 'pypy'
test_program = "print __import__('sys').stdin.read()"
test_program = """
import sys
if sys.version_info.major == 2:
print sys.stdin.read()
"""
_pypy_versions: List[Tuple[int, ...]]

@classmethod
Expand Down
6 changes: 5 additions & 1 deletion dmoj/executors/PYPY3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@

class Executor(PYPYExecutor):
command = 'pypy3'
test_program = "print(__import__('sys').stdin.read(), end='')"
test_program = """
import sys
if sys.version_info.major == 3:
print(sys.stdin.read(), end='')
"""