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

構文エラー発生時のエラーメッセージを表示するように改善 #853

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions example/Abnormals/BuildFailure02/kgenprog.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root-dir = "./"
src = ["src/example/CloseToZero.java"]
test = ["src/example/CloseToZeroTest.java"]

15 changes: 15 additions & 0 deletions example/Abnormals/BuildFailure02/src/example/CloseToZero.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package example;

public class CloseToZero {

public int close_to_zero(int n) {
if (n == 0) {
n++ // build failure
} else if (n > 0) {
n--;
} else {
n++;
}
return n;
}
}
26 changes: 26 additions & 0 deletions example/Abnormals/BuildFailure02/src/example/CloseToZeroTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package example;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class CloseToZeroTest {
@Test
public void test01() {
assertEquals(9, new CloseToZero().close_to_zero(10));
}

@Test
public void test02() {
assertEquals(99, new CloseToZero().close_to_zero(100));
}

@Test
public void test03() {
assertEquals(0, new CloseToZero().close_to_zero(0));
}

@Test
public void test04() {
assertEquals(-9, new CloseToZero().close_to_zero(-10));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import java.util.function.Function;

import io.reactivex.Single;
import jp.kusumotolab.kgenprog.Configuration;
import jp.kusumotolab.kgenprog.OrdinalNumber;
Expand All @@ -18,7 +19,9 @@
import jp.kusumotolab.kgenprog.ga.validation.SourceCodeValidation.Input;
import jp.kusumotolab.kgenprog.project.GeneratedSourceCode;
import jp.kusumotolab.kgenprog.project.test.EmptyTestResults;
import jp.kusumotolab.kgenprog.project.test.TestResult;
import jp.kusumotolab.kgenprog.project.test.TestResults;
import org.junit.Test;

/**
* kGenProg が生成する Variant を生成したり保持したりするクラス
Expand Down Expand Up @@ -225,9 +228,14 @@ private Variant createVariant(final Gene gene, final GeneratedSourceCode sourceC
.cast(Variant.class)
.cache();

// ASTはあるがビルド&テスト実行がまだされていない場合 -> ビルド&テスト実行をする
// 以前生成したのと同じソースコードが生成された場合 -> その旨のメッセージを返す
// 上記以外の場合 -> 構文エラーが発生した登見なしてメッセージを返す
final Single<TestResults> resultsSingle =
sourceCode.shouldBeTested() ? strategies.execAsyncTestExecutor(variantSingle)
.cache() : Single.just(new EmptyTestResults("build failed or reproduced."));
.cache() : Single.just(new EmptyTestResults(
sourceCode.isReproducedSourceCode() ? "reproduced."
: sourceCode.getGenerationMessage()));
variant.setTestResultsSingle(resultsSingle);

final Single<Fitness> fitnessSingle = Single
Expand Down
13 changes: 11 additions & 2 deletions src/test/java/jp/kusumotolab/kgenprog/KGenProgMainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,23 @@ public void testQuickSort01() {


@Test
public void testBuildFailure() {
final Path rootPath = Paths.get("example/Abnormals/BuildFailure");
public void testBuildFailure01() {
final Path rootPath = Paths.get("example/Abnormals/BuildFailure01");
final Path productPath = rootPath.resolve(PRODUCT_NAME);
final Path testPath = rootPath.resolve(TEST_NAME);

final ExitStatus status = runKGenProgMain(rootPath, productPath, testPath);
assertThat(status).isEqualTo(ExitStatus.FAILURE_INITIAL_BUILD);
}

@Test
public void testBuildFailure02() {
final Path rootPath = Paths.get("example/Abnormals/BuildFailure02");
final Path productPath = rootPath.resolve(PRODUCT_NAME);
final Path testPath = rootPath.resolve(TEST_NAME);

final ExitStatus status = runKGenProgMain(rootPath, productPath, testPath);
assertThat(status).isEqualTo(ExitStatus.FAILURE_INITIAL_BUILD);
}

@Test
Expand Down