Skip to content

Commit

Permalink
Refactor runner: Split into main and logger
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Jul 22, 2017
1 parent 89fc25c commit d42b744
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 95 deletions.
29 changes: 15 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ set(INCLUDE
include/tcframe/os/ExecutionResult.hpp
include/tcframe/os/ExecutionRequest.hpp
include/tcframe/os/OperatingSystem.hpp
include/tcframe/runner.hpp
include/tcframe/runner/Args.hpp
include/tcframe/runner/ArgsParser.hpp
include/tcframe/runner/Runner.hpp
include/tcframe/runner/RunnerLogger.hpp
include/tcframe/runner/SlugParser.hpp
include/tcframe/runner/logger.hpp
include/tcframe/runner/logger/RunnerLogger.hpp
include/tcframe/runner/main.hpp
include/tcframe/runner/main/Args.hpp
include/tcframe/runner/main/ArgsParser.hpp
include/tcframe/runner/main/RunnerMain.hpp
include/tcframe/runner/main/SlugParser.hpp
include/tcframe/spec.hpp
include/tcframe/spec/constraint.hpp
include/tcframe/spec/constraint/Constraint.hpp
Expand Down Expand Up @@ -186,14 +187,14 @@ set(TEST_UNIT
test/unit/tcframe/logger/MockLoggerEngine.hpp
test/unit/tcframe/logger/SimpleLoggerEngineTests.cpp
test/unit/tcframe/os/MockOperatingSystem.hpp
test/unit/tcframe/runner/ArgsParserTests.cpp
test/unit/tcframe/runner/BatchRunnerTests.cpp
test/unit/tcframe/runner/BaseRunnerTests.hpp
test/unit/tcframe/runner/InteractiveRunnerTests.cpp
test/unit/tcframe/runner/MockRunnerLogger.hpp
test/unit/tcframe/runner/RunnerTests.cpp
test/unit/tcframe/runner/RunnerLoggerTests.cpp
test/unit/tcframe/runner/SlugParserTests.cpp
test/unit/tcframe/runner/logger/MockRunnerLogger.hpp
test/unit/tcframe/runner/logger/RunnerLoggerTests.cpp
test/unit/tcframe/runner/main/ArgsParserTests.cpp
test/unit/tcframe/runner/main/BatchRunnerMainTests.cpp
test/unit/tcframe/runner/main/BaseRunnerMainTests.hpp
test/unit/tcframe/runner/main/InteractiveRunnerMainTests.cpp
test/unit/tcframe/runner/main/RunnerMainTests.cpp
test/unit/tcframe/runner/main/SlugParserTests.cpp
test/unit/tcframe/spec/constraint/ConstraintSuiteTests.cpp
test/unit/tcframe/spec/constraint/ConstraintSuiteBuilderTests.cpp
test/unit/tcframe/spec/core/BaseTestSpecTests.cpp
Expand Down
6 changes: 0 additions & 6 deletions include/tcframe/runner.hpp

This file was deleted.

3 changes: 3 additions & 0 deletions include/tcframe/runner/logger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include "tcframe/runner/logger/RunnerLogger.hpp"
File renamed without changes.
6 changes: 6 additions & 0 deletions include/tcframe/runner/main.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "tcframe/runner/main/Args.hpp"
#include "tcframe/runner/main/ArgsParser.hpp"
#include "tcframe/runner/main/RunnerMain.hpp"
#include "tcframe/runner/main/SlugParser.hpp"
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

#include "Args.hpp"
#include "ArgsParser.hpp"
#include "RunnerLogger.hpp"
#include "SlugParser.hpp"
#include "tcframe/aggregator.hpp"
#include "tcframe/evaluator.hpp"
#include "tcframe/generator.hpp"
#include "tcframe/grader.hpp"
#include "tcframe/os.hpp"
#include "tcframe/runner/logger.hpp"
#include "tcframe/spec.hpp"
#include "tcframe/util.hpp"

Expand All @@ -28,7 +28,7 @@ struct RunnerDefaults {
};

template<typename TProblemSpec>
class Runner {
class RunnerMain {
private:
string specPath_;

Expand All @@ -45,7 +45,7 @@ class Runner {
AggregatorRegistry* aggregatorRegistry_;

public:
Runner(
RunnerMain(
const string& specPath,
BaseTestSpec<TProblemSpec>* testSpec,
LoggerEngine* loggerEngine,
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/tcframe/runner.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "tcframe/runner.hpp"
#include "tcframe/runner/main.hpp"

#include __TCFRAME_SPEC_FILE__

using tcframe::Runner;
using tcframe::RunnerMain;

int main(int argc, char* argv[]) {
Runner<ProblemSpec> runner(
RunnerMain<ProblemSpec> runner(
__TCFRAME_SPEC_FILE__,
new TestSpec(),
new SimpleLoggerEngine(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "gmock/gmock.h"

#include "tcframe/runner/RunnerLogger.hpp"
#include "tcframe/runner/logger/RunnerLogger.hpp"

namespace tcframe {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "gmock/gmock.h"
#include "../mock.hpp"
#include "../../mock.hpp"

#include "../logger/MockLoggerEngine.hpp"
#include "tcframe/runner/RunnerLogger.hpp"
#include "../../logger/MockLoggerEngine.hpp"
#include "tcframe/runner/logger/RunnerLogger.hpp"

using ::testing::InSequence;
using ::testing::Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "gmock/gmock.h"

#include "tcframe/runner/ArgsParser.hpp"
#include "tcframe/runner/main/ArgsParser.hpp"

using ::testing::Eq;
using ::testing::StrEq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include "gmock/gmock.h"
#include "../mock.hpp"
#include "../../mock.hpp"

#include "../aggregator/MockAggregator.hpp"
#include "../aggregator/MockAggregatorRegistry.hpp"
#include "../evaluator/MockEvaluator.hpp"
#include "../evaluator/MockEvaluatorRegistry.hpp"
#include "../generator/MockGenerator.hpp"
#include "../grader/MockGrader.hpp"
#include "../grader/MockGraderLogger.hpp"
#include "../grader/MockGraderLoggerFactory.hpp"
#include "../os/MockOperatingSystem.hpp"
#include "MockRunnerLogger.hpp"
#include "tcframe/runner/Runner.hpp"
#include "../../aggregator/MockAggregator.hpp"
#include "../../aggregator/MockAggregatorRegistry.hpp"
#include "../../evaluator/MockEvaluator.hpp"
#include "../../evaluator/MockEvaluatorRegistry.hpp"
#include "../../generator/MockGenerator.hpp"
#include "../../grader/MockGrader.hpp"
#include "../../grader/MockGraderLogger.hpp"
#include "../../grader/MockGraderLoggerFactory.hpp"
#include "../../os/MockOperatingSystem.hpp"
#include "../logger/MockRunnerLogger.hpp"
#include "tcframe/runner/main/RunnerMain.hpp"

using ::testing::_;
using ::testing::Eq;
Expand All @@ -23,7 +23,7 @@ using ::testing::Truly;

namespace tcframe {

class BaseRunnerTests : public Test {
class BaseRunnerMainTests : public Test {
protected:
class ProblemSpec : public BaseProblemSpec {
protected:
Expand Down Expand Up @@ -63,8 +63,8 @@ class BaseRunnerTests : public Test {
}

template<typename TProblem>
Runner<TProblem> createRunner(BaseTestSpec<TProblem>* testSpec) {
return Runner<TProblem>(
RunnerMain<TProblem> createRunner(BaseTestSpec<TProblem>* testSpec) {
return RunnerMain<TProblem>(
specPath, testSpec, loggerEngine, &os,&runnerLoggerFactory, &graderLoggerFactory,
&generatorFactory, &graderFactory, &evaluatorRegistry, &aggregatorRegistry);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "BaseRunnerTests.hpp"
#include "BaseRunnerMainTests.hpp"

namespace tcframe {

class BatchRunnerTests : public BaseRunnerTests {
class BatchRunnerMainTests : public BaseRunnerMainTests {
protected:
class BatchProblemSpec : public ProblemSpec {
protected:
Expand All @@ -22,39 +22,39 @@ class BatchRunnerTests : public BaseRunnerTests {
class BatchTestSpec : public BaseTestSpec<BatchProblemSpec> {};
class BatchWithCustomScorerTestSpec : public BaseTestSpec<BatchWithCustomScorerProblemSpec> {};

Runner<BatchProblemSpec> runner = createRunner(new BatchTestSpec());
Runner<BatchWithCustomScorerProblemSpec> runnerWithCustomScorer = createRunner(new BatchWithCustomScorerTestSpec());
RunnerMain<BatchProblemSpec> runner = createRunner(new BatchTestSpec());
RunnerMain<BatchWithCustomScorerProblemSpec> runnerWithCustomScorer = createRunner(new BatchWithCustomScorerTestSpec());
};

TEST_F(BatchRunnerTests, Run_Generation_EvaluatorRegistry_NoCustomScorer) {
TEST_F(BatchRunnerMainTests, Run_Generation_EvaluatorRegistry_NoCustomScorer) {
EXPECT_CALL(evaluatorRegistry, get(EvaluationStyle::BATCH, _, Truly(HelperKeyIs("scorer", ""))));
runner.run(argc, argv);
}

TEST_F(BatchRunnerTests, Run_Generation_EvaluatorRegistry_CustomScorer_Default) {
TEST_F(BatchRunnerMainTests, Run_Generation_EvaluatorRegistry_CustomScorer_Default) {
EXPECT_CALL(evaluatorRegistry,
get(EvaluationStyle::BATCH, _, Truly(HelperKeyIs("scorer", string(RunnerDefaults::SCORER_COMMAND)))));

runnerWithCustomScorer.run(argc, argv);
}

TEST_F(BatchRunnerTests, Run_Generation_EvaluatorRegistry_CustomScorer_Args) {
TEST_F(BatchRunnerMainTests, Run_Generation_EvaluatorRegistry_CustomScorer_Args) {
EXPECT_CALL(evaluatorRegistry, get(EvaluationStyle::BATCH, _, Truly(HelperKeyIs("scorer", "\"java Scorer\""))));
runnerWithCustomScorer.run(2, new char*[3]{
(char*) "./runner",
(char*) "--scorer=\"java Scorer\"",
nullptr});
}

TEST_F(BatchRunnerTests, Run_Grading_EvaluatorRegistry_NoCustomScorer) {
TEST_F(BatchRunnerMainTests, Run_Grading_EvaluatorRegistry_NoCustomScorer) {
EXPECT_CALL(evaluatorRegistry, get(EvaluationStyle::BATCH, _, Truly(HelperKeyIs("scorer", ""))));
runner.run(2, new char*[3]{
(char*) "./runner",
(char*) "grade",
nullptr});
}

TEST_F(BatchRunnerTests, Run_Grading_EvaluatorRegistry_CustomScorer_Default) {
TEST_F(BatchRunnerMainTests, Run_Grading_EvaluatorRegistry_CustomScorer_Default) {
EXPECT_CALL(evaluatorRegistry,
get(EvaluationStyle::BATCH, _, Truly(HelperKeyIs("scorer", string(RunnerDefaults::SCORER_COMMAND)))));

Expand All @@ -64,7 +64,7 @@ TEST_F(BatchRunnerTests, Run_Grading_EvaluatorRegistry_CustomScorer_Default) {
nullptr});
}

TEST_F(BatchRunnerTests, Run_Grading_EvaluatorRegistry_CustomScorer_Args) {
TEST_F(BatchRunnerMainTests, Run_Grading_EvaluatorRegistry_CustomScorer_Args) {
EXPECT_CALL(evaluatorRegistry, get(EvaluationStyle::BATCH, _, Truly(HelperKeyIs("scorer", "\"java Scorer\""))));
runnerWithCustomScorer.run(3, new char*[4]{
(char*) "./runner",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "BaseRunnerTests.hpp"
#include "BaseRunnerMainTests.hpp"

namespace tcframe {

class InteractiveRunnerTests : public BaseRunnerTests {
class InteractiveRunnerMainTests : public BaseRunnerMainTests {
protected:
class InteractiveProblemSpec : public ProblemSpec {
protected:
Expand All @@ -23,22 +23,22 @@ class InteractiveRunnerTests : public BaseRunnerTests {
class InteractiveWithRedundantNoOutputTestSpec :
public BaseTestSpec<InteractiveWithRedundantNoOutputProblemSpec> {};

Runner<InteractiveProblemSpec> runner = createRunner(new InteractiveTestSpec());
Runner<InteractiveWithRedundantNoOutputProblemSpec> runnerWithRedundantNoOutput =
RunnerMain<InteractiveProblemSpec> runner = createRunner(new InteractiveTestSpec());
RunnerMain<InteractiveWithRedundantNoOutputProblemSpec> runnerWithRedundantNoOutput =
createRunner(new InteractiveWithRedundantNoOutputTestSpec());
};

TEST_F(InteractiveRunnerTests, Run_Generation_NoOutput) {
TEST_F(InteractiveRunnerMainTests, Run_Generation_NoOutput) {
EXPECT_CALL(generator, generate(_, Property(&GenerationOptions::needsOutput, false)));
runner.run(argc, argv);
}

TEST_F(InteractiveRunnerTests, Run_Generation_NoOutput_Redundant) {
TEST_F(InteractiveRunnerMainTests, Run_Generation_NoOutput_Redundant) {
EXPECT_CALL(generator, generate(_, Property(&GenerationOptions::needsOutput, false)));
runnerWithRedundantNoOutput.run(argc, argv);
}

TEST_F(InteractiveRunnerTests, Run_Generation_EvaluatorRegistry_Communicator_Default) {
TEST_F(InteractiveRunnerMainTests, Run_Generation_EvaluatorRegistry_Communicator_Default) {
EXPECT_CALL(evaluatorRegistry, get(
EvaluationStyle::INTERACTIVE,
_,
Expand All @@ -47,7 +47,7 @@ TEST_F(InteractiveRunnerTests, Run_Generation_EvaluatorRegistry_Communicator_Def
runner.run(argc, argv);
}

TEST_F(InteractiveRunnerTests, Run_Generation_EvaluatorRegistry_Communicator_Args) {
TEST_F(InteractiveRunnerMainTests, Run_Generation_EvaluatorRegistry_Communicator_Args) {
EXPECT_CALL(evaluatorRegistry, get(
EvaluationStyle::INTERACTIVE,
_,
Expand All @@ -59,7 +59,7 @@ TEST_F(InteractiveRunnerTests, Run_Generation_EvaluatorRegistry_Communicator_Arg
nullptr});
}

TEST_F(InteractiveRunnerTests, Run_Grading_EvaluatorRegistry_Communicator_Default) {
TEST_F(InteractiveRunnerMainTests, Run_Grading_EvaluatorRegistry_Communicator_Default) {
EXPECT_CALL(evaluatorRegistry, get(
EvaluationStyle::INTERACTIVE,
_,
Expand All @@ -71,7 +71,7 @@ TEST_F(InteractiveRunnerTests, Run_Grading_EvaluatorRegistry_Communicator_Defaul
nullptr});
}

TEST_F(InteractiveRunnerTests, Run_Grading_EvaluatorRegistry_Communicator_Args) {
TEST_F(InteractiveRunnerMainTests, Run_Grading_EvaluatorRegistry_Communicator_Args) {
EXPECT_CALL(evaluatorRegistry, get(
EvaluationStyle::INTERACTIVE,
_,
Expand Down

0 comments on commit d42b744

Please sign in to comment.