Skip to content

Commit

Permalink
Migrate most of the assertions to Truth that the auto-migration tool …
Browse files Browse the repository at this point in the history
…did not catch.

IntelliJ's "replace structurally" command was surprisingly useful.

RELNOTES: None.
PiperOrigin-RevId: 157463734
  • Loading branch information
lberki authored and laszlocsomor committed May 31, 2017
1 parent a1fb6f2 commit 78cfa8d
Show file tree
Hide file tree
Showing 35 changed files with 625 additions and 659 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.android.DensitySpecificManifestProcessor.PLAY_STORE_SUPPORTED_DENSITIES;
import static com.google.devtools.build.android.DensitySpecificManifestProcessor.SCREEN_SIZES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import com.google.common.base.Joiner;
Expand Down Expand Up @@ -58,7 +56,7 @@ public class DensitySpecificManifestProcessorTest {
"</manifest>");
Path modified = new DensitySpecificManifestProcessor(ImmutableList.<String>of(),
tmp.resolve("manifest-filtered/AndroidManifest.xml")).process(manifest);
assertEquals(manifest, modified);
assertThat((Object) modified).isEqualTo(manifest);
}

@Test public void testSingleDensity() throws Exception {
Expand All @@ -69,7 +67,7 @@ public class DensitySpecificManifestProcessorTest {
"</manifest>");
Path modified = new DensitySpecificManifestProcessor(densities,
tmp.resolve("manifest-filtered/AndroidManifest.xml")).process(manifest);
assertNotNull(modified);
assertThat((Object) modified).isNotNull();
checkModification(modified, densities);
}

Expand All @@ -81,7 +79,7 @@ public class DensitySpecificManifestProcessorTest {
"</manifest>");
Path modified = new DensitySpecificManifestProcessor(densities,
tmp.resolve("manifest-filtered/AndroidManifest.xml")).process(manifest);
assertNotNull(modified);
assertThat((Object) modified).isNotNull();
checkModification(modified, densities);
}

Expand All @@ -93,7 +91,7 @@ public class DensitySpecificManifestProcessorTest {
"</manifest>");
Path modified = new DensitySpecificManifestProcessor(densities,
tmp.resolve("manifest-filtered/AndroidManifest.xml")).process(manifest);
assertNotNull(modified);
assertThat((Object) modified).isNotNull();
checkModification(modified, densities);
}

Expand All @@ -105,7 +103,7 @@ public class DensitySpecificManifestProcessorTest {
"</manifest>");
Path modified = new DensitySpecificManifestProcessor(densities,
tmp.resolve("manifest-filtered/AndroidManifest.xml")).process(manifest);
assertNotNull(modified);
assertThat((Object) modified).isNotNull();
checkCompatibleScreensOmitted(modified);
}

Expand All @@ -119,7 +117,7 @@ public class DensitySpecificManifestProcessorTest {
"</manifest>");
Path modified = new DensitySpecificManifestProcessor(densities,
tmp.resolve("manifest-filtered/AndroidManifest.xml")).process(manifest);
assertNotNull(modified);
assertThat((Object) modified).isNotNull();
checkModification(modified, densities);
}

Expand All @@ -141,7 +139,7 @@ public class DensitySpecificManifestProcessorTest {
"</manifest>");
Path modified = new DensitySpecificManifestProcessor(densities,
tmp.resolve("manifest-filtered/AndroidManifest.xml")).process(manifest);
assertNotNull(modified);
assertThat((Object) modified).isNotNull();
checkModification(modified, ImmutableList.<String>of("ldpi", "xxhdpi"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package com.google.devtools.build.lib.bazel.repository.cache;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;

import com.google.common.base.Strings;
import com.google.devtools.build.lib.bazel.repository.cache.RepositoryCache.KeyType;
Expand Down Expand Up @@ -117,7 +116,7 @@ public void testGetCacheValue() throws IOException {
.isEqualTo(FileSystemUtils.readContent(actualTargetPath, Charset.defaultCharset()));

// Check that the returned value is stored under outputBaseExternal.
assertEquals(targetPath, actualTargetPath);
assertThat((Object) actualTargetPath).isEqualTo(targetPath);
}

/**
Expand All @@ -129,7 +128,7 @@ public void testGetNullCacheValue() throws IOException {
Path targetPath = targetDirectory.getChild(downloadedFile.getBaseName());
Path actualTargetPath = repositoryCache.get(downloadedFileSha256, targetPath, KeyType.SHA256);

assertEquals(actualTargetPath, null);
assertThat(actualTargetPath).isNull();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.baseArtifactNames;
import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.baseNamesOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -114,15 +112,16 @@ public void testEmptyLibrary() throws Exception {
// But we avoid creating .so files for empty libraries,
// because those have a potentially significant run-time startup cost.
if (emptyShouldOutputStaticLibrary()) {
assertEquals("libemptylib.a", baseNamesOf(getFilesToBuild(emptylib)));
assertThat(baseNamesOf(getFilesToBuild(emptylib))).isEqualTo("libemptylib.a");
} else {
assertThat(getFilesToBuild(emptylib)).isEmpty();
}
assertTrue(
emptylib
.getProvider(CcExecutionDynamicLibrariesProvider.class)
.getExecutionDynamicLibraryArtifacts()
.isEmpty());
assertThat(
emptylib
.getProvider(CcExecutionDynamicLibrariesProvider.class)
.getExecutionDynamicLibraryArtifacts()
.isEmpty())
.isTrue();
}

protected boolean emptyShouldOutputStaticLibrary() {
Expand All @@ -132,8 +131,8 @@ protected boolean emptyShouldOutputStaticLibrary() {
@Test
public void testEmptyBinary() throws Exception {
ConfiguredTarget emptybin = getConfiguredTarget("//empty:emptybinary");
assertEquals(
"emptybinary" + OsUtils.executableExtension(), baseNamesOf(getFilesToBuild(emptybin)));
assertThat(baseNamesOf(getFilesToBuild(emptybin)))
.isEqualTo("emptybinary" + OsUtils.executableExtension());
}

private List<String> getCopts(String target) throws Exception {
Expand Down Expand Up @@ -229,11 +228,12 @@ public void testLinkStaticStatically() throws Exception {
"cc_library(name = 'statically',",
" srcs = ['statically.cc'],",
" linkstatic=1)");
assertTrue(
statically
.getProvider(CcExecutionDynamicLibrariesProvider.class)
.getExecutionDynamicLibraryArtifacts()
.isEmpty());
assertThat(
statically
.getProvider(CcExecutionDynamicLibrariesProvider.class)
.getExecutionDynamicLibraryArtifacts()
.isEmpty())
.isTrue();
Artifact staticallyDotA = getOnlyElement(getFilesToBuild(statically));
assertThat(getGeneratingAction(staticallyDotA)).isInstanceOf(CppLinkAction.class);
PathFragment dotAPath = staticallyDotA.getExecPath();
Expand Down Expand Up @@ -272,7 +272,8 @@ public void testStartEndLib() throws Exception {
CppLinkAction action = (CppLinkAction) getGeneratingAction(getExecutable(target));
for (Artifact input : action.getInputs()) {
String name = input.getFilename();
assertTrue(!CppFileTypes.ARCHIVE.matches(name) && !CppFileTypes.PIC_ARCHIVE.matches(name));
assertThat(!CppFileTypes.ARCHIVE.matches(name) && !CppFileTypes.PIC_ARCHIVE.matches(name))
.isTrue();
}
}

Expand Down Expand Up @@ -625,7 +626,7 @@ public void testExpandLabelInLinkoptsAgainstSrc() throws Exception {
// make sure the binary is dependent on the static lib
Action linkAction = getGeneratingAction(getOnlyElement(getFilesToBuild(theApp)));
ImmutableList<Artifact> filesToBuild = ImmutableList.copyOf(getFilesToBuild(theLib));
assertTrue(ImmutableSet.copyOf(linkAction.getInputs()).containsAll(filesToBuild));
assertThat(ImmutableSet.copyOf(linkAction.getInputs()).containsAll(filesToBuild)).isTrue();
}

@Test
Expand Down Expand Up @@ -699,8 +700,8 @@ public void testStampTests() throws Exception {
}

private void assertStamping(boolean enabled, String label) throws Exception {
assertEquals(
enabled, AnalysisUtils.isStampingEnabled(getRuleContext(getConfiguredTarget(label))));
assertThat(AnalysisUtils.isStampingEnabled(getRuleContext(getConfiguredTarget(label))))
.isEqualTo(enabled);
}

@Test
Expand Down Expand Up @@ -768,7 +769,7 @@ public void testSelectPreferredLibrariesInvariant() {
FileType.filterList(
LinkerInputs.toLibraryArtifacts(linkingOutputs.getPreferredLibraries(true, true)),
CppFileTypes.SHARED_LIBRARY);
assertEquals(sharedLibraries1, sharedLibraries2);
assertThat(sharedLibraries2).isEqualTo(sharedLibraries1);
}

/** Tests that shared libraries of the form "libfoo.so.1.2" are permitted within "srcs". */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.rules.cpp;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static com.google.common.truth.Truth.assertThat;

import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.util.CompileOnlyTestCase;
Expand Down Expand Up @@ -51,11 +50,11 @@ public void testCcCompileOnly() throws Exception {

ConfiguredTarget target = getConfiguredTarget("//package:foo");

assertNotNull(getArtifactByExecPathSuffix(target, "/foo.pic.o"));
assertNotNull(getArtifactByExecPathSuffix(target, "/bar.pic.o"));
assertThat(getArtifactByExecPathSuffix(target, "/foo.pic.o")).isNotNull();
assertThat(getArtifactByExecPathSuffix(target, "/bar.pic.o")).isNotNull();
// Check that deps are not built
assertNull(getArtifactByExecPathSuffix(target, "/foolib.pic.o"));
assertThat(getArtifactByExecPathSuffix(target, "/foolib.pic.o")).isNull();
// Check that linking is not executed
assertNull(getArtifactByExecPathSuffix(target, "/foo"));
assertThat(getArtifactByExecPathSuffix(target, "/foo")).isNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@

import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.FailAction;
Expand Down Expand Up @@ -94,7 +88,7 @@ private CppModuleMapAction getCppModuleMapAction(String label) throws Exception

private void assertNoCppModuleMapAction(String label) throws Exception {
ConfiguredTarget target = getConfiguredTarget(label);
assertNull(target.getProvider(CppCompilationContext.class).getCppModuleMap());
assertThat(target.getProvider(CppCompilationContext.class).getCppModuleMap()).isNull();
}


Expand Down Expand Up @@ -181,8 +175,13 @@ public void testFilesToBuildWithInterfaceSharedObjects() throws Exception {
@Test
public void testEmptyLinkopts() throws Exception {
ConfiguredTarget hello = getConfiguredTarget("//hello:hello");
assertTrue(hello.getProvider(CcLinkParamsProvider.class)
.getCcLinkParams(false, false).getLinkopts().isEmpty());
assertThat(
hello
.getProvider(CcLinkParamsProvider.class)
.getCcLinkParams(false, false)
.getLinkopts()
.isEmpty())
.isTrue();
}

@Test
Expand Down Expand Up @@ -219,20 +218,21 @@ public void testCppLinkActionExtraActionInfoWithoutSharedLibraries() throws Exce

ExtraActionInfo.Builder builder = action.getExtraActionInfo();
ExtraActionInfo info = builder.build();
assertEquals("CppLink", info.getMnemonic());
assertThat(info.getMnemonic()).isEqualTo("CppLink");

CppLinkInfo cppLinkInfo = info.getExtension(CppLinkInfo.cppLinkInfo);
assertNotNull(cppLinkInfo);
assertThat(cppLinkInfo).isNotNull();

Iterable<String> inputs = Artifact.asExecPaths(
LinkerInputs.toLibraryArtifacts(action.getLinkCommandLine().getLinkerInputs()));
assertThat(cppLinkInfo.getInputFileList()).containsExactlyElementsIn(inputs);
assertEquals(action.getPrimaryOutput().getExecPathString(), cppLinkInfo.getOutputFile());
assertFalse(cppLinkInfo.hasInterfaceOutputFile());
assertEquals(action.getLinkCommandLine().getLinkTargetType().name(),
cppLinkInfo.getLinkTargetType());
assertEquals(action.getLinkCommandLine().getLinkStaticness().name(),
cppLinkInfo.getLinkStaticness());
assertThat(cppLinkInfo.getOutputFile())
.isEqualTo(action.getPrimaryOutput().getExecPathString());
assertThat(cppLinkInfo.hasInterfaceOutputFile()).isFalse();
assertThat(cppLinkInfo.getLinkTargetType())
.isEqualTo(action.getLinkCommandLine().getLinkTargetType().name());
assertThat(cppLinkInfo.getLinkStaticness())
.isEqualTo(action.getLinkCommandLine().getLinkStaticness().name());
Iterable<String> linkstamps = Artifact.asExecPaths(
action.getLinkCommandLine().getLinkstamps().values());
assertThat(cppLinkInfo.getLinkStampList()).containsExactlyElementsIn(linkstamps);
Expand All @@ -248,25 +248,26 @@ public void testCppLinkActionExtraActionInfoWithoutSharedLibraries() throws Exce
public void testCppLinkActionExtraActionInfoWithSharedLibraries() throws Exception {
useConfiguration("--cpu=k8");
ConfiguredTarget hello = getConfiguredTarget("//hello:hello");
Artifact sharedObject =
Artifact sharedObject =
FileType.filter(getFilesToBuild(hello), CppFileTypes.SHARED_LIBRARY).iterator().next();
CppLinkAction action = (CppLinkAction) getGeneratingAction(sharedObject);

ExtraActionInfo.Builder builder = action.getExtraActionInfo();
ExtraActionInfo info = builder.build();
assertEquals("CppLink", info.getMnemonic());
assertThat(info.getMnemonic()).isEqualTo("CppLink");

CppLinkInfo cppLinkInfo = info.getExtension(CppLinkInfo.cppLinkInfo);
assertNotNull(cppLinkInfo);
assertThat(cppLinkInfo).isNotNull();

Iterable<String> inputs = Artifact.asExecPaths(
LinkerInputs.toLibraryArtifacts(action.getLinkCommandLine().getLinkerInputs()));
assertThat(cppLinkInfo.getInputFileList()).containsExactlyElementsIn(inputs);
assertEquals(action.getPrimaryOutput().getExecPathString(), cppLinkInfo.getOutputFile());
assertEquals(action.getLinkCommandLine().getLinkTargetType().name(),
cppLinkInfo.getLinkTargetType());
assertEquals(action.getLinkCommandLine().getLinkStaticness().name(),
cppLinkInfo.getLinkStaticness());
assertThat(cppLinkInfo.getOutputFile())
.isEqualTo(action.getPrimaryOutput().getExecPathString());
assertThat(cppLinkInfo.getLinkTargetType())
.isEqualTo(action.getLinkCommandLine().getLinkTargetType().name());
assertThat(cppLinkInfo.getLinkStaticness())
.isEqualTo(action.getLinkCommandLine().getLinkStaticness().name());
Iterable<String> linkstamps = Artifact.asExecPaths(
action.getLinkCommandLine().getLinkstamps().values());
assertThat(cppLinkInfo.getLinkStampList()).containsExactlyElementsIn(linkstamps);
Expand Down Expand Up @@ -377,15 +378,17 @@ public void testArtifactsToAlwaysBuild() throws Exception {
useConfiguration("--cpu=k8");
// ArtifactsToAlwaysBuild should apply both for static libraries.
ConfiguredTarget helloStatic = getConfiguredTarget("//hello:hello_static");
assertEquals(ImmutableSet.of("bin hello/_objs/hello_static/hello/hello.pic.o"),
artifactsToStrings(getOutputGroup(helloStatic, OutputGroupProvider.HIDDEN_TOP_LEVEL)));
assertThat(
artifactsToStrings(getOutputGroup(helloStatic, OutputGroupProvider.HIDDEN_TOP_LEVEL)))
.containsExactly("bin hello/_objs/hello_static/hello/hello.pic.o");
Artifact implSharedObject = getBinArtifact("libhello_static.so", helloStatic);
assertThat(getFilesToBuild(helloStatic)).doesNotContain(implSharedObject);

// And for shared libraries.
ConfiguredTarget hello = getConfiguredTarget("//hello:hello");
assertEquals(ImmutableSet.of("bin hello/_objs/hello_static/hello/hello.pic.o"),
artifactsToStrings(getOutputGroup(helloStatic, OutputGroupProvider.HIDDEN_TOP_LEVEL)));
assertThat(
artifactsToStrings(getOutputGroup(helloStatic, OutputGroupProvider.HIDDEN_TOP_LEVEL)))
.containsExactly("bin hello/_objs/hello_static/hello/hello.pic.o");
implSharedObject = getBinArtifact("libhello.so", hello);
assertThat(getFilesToBuild(hello)).contains(implSharedObject);
}
Expand All @@ -398,12 +401,11 @@ public void testTransitiveArtifactsToAlwaysBuildStatic() throws Exception {
"cc_library(name = 'x', srcs = ['x.cc'], deps = [':y'], linkstatic = 1)",
"cc_library(name = 'y', srcs = ['y.cc'], deps = [':z'])",
"cc_library(name = 'z', srcs = ['z.cc'])");
assertEquals(
ImmutableSet.of(
"bin foo/_objs/x/foo/x.pic.o",
"bin foo/_objs/y/foo/y.pic.o",
"bin foo/_objs/z/foo/z.pic.o"),
artifactsToStrings(getOutputGroup(x, OutputGroupProvider.HIDDEN_TOP_LEVEL)));
assertThat(artifactsToStrings(getOutputGroup(x, OutputGroupProvider.HIDDEN_TOP_LEVEL)))
.containsExactly(
"bin foo/_objs/x/foo/x.pic.o",
"bin foo/_objs/y/foo/y.pic.o",
"bin foo/_objs/z/foo/z.pic.o");
}

@Test
Expand Down Expand Up @@ -789,8 +791,8 @@ public void testCppModuleMap() throws Exception {
assertThat(ActionsTestUtil.baseArtifactNames(action.getDependencyArtifacts())).containsExactly(
"stl.cppmap",
"crosstool.cppmap");
assertEquals(ImmutableSet.of("src module/a.h"),
artifactsToStrings(action.getPrivateHeaders()));
assertThat(artifactsToStrings(action.getPrivateHeaders()))
.containsExactly("src module/a.h");
assertThat(action.getPublicHeaders()).isEmpty();
}

Expand Down
Loading

0 comments on commit 78cfa8d

Please sign in to comment.