Navigation Menu

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

Fix mutation analysis of generated tests for Mockito (addresses issue #308) #315

Merged
merged 3 commits into from Mar 24, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions framework/core/Constants.pm
Expand Up @@ -48,7 +48,7 @@ our @ISA = qw(Exporter);
my $dir = dirname(abs_path(__FILE__));

# Enable debugging and verbose output
our $DEBUG = 0;
our $DEBUG = $ENV{'D4J_DEBUG'} // 0;

=pod

Expand Down Expand Up @@ -232,8 +232,6 @@ unshift(@INC, $SCRIPT_DIR);
unshift(@INC, $LIB_DIR);
# Append Major's executables to the PATH -> ant may not be installed by default
$ENV{PATH}="$ENV{PATH}:$MAJOR_ROOT/bin";
# set name of mml file that provides definitions of used mutation operators
$ENV{MML}="$MAJOR_ROOT/mml/all_mutants.mml.bin" unless defined $ENV{'MML'};

# Constant strings used for errors
our $ARG_ERROR = "Invalid number of arguments!";
Expand Down
13 changes: 11 additions & 2 deletions framework/core/Project.pm
Expand Up @@ -767,7 +767,11 @@ sub mutate {
$ENV{MML} = $mml_bin;

# Mutate and compile sources
if (! $self->_call_major("mutate")) {
my $ret = $self->_call_major("mutate");

delete($ENV{MML});

if (! $ret) {
return -1;
}

Expand Down Expand Up @@ -1031,9 +1035,14 @@ sub _call_major {
@_ >= 2 or die $ARG_ERROR;
my ($self, $target, $option_str, $log_file, $ant_cmd) = @_;
$option_str = "-Dbuild.compiler=major.ant.MajorCompiler " . ($option_str // "");
# Prepend path with Major's executables
my $path = $ENV{PATH};
$ENV{PATH}="$MAJOR_ROOT/bin:$ENV{PATH}";
$ant_cmd = "$MAJOR_ROOT/bin/ant" unless defined $ant_cmd;
return $self->_ant_call($target, $option_str, $log_file, $ant_cmd);
my $ret = $self->_ant_call($target, $option_str, $log_file, $ant_cmd);
# Reset path for downstream calls to ant
$ENV{PATH} = $path;
return($ret);
}

#
Expand Down
16 changes: 9 additions & 7 deletions framework/projects/defects4j.build.xml
Expand Up @@ -60,6 +60,8 @@ project-specific build file ("project_id"/"project_id".build.xml) for the

<!-- Location of customized JUnit formatter-->
<property name="formatter.jar" value="${d4j.home}/framework/lib/formatter.jar"/>
<!-- Directory of compiled test-gen classes -->
<property name="d4j.dir.classes.testgen" value="${d4j.workdir}/.classes_testgen"/>
<!-- Directory of instrumented classes (e.g., for coverage analysis)-->
<property name="d4j.dir.classes.instrumented" value="${d4j.workdir}/.classes_instrumented"/>
<!-- Directory of mutated classes-->
Expand Down Expand Up @@ -143,7 +145,7 @@ project-specific build file ("project_id"/"project_id".build.xml) for the
<classpath>
<pathelement path="${formatter.jar}" />
<pathelement path="${junit.jar}" />
<pathelement path="${build.home}/gen-tests" />
<pathelement path="${d4j.dir.classes.testgen}" />
<path refid="d4j.test.classpath"/>
<!-- Add dependencies to runtime libraries of test generation tools -->
<path refid="d4j.lib.testgen.rt"/>
Expand Down Expand Up @@ -184,7 +186,7 @@ project-specific build file ("project_id"/"project_id".build.xml) for the
<!--
Run mutation analysis
-->
<target name="mutation.test" depends="compile.tests,update.all.tests" description="Perform mutation analysis">
<target name="mutation.test" depends="update.all.tests" description="Perform mutation analysis">
<!-- Test a generated test suite -->
<if><isset property="d4j.test.include"/>
<then>
Expand Down Expand Up @@ -229,7 +231,7 @@ project-specific build file ("project_id"/"project_id".build.xml) for the

<classpath>
<pathelement location="${d4j.dir.classes.mutated}" />
<pathelement path="${build.home}/gen-tests" />
<pathelement path="${d4j.dir.classes.testgen}" />
<path refid="d4j.test.classpath"/>
<!-- Add dependencies to runtime libraries of test generation tools -->
<path refid="d4j.lib.testgen.rt"/>
Expand All @@ -254,10 +256,10 @@ project-specific build file ("project_id"/"project_id".build.xml) for the
<echo message="classes.dir: ${classes.dir}" />
<echo message="build.home: ${build.home}" />

<delete dir="${build.home}/gen-tests" quiet="true" />
<mkdir dir="${build.home}/gen-tests" />
<delete dir="${d4j.dir.classes.testgen}" quiet="true" />
<mkdir dir="${d4j.dir.classes.testgen}" />
<javac srcdir="${d4j.test.dir}"
destdir="${build.home}/gen-tests"
destdir="${d4j.dir.classes.testgen}"
debug="true"
deprecation="false"
optimize="false">
Expand Down Expand Up @@ -288,7 +290,7 @@ project-specific build file ("project_id"/"project_id".build.xml) for the
<!-- Make sure that instrumented classes appear at the beginning of the
classpath -->
<pathelement location="${d4j.dir.classes.instrumented}" />
<pathelement path="${build.home}/gen-tests" />
<pathelement path="${d4j.dir.classes.testgen}" />
<pathelement path="${formatter.jar}" />
<pathelement path="${junit.jar}" />
<pathelement path="${classes.dir}" />
Expand Down