diff options
author | lberki <lberki@google.com> | 2017-05-30 17:00:48 +0200 |
---|---|---|
committer | László Csomor <laszlocsomor@google.com> | 2017-05-31 09:18:22 +0200 |
commit | 78cfa8d1977036452f45838f739cc53debf8a615 (patch) | |
tree | 1a7aa946715e7d1b764955f3ee857ef435295ec0 /src | |
parent | a1fb6f26cfeaa712f447e5d41d2a98565e9ab478 (diff) |
Migrate most of the assertions to Truth that the auto-migration tool did not catch.
IntelliJ's "replace structurally" command was surprisingly useful.
RELNOTES: None.
PiperOrigin-RevId: 157463734
Diffstat (limited to 'src')
35 files changed, 625 insertions, 659 deletions
diff --git a/src/test/java/com/google/devtools/build/android/DensitySpecificManifestProcessorTest.java b/src/test/java/com/google/devtools/build/android/DensitySpecificManifestProcessorTest.java index b62717dba7..fca649b2b7 100644 --- a/src/test/java/com/google/devtools/build/android/DensitySpecificManifestProcessorTest.java +++ b/src/test/java/com/google/devtools/build/android/DensitySpecificManifestProcessorTest.java @@ -16,8 +16,6 @@ package com.google.devtools.build.android; 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; @@ -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 { @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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")); } diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCacheTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCacheTest.java index dfcca3d6c9..dc1a690c86 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCacheTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCacheTest.java @@ -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; @@ -117,7 +116,7 @@ public class RepositoryCacheTest { .isEqualTo(FileSystemUtils.readContent(actualTargetPath, Charset.defaultCharset())); // Check that the returned value is stored under outputBaseExternal. - assertEquals(targetPath, actualTargetPath); + assertThat((Object) actualTargetPath).isEqualTo(targetPath); } /** @@ -129,7 +128,7 @@ public class RepositoryCacheTest { Path targetPath = targetDirectory.getChild(downloadedFile.getBaseName()); Path actualTargetPath = repositoryCache.get(downloadedFileSha256, targetPath, KeyType.SHA256); - assertEquals(actualTargetPath, null); + assertThat(actualTargetPath).isNull(); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java index 4f5b63e26e..88aa3c09b8 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java @@ -17,8 +17,6 @@ import static com.google.common.collect.Iterables.getOnlyElement; 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; @@ -114,15 +112,16 @@ public class CcCommonTest extends BuildViewTestCase { // 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() { @@ -132,8 +131,8 @@ public class CcCommonTest extends BuildViewTestCase { @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 { @@ -229,11 +228,12 @@ public class CcCommonTest extends BuildViewTestCase { "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(); @@ -272,7 +272,8 @@ public class CcCommonTest extends BuildViewTestCase { 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(); } } @@ -625,7 +626,7 @@ public class CcCommonTest extends BuildViewTestCase { // 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 @@ -699,8 +700,8 @@ public class CcCommonTest extends BuildViewTestCase { } 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 @@ -768,7 +769,7 @@ public class CcCommonTest extends BuildViewTestCase { 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". */ diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCompileOnlyTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCompileOnlyTest.java index 4b1fe98151..03f06b6534 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCompileOnlyTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCompileOnlyTest.java @@ -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; @@ -51,11 +50,11 @@ public class CcCompileOnlyTest extends CompileOnlyTestCase { 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(); } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java index 7b3064dbb3..1613d25323 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java @@ -17,17 +17,11 @@ package com.google.devtools.build.lib.rules.cpp; 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; @@ -94,7 +88,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { private void assertNoCppModuleMapAction(String label) throws Exception { ConfiguredTarget target = getConfiguredTarget(label); - assertNull(target.getProvider(CppCompilationContext.class).getCppModuleMap()); + assertThat(target.getProvider(CppCompilationContext.class).getCppModuleMap()).isNull(); } @@ -181,8 +175,13 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { @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 @@ -219,20 +218,21 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { 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); @@ -248,25 +248,26 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { 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); @@ -377,15 +378,17 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { 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); } @@ -398,12 +401,11 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { "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 @@ -789,8 +791,8 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { 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(); } diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java index 4d6109fe9a..3beb3a6d13 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java @@ -54,12 +54,12 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) @TestSpec(size = Suite.MEDIUM_TESTS) public class CcToolchainFeaturesTest { - + /** * Creates a {@code Variables} configuration from a list of key/value pairs. - * + * * <p>If there are multiple entries with the same key, the variable will be treated as sequence - * type. + * type. */ private Variables createVariables(String... entries) { if (entries.length % 2 != 0) { @@ -81,14 +81,14 @@ public class CcToolchainFeaturesTest { } return variables.build(); } - + /** * Creates a CcToolchainFeatures from features described in the given toolchain fragment. */ public static CcToolchainFeatures buildFeatures(String... toolchain) throws Exception { CToolchain.Builder toolchainBuilder = CToolchain.newBuilder(); - TextFormat.merge(Joiner.on("").join(toolchain), toolchainBuilder); - return new CcToolchainFeatures(toolchainBuilder.buildPartial()); + TextFormat.merge(Joiner.on("").join(toolchain), toolchainBuilder); + return new CcToolchainFeatures(toolchainBuilder.buildPartial()); } private Set<String> getEnabledFeatures(CcToolchainFeatures features, @@ -204,7 +204,7 @@ public class CcToolchainFeaturesTest { private String getExpansionOfFlag(String value) throws Exception { return getExpansionOfFlag(value, createVariables()); } - + private List<String> getCommandLineForFlagGroups(String groups, Variables variables) throws Exception { FeatureConfiguration configuration = @@ -219,11 +219,11 @@ public class CcToolchainFeaturesTest { .getFeatureConfiguration(assumptionsFor("a")); return configuration.getCommandLine(CppCompileAction.CPP_COMPILE, variables); } - + private List<String> getCommandLineForFlag(String value, Variables variables) throws Exception { return getCommandLineForFlagGroups("flag_group { flag: '" + value + "' }", variables); } - + private String getExpansionOfFlag(String value, Variables variables) throws Exception { return getCommandLineForFlag(value, variables).get(0); } @@ -237,7 +237,7 @@ public class CcToolchainFeaturesTest { return e.getMessage(); } } - + private String getFlagExpansionError(String value, Variables variables) throws Exception { try { getExpansionOfFlag(value, variables); @@ -752,7 +752,7 @@ public class CcToolchainFeaturesTest { assertThat(e).hasMessageThat().contains("'v1' and 'v2'"); } } - + private VariableValueBuilder createNestedSequence(int depth, int count, String prefix) { if (depth == 0) { StringSequenceBuilder builder = new StringSequenceBuilder(); @@ -836,7 +836,7 @@ public class CcToolchainFeaturesTest { CcToolchainFeatures features = buildFeatures( "feature { name: 'a' requires: { feature: 'b' } }", "feature { name: 'b' requires: { feature: 'c' } }", - "feature { name: 'c' }"); + "feature { name: 'c' }"); assertThat(getEnabledFeatures(features, "a")).isEmpty(); assertThat(getEnabledFeatures(features, "a", "b")).isEmpty(); assertThat(getEnabledFeatures(features, "a", "c")).containsExactly("c"); @@ -855,7 +855,7 @@ public class CcToolchainFeaturesTest { "feature { name: 'b' requires: { feature: 'a' } implies: 'c' }", "feature { name: 'c' }", "feature { name: 'd' requires: { feature: 'c' } implies: 'e' }", - "feature { name: 'e' }"); + "feature { name: 'e' }"); assertThat(getEnabledFeatures(features, "b", "d")).isEmpty(); } @@ -867,7 +867,7 @@ public class CcToolchainFeaturesTest { "feature { name: 'b' requires: { feature: 'a' } implies: 'c' }", "feature { name: 'c' }", "feature { name: 'd' requires: { feature: 'c' } implies: 'e' }", - "feature { name: 'e' }"); + "feature { name: 'e' }"); assertThat(getEnabledFeatures(features, "0", "b", "d")).containsExactly( "0", "a", "b", "c", "d", "e"); } @@ -912,7 +912,7 @@ public class CcToolchainFeaturesTest { "feature { name: 'a' implies: 'b' requires: { feature: 'c' } }", "feature { name: 'b' }", "feature { name: 'c' }"); - assertThat(getEnabledFeatures(features, "a")).isEmpty(); + assertThat(getEnabledFeatures(features, "a")).isEmpty(); } @Test @@ -979,7 +979,7 @@ public class CcToolchainFeaturesTest { "feature { name: 'b' requires: { feature: 'a' } implies: 'd' }", "feature { name: 'c' implies: 'd' }", "feature { name: 'd' }"); - assertThat(getEnabledFeatures(features, "b", "c")).containsExactly("c", "d"); + assertThat(getEnabledFeatures(features, "b", "c")).containsExactly("c", "d"); } @Test @@ -989,7 +989,7 @@ public class CcToolchainFeaturesTest { "feature { name: 'b' }", "feature { name: 'c' requires: { feature: 'd' } }", "feature { name: 'd' }"); - assertThat(getEnabledFeatures(features, "a", "b", "c")).containsExactly("a", "b"); + assertThat(getEnabledFeatures(features, "a", "b", "c")).containsExactly("a", "b"); } @Test @@ -1056,14 +1056,14 @@ public class CcToolchainFeaturesTest { byte[] serialized = TestUtils.serializeObject(features); CcToolchainFeatures deserialized = (CcToolchainFeatures) TestUtils.deserializeObject(serialized); - assertThat(getEnabledFeatures(deserialized, "b")).containsExactly("a", "b"); + assertThat(getEnabledFeatures(deserialized, "b")).containsExactly("a", "b"); assertThat( features .getFeatureConfiguration(assumptionsFor("b")) .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables("v", "1"))) .containsExactly("-f", "1"); } - + @Test public void testDefaultFeatures() throws Exception { CcToolchainFeatures features = @@ -1446,7 +1446,6 @@ public class CcToolchainFeaturesTest { List<String> commandLine = featureConfiguration.getCommandLine("c++-compile", createVariables()); assertThat(commandLine).contains("foo"); - ; } @Test diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppFileTypesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppFileTypesTest.java index 7970273005..46677cd480 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppFileTypesTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppFileTypesTest.java @@ -14,8 +14,7 @@ package com.google.devtools.build.lib.rules.cpp; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,22 +28,22 @@ public class CppFileTypesTest { @Test public void testTwoDotExtensions() { - assertTrue(CppFileTypes.OBJECT_FILE.matches("test.o")); - assertTrue(CppFileTypes.PIC_OBJECT_FILE.matches("test.pic.o")); - assertFalse(CppFileTypes.OBJECT_FILE.matches("test.pic.o")); + assertThat(CppFileTypes.OBJECT_FILE.matches("test.o")).isTrue(); + assertThat(CppFileTypes.PIC_OBJECT_FILE.matches("test.pic.o")).isTrue(); + assertThat(CppFileTypes.OBJECT_FILE.matches("test.pic.o")).isFalse(); } @Test public void testVersionedSharedLibraries() { - assertTrue(CppFileTypes.SHARED_LIBRARY.matches("somelibrary.so")); - assertTrue(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.2")); - assertTrue(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.20")); - assertTrue(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.20.2")); - assertTrue(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("a/somelibrary.so.2")); - assertFalse(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.e")); - assertFalse(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.2e")); - assertFalse(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.e2")); - assertFalse(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.20.e2")); - assertFalse(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.a.2")); + assertThat(CppFileTypes.SHARED_LIBRARY.matches("somelibrary.so")).isTrue(); + assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.2")).isTrue(); + assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.20")).isTrue(); + assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.20.2")).isTrue(); + assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("a/somelibrary.so.2")).isTrue(); + assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.e")).isFalse(); + assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.2e")).isFalse(); + assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.e2")).isFalse(); + assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.so.20.e2")).isFalse(); + assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("somelibrary.a.2")).isFalse(); } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java index fb8ebbbe8f..fdd13b07f1 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java @@ -15,8 +15,6 @@ package com.google.devtools.build.lib.rules.cpp; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.base.Joiner; @@ -386,17 +384,17 @@ public class CppLinkActionTest extends BuildViewTestCase { CppHelper.getToolchainUsingDefaultCcToolchainAttribute(ruleContext), CppHelper.getFdoSupportUsingDefaultCcToolchainAttribute(ruleContext)); builder.setLinkType(LinkTargetType.STATIC_LIBRARY); - assertTrue(builder.canSplitCommandLine()); + assertThat(builder.canSplitCommandLine()).isTrue(); builder.setLinkType(LinkTargetType.DYNAMIC_LIBRARY); - assertTrue(builder.canSplitCommandLine()); + assertThat(builder.canSplitCommandLine()).isTrue(); builder.setInterfaceOutput(outputIfso); - assertFalse(builder.canSplitCommandLine()); + assertThat(builder.canSplitCommandLine()).isFalse(); builder.setInterfaceOutput(null); builder.setLinkType(LinkTargetType.INTERFACE_DYNAMIC_LIBRARY); - assertFalse(builder.canSplitCommandLine()); + assertThat(builder.canSplitCommandLine()).isFalse(); } /** @@ -426,11 +424,11 @@ public class CppLinkActionTest extends BuildViewTestCase { CppLinkAction linkAction = createLinkBuilder( - Link.LinkTargetType.EXECUTABLE, - "dummyRuleContext/binary2", - objects.build(), - ImmutableList.<LibraryToLink>of(), - new FeatureConfiguration()) + Link.LinkTargetType.EXECUTABLE, + "dummyRuleContext/binary2", + objects.build(), + ImmutableList.<LibraryToLink>of(), + new FeatureConfiguration()) .setFake(true) .build(); @@ -451,12 +449,12 @@ public class CppLinkActionTest extends BuildViewTestCase { ); // Ensure that anything above the minimum is properly scaled. - assertTrue(resources.getMemoryMb() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getMemoryMb() - || resources.getMemoryMb() == scaledSet.getMemoryMb()); - assertTrue(resources.getCpuUsage() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getCpuUsage() - || resources.getCpuUsage() == scaledSet.getCpuUsage()); - assertTrue(resources.getIoUsage() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getIoUsage() - || resources.getIoUsage() == scaledSet.getIoUsage()); + assertThat(resources.getMemoryMb() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getMemoryMb() + || resources.getMemoryMb() == scaledSet.getMemoryMb()).isTrue(); + assertThat(resources.getCpuUsage() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getCpuUsage() + || resources.getCpuUsage() == scaledSet.getCpuUsage()).isTrue(); + assertThat(resources.getIoUsage() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getIoUsage() + || resources.getIoUsage() == scaledSet.getIoUsage()).isTrue(); } private CppLinkActionBuilder createLinkBuilder( diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkActionTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkActionTest.java index 07ba4ff058..323ec54621 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkActionTest.java @@ -17,8 +17,6 @@ package com.google.devtools.build.lib.rules.cpp; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ACTION_OWNER; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.Artifact; @@ -101,9 +99,9 @@ public class CreateIncSymlinkActionTest extends FoundationTestCase { ImmutableMap.of(a, b), outputDir); action.execute(null); symlink.stat(Symlinks.NOFOLLOW); - assertTrue(symlink.isSymbolicLink()); + assertThat(symlink.isSymbolicLink()).isTrue(); assertEquals(symlink.readSymbolicLink(), b.getPath().asFragment()); - assertFalse(rootDirectory.getRelative("a").exists()); + assertThat(rootDirectory.getRelative("a").exists()).isFalse(); } @Test @@ -118,8 +116,8 @@ public class CreateIncSymlinkActionTest extends FoundationTestCase { new CreateIncSymlinkAction(NULL_ACTION_OWNER, ImmutableMap.of(a, b), outputDir); Path extra = rootDirectory.getRelative("out/extra"); extra.getOutputStream().close(); - assertTrue(extra.exists()); + assertThat(extra.exists()).isTrue(); action.prepare(rootDirectory); - assertFalse(extra.exists()); + assertThat(extra.exists()).isFalse(); } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoaderTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoaderTest.java index 464757378b..38d57b70dc 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoaderTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoaderTest.java @@ -15,11 +15,6 @@ package com.google.devtools.build.lib.rules.cpp; 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.Functions; @@ -42,7 +37,6 @@ import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.LipoMode; import java.io.IOException; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import org.junit.Before; @@ -183,52 +177,58 @@ public class CrosstoolConfigurationLoaderTest extends AnalysisTestCase { CppConfiguration toolchain = create(loader, "--cpu=cpu", "--host_cpu=cpu", "--android_cpu=", "--fat_apk_cpu="); CcToolchainProvider ccProvider = getCcToolchainProvider(toolchain); - assertEquals("toolchain-identifier", toolchain.getToolchainIdentifier()); + assertThat(toolchain.getToolchainIdentifier()).isEqualTo("toolchain-identifier"); - assertEquals("host-system-name", toolchain.getHostSystemName()); - assertEquals("compiler", toolchain.getCompiler()); - assertEquals("target-libc", toolchain.getTargetLibc()); - assertEquals("piii", toolchain.getTargetCpu()); - assertEquals("target-system-name", toolchain.getTargetGnuSystemName()); + assertThat(toolchain.getHostSystemName()).isEqualTo("host-system-name"); + assertThat(toolchain.getCompiler()).isEqualTo("compiler"); + assertThat(toolchain.getTargetLibc()).isEqualTo("target-libc"); + assertThat(toolchain.getTargetCpu()).isEqualTo("piii"); + assertThat(toolchain.getTargetGnuSystemName()).isEqualTo("target-system-name"); - assertEquals(getToolPath("/path-to-ar"), toolchain.getToolPathFragment(Tool.AR)); + assertThat(toolchain.getToolPathFragment(Tool.AR)).isEqualTo(getToolPath("/path-to-ar")); - assertEquals("abi-version", toolchain.getAbi()); - assertEquals("abi-libc-version", toolchain.getAbiGlibcVersion()); + assertThat(toolchain.getAbi()).isEqualTo("abi-version"); + assertThat(toolchain.getAbiGlibcVersion()).isEqualTo("abi-libc-version"); - assertTrue(toolchain.supportsGoldLinker()); - assertFalse(toolchain.supportsStartEndLib()); - assertFalse(toolchain.supportsInterfaceSharedObjects()); - assertFalse(toolchain.supportsEmbeddedRuntimes()); - assertFalse(toolchain.toolchainNeedsPic()); - assertTrue(toolchain.supportsFission()); + assertThat(toolchain.supportsGoldLinker()).isTrue(); + assertThat(toolchain.supportsStartEndLib()).isFalse(); + assertThat(toolchain.supportsInterfaceSharedObjects()).isFalse(); + assertThat(toolchain.supportsEmbeddedRuntimes()).isFalse(); + assertThat(toolchain.toolchainNeedsPic()).isFalse(); + assertThat(toolchain.supportsFission()).isTrue(); assertThat(ccProvider.getBuiltInIncludeDirectories()) .containsExactly(getToolPath("/system-include-dir")); - assertNull(ccProvider.getSysroot()); + assertThat(ccProvider.getSysroot()).isNull(); - assertEquals(Arrays.asList("c", "fastbuild"), toolchain.getCompilerOptions(NO_FEATURES)); - assertEquals(Arrays.<String>asList(), toolchain.getCOptions()); - assertEquals(Arrays.asList("cxx", "cxx-fastbuild"), toolchain.getCxxOptions(NO_FEATURES)); - assertEquals(Arrays.asList("unfiltered"), ccProvider.getUnfilteredCompilerOptions(NO_FEATURES)); + assertThat(toolchain.getCompilerOptions(NO_FEATURES)) + .containsExactly("c", "fastbuild") + .inOrder(); + assertThat(toolchain.getCOptions()).isEmpty(); + assertThat(toolchain.getCxxOptions(NO_FEATURES)) + .containsExactly("cxx", "cxx-fastbuild") + .inOrder(); + assertThat(ccProvider.getUnfilteredCompilerOptions(NO_FEATURES)) + .containsExactly("unfiltered") + .inOrder(); - assertEquals(Arrays.<String>asList(), ccProvider.getLinkOptions()); - assertEquals( - Arrays.asList("linker", "linker-fastbuild", "fully static"), - toolchain.getFullyStaticLinkOptions(NO_FEATURES, false)); - assertEquals( - Arrays.asList("linker", "linker-fastbuild", "dynamic"), - toolchain.getDynamicLinkOptions(NO_FEATURES, false)); - assertEquals( - Arrays.asList("linker", "linker-fastbuild", "mostly static", "solinker"), - toolchain.getFullyStaticLinkOptions(NO_FEATURES, true)); - assertEquals( - Arrays.asList("linker", "linker-fastbuild", "dynamic", "solinker"), - toolchain.getDynamicLinkOptions(NO_FEATURES, true)); + assertThat(ccProvider.getLinkOptions()).isEmpty(); + assertThat(toolchain.getFullyStaticLinkOptions(NO_FEATURES, false)) + .containsExactly("linker", "linker-fastbuild", "fully static") + .inOrder(); + assertThat(toolchain.getDynamicLinkOptions(NO_FEATURES, false)) + .containsExactly("linker", "linker-fastbuild", "dynamic") + .inOrder(); + assertThat(toolchain.getFullyStaticLinkOptions(NO_FEATURES, true)) + .containsExactly("linker", "linker-fastbuild", "mostly static", "solinker") + .inOrder(); + assertThat(toolchain.getDynamicLinkOptions(NO_FEATURES, true)) + .containsExactly("linker", "linker-fastbuild", "dynamic", "solinker") + .inOrder(); - assertEquals(Arrays.asList("objcopy"), toolchain.getObjCopyOptionsForEmbedding()); - assertEquals(Arrays.<String>asList(), toolchain.getLdOptionsForEmbedding()); - assertEquals(Arrays.asList("rcsD"), toolchain.getArFlags()); + assertThat(toolchain.getObjCopyOptionsForEmbedding()).containsExactly("objcopy").inOrder(); + assertThat(toolchain.getLdOptionsForEmbedding()).isEmpty(); + assertThat(toolchain.getArFlags()).containsExactly("rcsD").inOrder(); assertThat(toolchain.getAdditionalMakeVariables().entrySet()) .containsExactlyElementsIn( @@ -238,8 +238,8 @@ public class CrosstoolConfigurationLoaderTest extends AnalysisTestCase { "CC_FLAGS", "") .entrySet()); - assertEquals(getToolPath("/path-to-ld"), toolchain.getLdExecutable()); - assertEquals(getToolPath("/path-to-dwp"), toolchain.getToolPathFragment(Tool.DWP)); + assertThat(toolchain.getLdExecutable()).isEqualTo(getToolPath("/path-to-ld")); + assertThat(toolchain.getToolPathFragment(Tool.DWP)).isEqualTo(getToolPath("/path-to-dwp")); } /** @@ -493,106 +493,104 @@ public class CrosstoolConfigurationLoaderTest extends AnalysisTestCase { ConfiguredTarget ccToolchainA = getCcToolchainTarget(toolchainA); CcToolchainProvider ccProviderA = ccToolchainA.getProvider(CcToolchainProvider.class); MakeVariableProvider makeProviderA = ccToolchainA.getProvider(MakeVariableProvider.class); - assertEquals("toolchain-identifier-A", toolchainA.getToolchainIdentifier()); - assertEquals("host-system-name-A", toolchainA.getHostSystemName()); - assertEquals("target-system-name-A", toolchainA.getTargetGnuSystemName()); - assertEquals("piii", toolchainA.getTargetCpu()); - assertEquals("target-libc-A", toolchainA.getTargetLibc()); - assertEquals("compiler-A", toolchainA.getCompiler()); - assertEquals("abi-version-A", toolchainA.getAbi()); - assertEquals("abi-libc-version-A", toolchainA.getAbiGlibcVersion()); - assertEquals(getToolPath("path/to/ar-A"), toolchainA.getToolPathFragment(Tool.AR)); - assertEquals(getToolPath("path/to/cpp-A"), toolchainA.getToolPathFragment(Tool.CPP)); - assertEquals(getToolPath("path/to/gcc-A"), toolchainA.getToolPathFragment(Tool.GCC)); - assertEquals(getToolPath("path/to/gcov-A"), toolchainA.getToolPathFragment(Tool.GCOV)); - assertEquals(getToolPath("path/to/ld-A"), toolchainA.getToolPathFragment(Tool.LD)); - assertEquals(getToolPath("path/to/nm-A"), toolchainA.getToolPathFragment(Tool.NM)); - assertEquals(getToolPath("path/to/objcopy-A"), toolchainA.getToolPathFragment(Tool.OBJCOPY)); - assertEquals(getToolPath("path/to/objdump-A"), toolchainA.getToolPathFragment(Tool.OBJDUMP)); - assertEquals(getToolPath("path/to/strip-A"), toolchainA.getToolPathFragment(Tool.STRIP)); - assertTrue(toolchainA.supportsGoldLinker()); - assertTrue(toolchainA.supportsStartEndLib()); - assertTrue(toolchainA.supportsEmbeddedRuntimes()); - assertTrue(toolchainA.toolchainNeedsPic()); + assertThat(toolchainA.getToolchainIdentifier()).isEqualTo("toolchain-identifier-A"); + assertThat(toolchainA.getHostSystemName()).isEqualTo("host-system-name-A"); + assertThat(toolchainA.getTargetGnuSystemName()).isEqualTo("target-system-name-A"); + assertThat(toolchainA.getTargetCpu()).isEqualTo("piii"); + assertThat(toolchainA.getTargetLibc()).isEqualTo("target-libc-A"); + assertThat(toolchainA.getCompiler()).isEqualTo("compiler-A"); + assertThat(toolchainA.getAbi()).isEqualTo("abi-version-A"); + assertThat(toolchainA.getAbiGlibcVersion()).isEqualTo("abi-libc-version-A"); + assertThat(toolchainA.getToolPathFragment(Tool.AR)).isEqualTo(getToolPath("path/to/ar-A")); + assertThat(toolchainA.getToolPathFragment(Tool.CPP)).isEqualTo(getToolPath("path/to/cpp-A")); + assertThat(toolchainA.getToolPathFragment(Tool.GCC)).isEqualTo(getToolPath("path/to/gcc-A")); + assertThat(toolchainA.getToolPathFragment(Tool.GCOV)).isEqualTo(getToolPath("path/to/gcov-A")); + assertThat(toolchainA.getToolPathFragment(Tool.LD)).isEqualTo(getToolPath("path/to/ld-A")); + assertThat(toolchainA.getToolPathFragment(Tool.NM)).isEqualTo(getToolPath("path/to/nm-A")); + assertThat(toolchainA.getToolPathFragment(Tool.OBJCOPY)) + .isEqualTo(getToolPath("path/to/objcopy-A")); + assertThat(toolchainA.getToolPathFragment(Tool.OBJDUMP)) + .isEqualTo(getToolPath("path/to/objdump-A")); + assertThat(toolchainA.getToolPathFragment(Tool.STRIP)) + .isEqualTo(getToolPath("path/to/strip-A")); + assertThat(toolchainA.supportsGoldLinker()).isTrue(); + assertThat(toolchainA.supportsStartEndLib()).isTrue(); + assertThat(toolchainA.supportsEmbeddedRuntimes()).isTrue(); + assertThat(toolchainA.toolchainNeedsPic()).isTrue(); - assertEquals( - Arrays.asList( - "compiler-flag-A-1", "compiler-flag-A-2", "fastbuild-flag-A-1", "fastbuild-flag-A-2"), - toolchainA.getCompilerOptions(NO_FEATURES)); - assertEquals( - Arrays.asList( - "cxx-flag-A-1", "cxx-flag-A-2", "cxx-fastbuild-flag-A-1", "cxx-fastbuild-flag-A-2"), - toolchainA.getCxxOptions(NO_FEATURES)); - assertEquals( - Arrays.asList("--sysroot=some", "unfiltered-flag-A-1", "unfiltered-flag-A-2"), - ccProviderA.getUnfilteredCompilerOptions(NO_FEATURES)); - assertEquals( - Arrays.asList( + assertThat(toolchainA.getCompilerOptions(NO_FEATURES)) + .containsExactly( + "compiler-flag-A-1", "compiler-flag-A-2", "fastbuild-flag-A-1", "fastbuild-flag-A-2") + .inOrder(); + assertThat(toolchainA.getCxxOptions(NO_FEATURES)) + .containsExactly( + "cxx-flag-A-1", "cxx-flag-A-2", "cxx-fastbuild-flag-A-1", "cxx-fastbuild-flag-A-2") + .inOrder(); + assertThat(ccProviderA.getUnfilteredCompilerOptions(NO_FEATURES)) + .containsExactly("--sysroot=some", "unfiltered-flag-A-1", "unfiltered-flag-A-2") + .inOrder(); + assertThat(toolchainA.getDynamicLinkOptions(NO_FEATURES, true)) + .containsExactly( "linker-flag-A-1", "linker-flag-A-2", "linker-fastbuild-flag-A-1", "linker-fastbuild-flag-A-2", "solinker-flag-A-1", - "solinker-flag-A-2"), - toolchainA.getDynamicLinkOptions(NO_FEATURES, true)); + "solinker-flag-A-2") + .inOrder(); // Only test a couple of compilation/lipo/linking mode combinations // (but test each mode at least once.) - assertEquals( - Arrays.asList( + assertThat( + toolchainA.configureLinkerOptions( + CompilationMode.FASTBUILD, + LipoMode.OFF, + LinkingMode.FULLY_STATIC, + PathFragment.create("hello-world/ld"))) + .containsExactly( "linker-flag-A-1", "linker-flag-A-2", "linker-fastbuild-flag-A-1", "linker-fastbuild-flag-A-2", "fully-static-flag-A-1", - "fully-static-flag-A-2"), - toolchainA.configureLinkerOptions( - CompilationMode.FASTBUILD, - LipoMode.OFF, - LinkingMode.FULLY_STATIC, - PathFragment.create("hello-world/ld"))); - assertEquals( - Arrays.asList( - "linker-flag-A-1", - "linker-flag-A-2", - "linker-dbg-flag-A-1", - "linker-dbg-flag-A-2"), - toolchainA.configureLinkerOptions( - CompilationMode.DBG, - LipoMode.OFF, - LinkingMode.DYNAMIC, - PathFragment.create("hello-world/ld"))); - assertEquals( - Arrays.asList( - "linker-flag-A-1", - "linker-flag-A-2", - "fully-static-flag-A-1", - "fully-static-flag-A-2"), - toolchainA.configureLinkerOptions( - CompilationMode.OPT, - LipoMode.OFF, - LinkingMode.FULLY_STATIC, - PathFragment.create("hello-world/ld"))); + "fully-static-flag-A-2") + .inOrder(); + assertThat( + toolchainA.configureLinkerOptions( + CompilationMode.DBG, + LipoMode.OFF, + LinkingMode.DYNAMIC, + PathFragment.create("hello-world/ld"))) + .containsExactly( + "linker-flag-A-1", "linker-flag-A-2", "linker-dbg-flag-A-1", "linker-dbg-flag-A-2") + .inOrder(); + assertThat( + toolchainA.configureLinkerOptions( + CompilationMode.OPT, + LipoMode.OFF, + LinkingMode.FULLY_STATIC, + PathFragment.create("hello-world/ld"))) + .containsExactly( + "linker-flag-A-1", "linker-flag-A-2", "fully-static-flag-A-1", "fully-static-flag-A-2") + .inOrder(); - assertEquals( - Arrays.asList( - "linker-flag-A-1", - "linker-flag-A-2", - "fully-static-flag-A-1", - "fully-static-flag-A-2"), - toolchainA.configureLinkerOptions( - CompilationMode.OPT, - LipoMode.BINARY, - LinkingMode.FULLY_STATIC, - PathFragment.create("hello-world/ld"))); + assertThat( + toolchainA.configureLinkerOptions( + CompilationMode.OPT, + LipoMode.BINARY, + LinkingMode.FULLY_STATIC, + PathFragment.create("hello-world/ld"))) + .containsExactly( + "linker-flag-A-1", "linker-flag-A-2", "fully-static-flag-A-1", "fully-static-flag-A-2") + .inOrder(); - assertEquals( - Arrays.asList("objcopy-embed-flag-A-1", "objcopy-embed-flag-A-2"), - toolchainA.getObjCopyOptionsForEmbedding()); - assertEquals( - Arrays.asList("ld-embed-flag-A-1", "ld-embed-flag-A-2"), - toolchainA.getLdOptionsForEmbedding()); - assertEquals(Arrays.asList("ar-flag-A"), toolchainA.getArFlags()); + assertThat(toolchainA.getObjCopyOptionsForEmbedding()) + .containsExactly("objcopy-embed-flag-A-1", "objcopy-embed-flag-A-2") + .inOrder(); + assertThat(toolchainA.getLdOptionsForEmbedding()) + .containsExactly("ld-embed-flag-A-1", "ld-embed-flag-A-2") + .inOrder(); + assertThat(toolchainA.getArFlags()).containsExactly("ar-flag-A").inOrder(); assertThat(makeProviderA.getMakeVariables().entrySet()) .containsExactlyElementsIn( @@ -603,11 +601,11 @@ public class CrosstoolConfigurationLoaderTest extends AnalysisTestCase { .put("STACK_FRAME_UNLIMITED", "") .build() .entrySet()); - assertEquals( - Arrays.asList( - getToolPath("/system-include-dir-A-1"), getToolPath("/system-include-dir-A-2")), - ccProviderA.getBuiltInIncludeDirectories()); - assertEquals(PathFragment.create("some"), ccProviderA.getSysroot()); + assertThat(ccProviderA.getBuiltInIncludeDirectories()) + .containsExactly( + getToolPath("/system-include-dir-A-1"), getToolPath("/system-include-dir-A-2")) + .inOrder(); + assertThat(ccProviderA.getSysroot()).isEqualTo(PathFragment.create("some")); // Cursory testing of the "B" toolchain only; assume that if none of // toolchain B bled through into toolchain A, the reverse also didn't occur. And @@ -628,60 +626,56 @@ public class CrosstoolConfigurationLoaderTest extends AnalysisTestCase { "--android_cpu=", "--fat_apk_cpu="); CcToolchainProvider ccProviderC = getCcToolchainProvider(toolchainC); - assertEquals("toolchain-identifier-C", toolchainC.getToolchainIdentifier()); - assertEquals("host-system-name-C", toolchainC.getHostSystemName()); - assertEquals("target-system-name-C", toolchainC.getTargetGnuSystemName()); - assertEquals("piii", toolchainC.getTargetCpu()); - assertEquals("target-libc-C", toolchainC.getTargetLibc()); - assertEquals("compiler-C", toolchainC.getCompiler()); - assertEquals("abi-version-C", toolchainC.getAbi()); - assertEquals("abi-libc-version-C", toolchainC.getAbiGlibcVersion()); + assertThat(toolchainC.getToolchainIdentifier()).isEqualTo("toolchain-identifier-C"); + assertThat(toolchainC.getHostSystemName()).isEqualTo("host-system-name-C"); + assertThat(toolchainC.getTargetGnuSystemName()).isEqualTo("target-system-name-C"); + assertThat(toolchainC.getTargetCpu()).isEqualTo("piii"); + assertThat(toolchainC.getTargetLibc()).isEqualTo("target-libc-C"); + assertThat(toolchainC.getCompiler()).isEqualTo("compiler-C"); + assertThat(toolchainC.getAbi()).isEqualTo("abi-version-C"); + assertThat(toolchainC.getAbiGlibcVersion()).isEqualTo("abi-libc-version-C"); // Don't bother with testing the list of tools again. - assertFalse(toolchainC.supportsGoldLinker()); - assertFalse(toolchainC.supportsStartEndLib()); - assertFalse(toolchainC.supportsInterfaceSharedObjects()); - assertFalse(toolchainC.supportsEmbeddedRuntimes()); - assertFalse(toolchainC.toolchainNeedsPic()); - assertFalse(toolchainC.supportsFission()); + assertThat(toolchainC.supportsGoldLinker()).isFalse(); + assertThat(toolchainC.supportsStartEndLib()).isFalse(); + assertThat(toolchainC.supportsInterfaceSharedObjects()).isFalse(); + assertThat(toolchainC.supportsEmbeddedRuntimes()).isFalse(); + assertThat(toolchainC.toolchainNeedsPic()).isFalse(); + assertThat(toolchainC.supportsFission()).isFalse(); assertThat(toolchainC.getCompilerOptions(NO_FEATURES)).isEmpty(); assertThat(toolchainC.getCOptions()).isEmpty(); assertThat(toolchainC.getCxxOptions(NO_FEATURES)).isEmpty(); assertThat(ccProviderC.getUnfilteredCompilerOptions(NO_FEATURES)).isEmpty(); - assertEquals(Collections.EMPTY_LIST, toolchainC.getDynamicLinkOptions(NO_FEATURES, true)); - assertEquals( - Collections.EMPTY_LIST, - toolchainC.configureLinkerOptions( - CompilationMode.FASTBUILD, - LipoMode.OFF, - LinkingMode.FULLY_STATIC, - PathFragment.create("hello-world/ld"))); - assertEquals( - Collections.EMPTY_LIST, - toolchainC.configureLinkerOptions( - CompilationMode.DBG, - LipoMode.OFF, - LinkingMode.DYNAMIC, - PathFragment.create("hello-world/ld"))); - assertEquals( - Collections.EMPTY_LIST, - toolchainC.configureLinkerOptions( - CompilationMode.OPT, - LipoMode.OFF, - LinkingMode.FULLY_STATIC, - PathFragment.create("hello-world/ld"))); + assertThat(toolchainC.getDynamicLinkOptions(NO_FEATURES, true)).isEmpty(); + assertThat( + toolchainC.configureLinkerOptions( + CompilationMode.FASTBUILD, + LipoMode.OFF, + LinkingMode.FULLY_STATIC, + PathFragment.create("hello-world/ld"))) + .isEmpty(); + assertThat( + toolchainC.configureLinkerOptions( + CompilationMode.DBG, + LipoMode.OFF, + LinkingMode.DYNAMIC, + PathFragment.create("hello-world/ld"))) + .isEmpty(); + assertThat( + toolchainC.configureLinkerOptions( + CompilationMode.OPT, + LipoMode.OFF, + LinkingMode.FULLY_STATIC, + PathFragment.create("hello-world/ld"))) + .isEmpty(); assertThat(toolchainC.getObjCopyOptionsForEmbedding()).isEmpty(); assertThat(toolchainC.getLdOptionsForEmbedding()).isEmpty(); - assertThat(toolchainC.getAdditionalMakeVariables().entrySet()) - .containsExactlyElementsIn( - ImmutableMap.<String, String>builder() - .put("CC_FLAGS", "") - .put("STACK_FRAME_UNLIMITED", "") - .build() - .entrySet()); + assertThat(toolchainC.getAdditionalMakeVariables()).containsExactlyEntriesIn(ImmutableMap.of( + "CC_FLAGS", "", + "STACK_FRAME_UNLIMITED", "")); assertThat(ccProviderC.getBuiltInIncludeDirectories()).isEmpty(); - assertNull(ccProviderC.getSysroot()); + assertThat(ccProviderC.getSysroot()).isNull(); } protected PathFragment getToolPath(String path) throws LabelSyntaxException { @@ -698,28 +692,29 @@ public class CrosstoolConfigurationLoaderTest extends AnalysisTestCase { throws Exception { String lipoSuffix = lipoMode.toString().toLowerCase(); CppConfiguration toolchainB = create(loader, args); - assertEquals("toolchain-identifier-B", toolchainB.getToolchainIdentifier()); - assertEquals( - Arrays.asList( + assertThat(toolchainB.getToolchainIdentifier()).isEqualTo("toolchain-identifier-B"); + assertThat( + toolchainB.configureLinkerOptions( + CompilationMode.DBG, + lipoMode, + LinkingMode.DYNAMIC, + PathFragment.create("hello-world/ld"))) + .containsExactly( "linker-flag-B-1", "linker-flag-B-2", "linker-dbg-flag-B-1", "linker-dbg-flag-B-2", - "linker-lipo_" + lipoSuffix), - toolchainB.configureLinkerOptions( - CompilationMode.DBG, - lipoMode, - LinkingMode.DYNAMIC, - PathFragment.create("hello-world/ld"))); - assertEquals( - ImmutableList.<String>of( + "linker-lipo_" + lipoSuffix) + .inOrder(); + assertThat(toolchainB.getCompilerOptions(ImmutableList.of("crosstool_fig"))) + .containsExactly( "compiler-flag-B-1", "compiler-flag-B-2", "fastbuild-flag-B-1", "fastbuild-flag-B-2", "lipo_" + lipoSuffix, - "-Wfig"), - toolchainB.getCompilerOptions(ImmutableList.of("crosstool_fig"))); + "-Wfig") + .inOrder(); } /** @@ -806,28 +801,26 @@ public class CrosstoolConfigurationLoaderTest extends AnalysisTestCase { + "}"); // Uses the default toolchain for k8. - assertEquals("toolchain-identifier-BB", create(loader, "--cpu=k8").getToolchainIdentifier()); + assertThat(create(loader, "--cpu=k8").getToolchainIdentifier()) + .isEqualTo("toolchain-identifier-BB"); // Does not default to --cpu=k8; if no --cpu flag is present, Bazel defaults to the host cpu! - assertEquals( - "toolchain-identifier-BA", - create(loader, "--cpu=k8", "--compiler=compiler-A", "--glibc=target-libc-B") - .getToolchainIdentifier()); + assertThat( + create(loader, "--cpu=k8", "--compiler=compiler-A", "--glibc=target-libc-B") + .getToolchainIdentifier()) + .isEqualTo("toolchain-identifier-BA"); // Uses the default toolchain for piii. - assertEquals( - "toolchain-identifier-AA-piii", create(loader, "--cpu=piii").getToolchainIdentifier()); + assertThat(create(loader, "--cpu=piii").getToolchainIdentifier()) + .isEqualTo("toolchain-identifier-AA-piii"); // We can select the unique piii toolchain with either its compiler or glibc. - assertEquals( - "toolchain-identifier-AA-piii", - create(loader, "--cpu=piii", "--compiler=compiler-A").getToolchainIdentifier()); - assertEquals( - "toolchain-identifier-AA-piii", - create(loader, "--cpu=piii", "--glibc=target-libc-A").getToolchainIdentifier()); + assertThat(create(loader, "--cpu=piii", "--compiler=compiler-A").getToolchainIdentifier()) + .isEqualTo("toolchain-identifier-AA-piii"); + assertThat(create(loader, "--cpu=piii", "--glibc=target-libc-A").getToolchainIdentifier()) + .isEqualTo("toolchain-identifier-AA-piii"); // compiler-C uniquely identifies a toolchain, so we can use it. - assertEquals( - "toolchain-identifier-BC", - create(loader, "--cpu=k8", "--compiler=compiler-C").getToolchainIdentifier()); + assertThat(create(loader, "--cpu=k8", "--compiler=compiler-C").getToolchainIdentifier()) + .isEqualTo("toolchain-identifier-BC"); try { create(loader, "--cpu=k8", "--compiler=nonexistent-compiler"); @@ -1013,14 +1006,16 @@ public class CrosstoolConfigurationLoaderTest extends AnalysisTestCase { ctTop = PackageIdentifier.createInMainRepo(ctTop.getPackageFragment()); } CppConfiguration defaultLibs = create(loader, "--cpu=piii"); - assertEquals( - Label.create(ctTop, "static-runtime-libs-piii"), defaultLibs.getStaticRuntimeLibsLabel()); - assertEquals( - Label.create(ctTop, "dynamic-runtime-libs-piii"), defaultLibs.getDynamicRuntimeLibsLabel()); + assertThat(defaultLibs.getStaticRuntimeLibsLabel()) + .isEqualTo(Label.create(ctTop, "static-runtime-libs-piii")); + assertThat(defaultLibs.getDynamicRuntimeLibsLabel()) + .isEqualTo(Label.create(ctTop, "dynamic-runtime-libs-piii")); CppConfiguration customLibs = create(loader, "--cpu=k8"); - assertEquals(Label.create(ctTop, "static-group"), customLibs.getStaticRuntimeLibsLabel()); - assertEquals(Label.create(ctTop, "dynamic-group"), customLibs.getDynamicRuntimeLibsLabel()); + assertThat(customLibs.getStaticRuntimeLibsLabel()) + .isEqualTo(Label.create(ctTop, "static-group")); + assertThat(customLibs.getDynamicRuntimeLibsLabel()) + .isEqualTo(Label.create(ctTop, "dynamic-group")); } /* @@ -1035,7 +1030,7 @@ public class CrosstoolConfigurationLoaderTest extends AnalysisTestCase { CppConfiguration cppConfig = create(loader, "--cpu=cpu"); ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); cppConfig.addGlobalMakeVariables(builder); - assertNotNull(builder.build().get("GCOVTOOL")); + assertThat(builder.build().get("GCOVTOOL")).isNotNull(); // Crosstool without gcov-tool loader = loaderWithOptionalTool(""); diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/LTOBackendActionTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/LTOBackendActionTest.java index d5f471e87b..4b2bebf212 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/LTOBackendActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/LTOBackendActionTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.rules.cpp; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -93,12 +92,14 @@ public class LTOBackendActionTest extends BuildViewTestCase { .build(ActionsTestUtil.NULL_ACTION_OWNER, collectingAnalysisEnvironment, targetConfig); collectingAnalysisEnvironment.registerAction(actions); LTOBackendAction action = (LTOBackendAction) actions[0]; - assertEquals(ActionsTestUtil.NULL_ACTION_OWNER.getLabel(), action.getOwner().getLabel()); + assertThat(action.getOwner().getLabel()) + .isEqualTo(ActionsTestUtil.NULL_ACTION_OWNER.getLabel()); assertThat(action.getInputs()).containsExactly(bitcode1Artifact, index1Artifact); assertThat(action.getOutputs()).containsExactly(destinationArtifact); - assertEquals(AbstractAction.DEFAULT_RESOURCE_SET, action.getSpawn().getLocalResources()); + assertThat(action.getSpawn().getLocalResources()) + .isEqualTo(AbstractAction.DEFAULT_RESOURCE_SET); assertThat(action.getArguments()).containsExactly("/bin/clang"); - assertEquals("Test", action.getProgressMessage()); + assertThat(action.getProgressMessage()).isEqualTo("Test"); assertThat(action.inputsDiscovered()).isFalse(); // Discover inputs, which should not add any inputs since bitcode1.imports is empty. @@ -120,12 +121,14 @@ public class LTOBackendActionTest extends BuildViewTestCase { .build(ActionsTestUtil.NULL_ACTION_OWNER, collectingAnalysisEnvironment, targetConfig); collectingAnalysisEnvironment.registerAction(actions); LTOBackendAction action = (LTOBackendAction) actions[0]; - assertEquals(ActionsTestUtil.NULL_ACTION_OWNER.getLabel(), action.getOwner().getLabel()); + assertThat(action.getOwner().getLabel()) + .isEqualTo(ActionsTestUtil.NULL_ACTION_OWNER.getLabel()); assertThat(action.getInputs()).containsExactly(bitcode2Artifact, index2Artifact); assertThat(action.getOutputs()).containsExactly(destinationArtifact); - assertEquals(AbstractAction.DEFAULT_RESOURCE_SET, action.getSpawn().getLocalResources()); + assertThat(action.getSpawn().getLocalResources()) + .isEqualTo(AbstractAction.DEFAULT_RESOURCE_SET); assertThat(action.getArguments()).containsExactly("/bin/clang"); - assertEquals("Test", action.getProgressMessage()); + assertThat(action.getProgressMessage()).isEqualTo("Test"); assertThat(action.inputsDiscovered()).isFalse(); // Discover inputs, which should add bitcode1.o which is listed in bitcode2.imports. diff --git a/src/test/java/com/google/devtools/build/lib/util/AnsiStrippingOutputStreamTest.java b/src/test/java/com/google/devtools/build/lib/util/AnsiStrippingOutputStreamTest.java index 5ca0444386..ce1f6d79ee 100644 --- a/src/test/java/com/google/devtools/build/lib/util/AnsiStrippingOutputStreamTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/AnsiStrippingOutputStreamTest.java @@ -13,17 +13,16 @@ // limitations under the License. package com.google.devtools.build.lib.util; -import static org.junit.Assert.assertEquals; +import static com.google.common.truth.Truth.assertThat; +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.io.PrintStream; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.io.ByteArrayOutputStream; -import java.io.OutputStream; -import java.io.PrintStream; - /** * Tests for {@link AnsiStrippingOutputStream}. */ @@ -51,34 +50,32 @@ public class AnsiStrippingOutputStreamTest { @Test public void doesNotFailHorribly() throws Exception { - assertEquals("Love", getOutput("Love")); + assertThat(getOutput("Love")).isEqualTo("Love"); } @Test public void canStripAnsiCode() throws Exception { - assertEquals("Love", getOutput(ESCAPE + "32mLove" + ESCAPE + "m")); + assertThat(getOutput(ESCAPE + "32mLove" + ESCAPE + "m")).isEqualTo("Love"); } @Test public void recognizesAnsiCodeWhenBrokenUp() throws Exception { - assertEquals("Love", getOutput("\u001b", "[", "mLove")); + assertThat(getOutput("\u001b", "[", "mLove")).isEqualTo("Love"); } @Test public void handlesOnlyEscCorrectly() throws Exception { - assertEquals("\u001bLove", getOutput("\u001bLove")); + assertThat(getOutput("\u001bLove")).isEqualTo("\u001bLove"); } @Test public void handlesEscInPlaceOfControlCharCorrectly() throws Exception { - assertEquals(ESCAPE + "31;42Love", - getOutput(ESCAPE + "31;42" + ESCAPE + "1mLove")); + assertThat(getOutput(ESCAPE + "31;42" + ESCAPE + "1mLove")).isEqualTo(ESCAPE + "31;42Love"); } @Test public void handlesTwoEscapeSequencesCorrectly() throws Exception { - assertEquals("Love", - getOutput(ESCAPE + "32m" + ESCAPE + "1m" + "Love")); + assertThat(getOutput(ESCAPE + "32m" + ESCAPE + "1m" + "Love")).isEqualTo("Love"); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/CommandFailureUtilsTest.java b/src/test/java/com/google/devtools/build/lib/util/CommandFailureUtilsTest.java index 8c1cd2a5ff..7ce30ec51d 100644 --- a/src/test/java/com/google/devtools/build/lib/util/CommandFailureUtilsTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/CommandFailureUtilsTest.java @@ -13,15 +13,14 @@ // limitations under the License. package com.google.devtools.build.lib.util; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import static com.google.common.truth.Truth.assertThat; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class CommandFailureUtilsTest { @@ -40,28 +39,28 @@ public class CommandFailureUtilsTest { env.put("FOO", "foo"); String cwd = "/my/working/directory"; String message = CommandFailureUtils.describeCommandError(false, Arrays.asList(args), env, cwd); - String verboseMessage = CommandFailureUtils.describeCommandError(true, Arrays.asList(args), env, - cwd); - assertEquals( - "error executing command some_command arg1 " - + "arg2 arg3 arg4 arg5 arg6 'with spaces' arg8 '*' arg10 " - + "arg11 arg12 arg13 arg14 arg15 arg16 arg17 arg18 " - + "arg19 arg20 arg21 arg22 arg23 arg24 arg25 arg26 " - + "arg27 arg28 arg29 arg30 arg31 " - + "... (remaining 8 argument(s) skipped)", - message); - assertEquals( - "error executing command \n" - + " (cd /my/working/directory && \\\n" - + " exec env - \\\n" - + " FOO=foo \\\n" - + " PATH=/usr/bin:/bin:/sbin \\\n" - + " some_command arg1 arg2 arg3 arg4 arg5 arg6 'with spaces' arg8 '*' arg10 " - + "arg11 arg12 arg13 arg14 arg15 arg16 arg17 arg18 " - + "arg19 arg20 arg21 arg22 arg23 arg24 arg25 arg26 " - + "arg27 arg28 arg29 arg30 arg31 arg32 arg33 arg34 " - + "arg35 arg36 arg37 arg38 arg39)", - verboseMessage); + String verboseMessage = + CommandFailureUtils.describeCommandError(true, Arrays.asList(args), env, cwd); + assertThat(message) + .isEqualTo( + "error executing command some_command arg1 " + + "arg2 arg3 arg4 arg5 arg6 'with spaces' arg8 '*' arg10 " + + "arg11 arg12 arg13 arg14 arg15 arg16 arg17 arg18 " + + "arg19 arg20 arg21 arg22 arg23 arg24 arg25 arg26 " + + "arg27 arg28 arg29 arg30 arg31 " + + "... (remaining 8 argument(s) skipped)"); + assertThat(verboseMessage) + .isEqualTo( + "error executing command \n" + + " (cd /my/working/directory && \\\n" + + " exec env - \\\n" + + " FOO=foo \\\n" + + " PATH=/usr/bin:/bin:/sbin \\\n" + + " some_command arg1 arg2 arg3 arg4 arg5 arg6 'with spaces' arg8 '*' arg10 " + + "arg11 arg12 arg13 arg14 arg15 arg16 arg17 arg18 " + + "arg19 arg20 arg21 arg22 arg23 arg24 arg25 arg26 " + + "arg27 arg28 arg29 arg30 arg31 arg32 arg33 arg34 " + + "arg35 arg36 arg37 arg38 arg39)"); } @Test @@ -74,20 +73,20 @@ public class CommandFailureUtilsTest { env.put("FOO", "foo"); env.put("PATH", "/usr/bin:/bin:/sbin"); String cwd = null; - String message = CommandFailureUtils.describeCommandFailure(false, Arrays.asList(args), - env, cwd); - String verboseMessage = CommandFailureUtils.describeCommandFailure(true, Arrays.asList(args), - env, cwd); - assertEquals( - "sh failed: error executing command " - + "/bin/sh -c 'echo Some errors 1>&2; echo Some output; exit 42'", - message); - assertEquals( - "sh failed: error executing command \n" - + " (exec env - \\\n" - + " FOO=foo \\\n" - + " PATH=/usr/bin:/bin:/sbin \\\n" - + " /bin/sh -c 'echo Some errors 1>&2; echo Some output; exit 42')", - verboseMessage); + String message = + CommandFailureUtils.describeCommandFailure(false, Arrays.asList(args), env, cwd); + String verboseMessage = + CommandFailureUtils.describeCommandFailure(true, Arrays.asList(args), env, cwd); + assertThat(message) + .isEqualTo( + "sh failed: error executing command " + + "/bin/sh -c 'echo Some errors 1>&2; echo Some output; exit 42'"); + assertThat(verboseMessage) + .isEqualTo( + "sh failed: error executing command \n" + + " (exec env - \\\n" + + " FOO=foo \\\n" + + " PATH=/usr/bin:/bin:/sbin \\\n" + + " /bin/sh -c 'echo Some errors 1>&2; echo Some output; exit 42')"); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/CommandUtilsTest.java b/src/test/java/com/google/devtools/build/lib/util/CommandUtilsTest.java index f226383492..fde8fb71ee 100644 --- a/src/test/java/com/google/devtools/build/lib/util/CommandUtilsTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/CommandUtilsTest.java @@ -13,20 +13,18 @@ // limitations under the License. package com.google.devtools.build.lib.util; -import static org.junit.Assert.assertEquals; +import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.fail; import com.google.common.collect.Maps; import com.google.devtools.build.lib.shell.Command; import com.google.devtools.build.lib.shell.CommandException; - +import java.io.File; +import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.io.File; -import java.util.Map; - @RunWith(JUnit4.class) public class CommandUtilsTest { @@ -47,27 +45,27 @@ public class CommandUtilsTest { } catch (CommandException exception) { String message = CommandUtils.describeCommandError(false, exception.getCommand()); String verboseMessage = CommandUtils.describeCommandError(true, exception.getCommand()); - assertEquals( - "error executing command this_command_will_not_be_found arg1 " - + "arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10 " - + "arg11 arg12 arg13 arg14 arg15 arg16 arg17 arg18 " - + "arg19 arg20 arg21 arg22 arg23 arg24 arg25 arg26 " - + "arg27 arg28 arg29 arg30 " - + "... (remaining 9 argument(s) skipped)", - message); - assertEquals( - "error executing command \n" - + " (cd /tmp && \\\n" - + " exec env - \\\n" - + " FOO=foo \\\n" - + " PATH=/usr/bin:/bin:/sbin \\\n" - + " this_command_will_not_be_found arg1 " - + "arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10 " - + "arg11 arg12 arg13 arg14 arg15 arg16 arg17 arg18 " - + "arg19 arg20 arg21 arg22 arg23 arg24 arg25 arg26 " - + "arg27 arg28 arg29 arg30 arg31 arg32 arg33 arg34 " - + "arg35 arg36 arg37 arg38 arg39)", - verboseMessage); + assertThat(message) + .isEqualTo( + "error executing command this_command_will_not_be_found arg1 " + + "arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10 " + + "arg11 arg12 arg13 arg14 arg15 arg16 arg17 arg18 " + + "arg19 arg20 arg21 arg22 arg23 arg24 arg25 arg26 " + + "arg27 arg28 arg29 arg30 " + + "... (remaining 9 argument(s) skipped)"); + assertThat(verboseMessage) + .isEqualTo( + "error executing command \n" + + " (cd /tmp && \\\n" + + " exec env - \\\n" + + " FOO=foo \\\n" + + " PATH=/usr/bin:/bin:/sbin \\\n" + + " this_command_will_not_be_found arg1 " + + "arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10 " + + "arg11 arg12 arg13 arg14 arg15 arg16 arg17 arg18 " + + "arg19 arg20 arg21 arg22 arg23 arg24 arg25 arg26 " + + "arg27 arg28 arg29 arg30 arg31 arg32 arg33 arg34 " + + "arg35 arg36 arg37 arg38 arg39)"); } } @@ -86,23 +84,23 @@ public class CommandUtilsTest { } catch (CommandException exception) { String message = CommandUtils.describeCommandFailure(false, exception); String verboseMessage = CommandUtils.describeCommandFailure(true, exception); - assertEquals( - "sh failed: error executing command " + - "/bin/sh -c 'echo Some errors 1>&2; echo Some output; exit 42': " + - "Process exited with status 42\n" + - "Some output\n" + - "Some errors\n", - message); - assertEquals( - "sh failed: error executing command \n" + - " (exec env - \\\n" + - " FOO=foo \\\n" + - " PATH=/usr/bin:/bin:/sbin \\\n" + - " /bin/sh -c 'echo Some errors 1>&2; echo Some output; exit 42'): " + - "Process exited with status 42\n" + - "Some output\n" + - "Some errors\n", - verboseMessage); + assertThat(message) + .isEqualTo( + "sh failed: error executing command " + + "/bin/sh -c 'echo Some errors 1>&2; echo Some output; exit 42': " + + "Process exited with status 42\n" + + "Some output\n" + + "Some errors\n"); + assertThat(verboseMessage) + .isEqualTo( + "sh failed: error executing command \n" + + " (exec env - \\\n" + + " FOO=foo \\\n" + + " PATH=/usr/bin:/bin:/sbin \\\n" + + " /bin/sh -c 'echo Some errors 1>&2; echo Some output; exit 42'): " + + "Process exited with status 42\n" + + "Some output\n" + + "Some errors\n"); } } } diff --git a/src/test/java/com/google/devtools/build/lib/util/DependencySetTest.java b/src/test/java/com/google/devtools/build/lib/util/DependencySetTest.java index d8e2b274d8..b2ad2b9776 100644 --- a/src/test/java/com/google/devtools/build/lib/util/DependencySetTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/DependencySetTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.util; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; @@ -52,7 +51,7 @@ public class DependencySetTest { " " + file2 + " "); DependencySet depset = newDependencySet().read(dotd); assertThat(depset.getDependencies()).containsExactlyElementsIn(Sets.newHashSet(file1, file2)); - assertEquals(depset.getOutputFileName(), filename); + assertThat(filename).isEqualTo(depset.getOutputFileName()); } @Test @@ -66,7 +65,7 @@ public class DependencySetTest { " " + file2 + " "); DependencySet depset = newDependencySet().read(dotd); assertThat(depset.getDependencies()).containsExactlyElementsIn(Sets.newHashSet(file1, file2)); - assertEquals(depset.getOutputFileName(), filename); + assertThat(filename).isEqualTo(depset.getOutputFileName()); } @Test @@ -74,13 +73,11 @@ public class DependencySetTest { Path file1 = fileSystem.getPath("/usr/local/blah/blah/genhello/hello.cc"); Path file2 = fileSystem.getPath("/usr/local/blah/blah/genhello/hello.h"); String filename = "hello.o"; - Path dotd = scratch.file("/tmp/foo.d", - filename + ": \\\r" - + " " + file1 + " \\\r" - + " " + file2 + " "); + Path dotd = + scratch.file("/tmp/foo.d", filename + ": \\\r " + file1 + " \\\r " + file2 + " "); DependencySet depset = newDependencySet().read(dotd); assertThat(depset.getDependencies()).containsExactlyElementsIn(Sets.newHashSet(file1, file2)); - assertEquals(depset.getOutputFileName(), filename); + assertThat(filename).isEqualTo(depset.getOutputFileName()); } @Test @@ -88,13 +85,13 @@ public class DependencySetTest { Path file1 = fileSystem.getPath("/usr/local/blah/blah/genhello/hello.cc"); Path file2 = fileSystem.getPath("/usr/local/blah/blah/genhello/hello.h"); String filename = "hello.o"; - Path dotd = scratch.file("/tmp/foo.d", - "\r\n" + filename + ": \\\r\n" - + " " + file1 + " \\\r\n" - + " " + file2 + " "); + Path dotd = + scratch.file( + "/tmp/foo.d", + "\r\n" + filename + ": \\\r\n " + file1 + " \\\r\n " + file2 + " "); DependencySet depset = newDependencySet().read(dotd); assertThat(depset.getDependencies()).containsExactlyElementsIn(Sets.newHashSet(file1, file2)); - assertEquals(depset.getOutputFileName(), filename); + assertThat(filename).isEqualTo(depset.getOutputFileName()); } @Test @@ -111,7 +108,7 @@ public class DependencySetTest { DependencySet depset = newDependencySet().read(dotd); assertThat(depset.getDependencies()) .containsExactlyElementsIn(Sets.newHashSet(file1, file2, file3, file4)); - assertEquals(depset.getOutputFileName(), filename); + assertThat(filename).isEqualTo(depset.getOutputFileName()); } @Test @@ -125,7 +122,7 @@ public class DependencySetTest { " " + file2.relativeTo(root) + " "); DependencySet depset = newDependencySet().read(dotd); assertThat(depset.getDependencies()).containsExactlyElementsIn(Sets.newHashSet(file1, file2)); - assertEquals(depset.getOutputFileName(), filename); + assertThat(filename).isEqualTo(depset.getOutputFileName()); } @Test @@ -136,7 +133,7 @@ public class DependencySetTest { if (!headers.isEmpty()) { fail("Not empty: " + headers.size() + " " + headers); } - assertEquals(depset.getOutputFileName(), null); + assertThat(depset.getOutputFileName()).isNull(); } @Test @@ -203,7 +200,7 @@ public class DependencySetTest { " " + file2 + " "); DependencySet depset = newDependencySet().read(dotd); assertThat(depset.getDependencies()).containsExactlyElementsIn(Sets.newHashSet(file1, file2)); - assertEquals(depset.getOutputFileName(), filename); + assertThat(filename).isEqualTo(depset.getOutputFileName()); } /* @@ -240,12 +237,12 @@ public class DependencySetTest { String dotdContents = new String(FileSystemUtils.readContentAsLatin1(dotd)); String expected = - "usr/local/blah/blah/genhello/hello.o: \\\n" + - " /usr/local/blah/blah/genhello/hello.cc \\\n" + - " /usr/local/blah/blah/genhello/hello.h \\\n" + - " /usr/local/blah/blah/genhello/other.h\n"; - assertEquals(expected, dotdContents); - assertEquals(filename, depSet1.getOutputFileName()); + "usr/local/blah/blah/genhello/hello.o: \\\n" + + " /usr/local/blah/blah/genhello/hello.cc \\\n" + + " /usr/local/blah/blah/genhello/hello.h \\\n" + + " /usr/local/blah/blah/genhello/other.h\n"; + assertThat(dotdContents).isEqualTo(expected); + assertThat(depSet1.getOutputFileName()).isEqualTo(filename); } @Test @@ -263,9 +260,9 @@ public class DependencySetTest { depSet1.write(dotd, ".d"); DependencySet depSet2 = newDependencySet().read(dotd); - assertEquals(depSet1, depSet2); + assertThat(depSet2).isEqualTo(depSet1); // due to how pic.d files are written, absolute paths are changed into relatives - assertEquals(depSet1.getOutputFileName(), "/" + depSet2.getOutputFileName()); + assertThat("/" + depSet2.getOutputFileName()).isEqualTo(depSet1.getOutputFileName()); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/FileTypeTest.java b/src/test/java/com/google/devtools/build/lib/util/FileTypeTest.java index bb13d18bef..f3da4d6b58 100644 --- a/src/test/java/com/google/devtools/build/lib/util/FileTypeTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/FileTypeTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.util; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import com.google.common.base.Joiner; import com.google.common.base.Predicate; @@ -116,17 +115,18 @@ public class FileTypeTest { @Test public void justJava() { - assertEquals("Foo.java", filterAll(JAVA_SOURCE)); + assertThat(filterAll(JAVA_SOURCE)).isEqualTo("Foo.java"); } @Test public void javaAndCpp() { - assertEquals("Foo.java bar.cc", filterAll(JAVA_SOURCE, CPP_SOURCE)); + assertThat(filterAll(JAVA_SOURCE, CPP_SOURCE)).isEqualTo("Foo.java bar.cc"); } @Test public void allThree() { - assertEquals("Foo.java bar.cc baz.py", filterAll(JAVA_SOURCE, CPP_SOURCE, PYTHON_SOURCE)); + assertThat(filterAll(JAVA_SOURCE, CPP_SOURCE, PYTHON_SOURCE)) + .isEqualTo("Foo.java bar.cc baz.py"); } private HasFilename filename(final String name) { diff --git a/src/test/java/com/google/devtools/build/lib/util/OptionsUtilsTest.java b/src/test/java/com/google/devtools/build/lib/util/OptionsUtilsTest.java index f7cac8c3fa..5a3a8b62e2 100644 --- a/src/test/java/com/google/devtools/build/lib/util/OptionsUtilsTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/OptionsUtilsTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.util; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.common.collect.Lists; @@ -74,7 +73,7 @@ public class OptionsUtilsTest { public void asStringOfExplicitOptions() throws Exception { OptionsParser parser = OptionsParser.newOptionsParser(IntrospectionExample.class); parser.parse("--alpha=no", "--gamma=no", "--echo=no"); - assertEquals("--alpha=no --gamma=no", OptionsUtils.asShellEscapedString(parser)); + assertThat(OptionsUtils.asShellEscapedString(parser)).isEqualTo("--alpha=no --gamma=no"); assertThat(OptionsUtils.asArgumentList(parser)) .containsExactly("--alpha=no", "--gamma=no") .inOrder(); @@ -85,7 +84,7 @@ public class OptionsUtilsTest { OptionsParser parser = OptionsParser.newOptionsParser(IntrospectionExample.class); parser.parse(OptionPriority.COMMAND_LINE, null, Arrays.asList("--alpha=no")); parser.parse(OptionPriority.COMPUTED_DEFAULT, null, Arrays.asList("--beta=no")); - assertEquals("--beta=no --alpha=no", OptionsUtils.asShellEscapedString(parser)); + assertThat(OptionsUtils.asShellEscapedString(parser)).isEqualTo("--beta=no --alpha=no"); assertThat(OptionsUtils.asArgumentList(parser)) .containsExactly("--beta=no", "--alpha=no") .inOrder(); @@ -107,7 +106,7 @@ public class OptionsUtilsTest { public void asStringOfExplicitOptionsWithBooleans() throws Exception { OptionsParser parser = OptionsParser.newOptionsParser(BooleanOpts.class); parser.parse(OptionPriority.COMMAND_LINE, null, Arrays.asList("--b_one", "--nob_two")); - assertEquals("--b_one --nob_two", OptionsUtils.asShellEscapedString(parser)); + assertThat(OptionsUtils.asShellEscapedString(parser)).isEqualTo("--b_one --nob_two"); assertThat(OptionsUtils.asArgumentList(parser)) .containsExactly("--b_one", "--nob_two") .inOrder(); @@ -116,7 +115,7 @@ public class OptionsUtilsTest { parser.parse(OptionPriority.COMMAND_LINE, null, Arrays.asList("--b_one=true", "--b_two=0")); assertThat(parser.getOptions(BooleanOpts.class).bOne).isTrue(); assertThat(parser.getOptions(BooleanOpts.class).bTwo).isFalse(); - assertEquals("--b_one --nob_two", OptionsUtils.asShellEscapedString(parser)); + assertThat(OptionsUtils.asShellEscapedString(parser)).isEqualTo("--b_one --nob_two"); assertThat(OptionsUtils.asArgumentList(parser)) .containsExactly("--b_one", "--nob_two") .inOrder(); @@ -127,7 +126,7 @@ public class OptionsUtilsTest { OptionsParser parser = OptionsParser.newOptionsParser(IntrospectionExample.class); parser.parse(OptionPriority.COMMAND_LINE, null, Arrays.asList("--alpha=one")); parser.parse(OptionPriority.COMMAND_LINE, null, Arrays.asList("--alpha=two")); - assertEquals("--alpha=one --alpha=two", OptionsUtils.asShellEscapedString(parser)); + assertThat(OptionsUtils.asShellEscapedString(parser)).isEqualTo("--alpha=one --alpha=two"); assertThat(OptionsUtils.asArgumentList(parser)) .containsExactly("--alpha=one", "--alpha=two") .inOrder(); @@ -147,23 +146,25 @@ public class OptionsUtilsTest { @Test public void emptyStringYieldsEmptyList() throws Exception { - assertEquals(list(), convert("")); + assertThat(convert("")).isEqualTo(list()); } @Test public void lonelyDotYieldsLonelyDot() throws Exception { - assertEquals(list(fragment(".")), convert(".")); + assertThat(convert(".")).containsExactly(fragment(".")); } @Test public void converterSkipsEmptyStrings() throws Exception { - assertEquals(list(fragment("foo"), fragment("bar")), convert("foo::bar:")); + assertThat(convert("foo::bar:")).containsExactly(fragment("foo"), fragment("bar")).inOrder(); } @Test public void multiplePaths() throws Exception { - assertEquals(list(fragment("foo"), fragment("/bar/baz"), fragment("."), - fragment("/tmp/bang")), convert("foo:/bar/baz:.:/tmp/bang")); + assertThat(convert("foo:/bar/baz:.:/tmp/bang")) + .containsExactly( + fragment("foo"), fragment("/bar/baz"), fragment("."), fragment("/tmp/bang")) + .inOrder(); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/util/PairTest.java b/src/test/java/com/google/devtools/build/lib/util/PairTest.java index 2dd9c80cbc..15879b44d4 100644 --- a/src/test/java/com/google/devtools/build/lib/util/PairTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/PairTest.java @@ -14,8 +14,8 @@ package com.google.devtools.build.lib.util; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; +import com.google.common.testing.EqualsTester; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -33,7 +33,7 @@ public class PairTest { Pair<Object, Object> p = Pair.of(a, b); assertThat(p.first).isSameAs(a); assertThat(p.second).isSameAs(b); - assertEquals(Pair.of(a, b), p); + assertThat(p).isEqualTo(Pair.of(a, b)); assertThat(p.hashCode()).isEqualTo(31 * a.hashCode() + b.hashCode()); } @@ -43,6 +43,6 @@ public class PairTest { assertThat(p.first).isNull(); assertThat(p.second).isNull(); p.hashCode(); // Should not throw. - assertEquals(p, p); + new EqualsTester().addEqualityGroup(p).testEquals(); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/PathFragmentFilterTest.java b/src/test/java/com/google/devtools/build/lib/util/PathFragmentFilterTest.java index 2d514340e4..c9a2b3f789 100644 --- a/src/test/java/com/google/devtools/build/lib/util/PathFragmentFilterTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/PathFragmentFilterTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.util; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import com.google.devtools.build.lib.vfs.PathFragment; import org.junit.Test; @@ -87,7 +86,7 @@ public class PathFragmentFilterTest { assertExcluded("e"); // When converted back to string, inclusion entries will be put first, followed by exclusion // entries. - assertEquals("a,d,a/b/c,a/b/d,-c,-a/b", filter.toString()); + assertThat(filter.toString()).isEqualTo("a,d,a/b/c,a/b/d,-c,-a/b"); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/RegexFilterTest.java b/src/test/java/com/google/devtools/build/lib/util/RegexFilterTest.java index 503d065827..c00cbc459a 100644 --- a/src/test/java/com/google/devtools/build/lib/util/RegexFilterTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/RegexFilterTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.util; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.common.testing.EqualsTester; @@ -53,7 +52,7 @@ public class RegexFilterTest { @Test public void inclusions() throws Exception { createFilter("a/b,+^c,_test$"); - assertEquals("(?:(?>a/b)|(?>^c)|(?>_test$))", filter.toString()); + assertThat(filter.toString()).isEqualTo("(?:(?>a/b)|(?>^c)|(?>_test$))"); assertIncluded("a/b"); assertIncluded("a/b/c"); assertIncluded("c"); @@ -70,7 +69,7 @@ public class RegexFilterTest { @Test public void exclusions() throws Exception { createFilter("-a/b,-^c,-_test$"); - assertEquals("-(?:(?>a/b)|(?>^c)|(?>_test$))", filter.toString()); + assertThat(filter.toString()).isEqualTo("-(?:(?>a/b)|(?>^c)|(?>_test$))"); assertExcluded("a/b"); assertExcluded("a/b/c"); assertExcluded("c"); @@ -87,7 +86,8 @@ public class RegexFilterTest { @Test public void inclusionsAndExclusions() throws Exception { createFilter("a,-^c,,-,+,d,+a/b/c,-a/b,a/b/d"); - assertEquals("(?:(?>a)|(?>d)|(?>a/b/c)|(?>a/b/d)),-(?:(?>^c)|(?>a/b))", filter.toString()); + assertThat(filter.toString()) + .isEqualTo("(?:(?>a)|(?>d)|(?>a/b/c)|(?>a/b/d)),-(?:(?>^c)|(?>a/b))"); assertIncluded("a"); assertIncluded("a/c"); assertExcluded("a/b"); @@ -103,7 +103,7 @@ public class RegexFilterTest { @Test public void commas() throws Exception { createFilter("a\\,b,c\\,d"); - assertEquals("(?:(?>a\\,b)|(?>c\\,d))", filter.toString()); + assertThat(filter.toString()).isEqualTo("(?:(?>a\\,b)|(?>c\\,d))"); assertIncluded("a,b"); assertIncluded("c,d"); assertExcluded("a"); diff --git a/src/test/java/com/google/devtools/build/lib/util/ResourceFileLoaderTest.java b/src/test/java/com/google/devtools/build/lib/util/ResourceFileLoaderTest.java index d1e2889887..0f00b75909 100644 --- a/src/test/java/com/google/devtools/build/lib/util/ResourceFileLoaderTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/ResourceFileLoaderTest.java @@ -14,15 +14,13 @@ package com.google.devtools.build.lib.util; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import java.io.IOException; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.io.IOException; - /** * A test for {@link ResourceFileLoader}. */ @@ -33,7 +31,7 @@ public class ResourceFileLoaderTest { public void loader() throws IOException { String message = ResourceFileLoader.loadResource( ResourceFileLoaderTest.class, "ResourceFileLoaderTest.message"); - assertEquals("Hello, world.", message); + assertThat(message).isEqualTo("Hello, world."); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/util/ShellEscaperTest.java b/src/test/java/com/google/devtools/build/lib/util/ShellEscaperTest.java index ad8f336dd7..cad9ce53f2 100644 --- a/src/test/java/com/google/devtools/build/lib/util/ShellEscaperTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/ShellEscaperTest.java @@ -13,19 +13,17 @@ // limitations under the License. package com.google.devtools.build.lib.util; +import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.util.ShellEscaper.escapeString; -import static org.junit.Assert.assertEquals; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableSet; - +import java.util.Arrays; +import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.util.Arrays; -import java.util.Set; - /** * Tests for {@link ShellEscaper}. * @@ -36,41 +34,42 @@ public class ShellEscaperTest { @Test public void shellEscape() throws Exception { - assertEquals("''", escapeString("")); - assertEquals("foo", escapeString("foo")); - assertEquals("'foo bar'", escapeString("foo bar")); - assertEquals("''\\''foo'\\'''", escapeString("'foo'")); - assertEquals("'\\'\\''foo\\'\\'''", escapeString("\\'foo\\'")); - assertEquals("'${filename%.c}.o'", escapeString("${filename%.c}.o")); - assertEquals("'<html!>'", escapeString("<html!>")); + assertThat(escapeString("")).isEqualTo("''"); + assertThat(escapeString("foo")).isEqualTo("foo"); + assertThat(escapeString("foo bar")).isEqualTo("'foo bar'"); + assertThat(escapeString("'foo'")).isEqualTo("''\\''foo'\\'''"); + assertThat(escapeString("\\'foo\\'")).isEqualTo("'\\'\\''foo\\'\\'''"); + assertThat(escapeString("${filename%.c}.o")).isEqualTo("'${filename%.c}.o'"); + assertThat(escapeString("<html!>")).isEqualTo("'<html!>'"); } @Test public void escapeAll() throws Exception { Set<String> escaped = ImmutableSet.copyOf( ShellEscaper.escapeAll(Arrays.asList("foo", "@bar", "baz'qux"))); - assertEquals(ImmutableSet.of("foo", "@bar", "'baz'\\''qux'"), escaped); + assertThat(escaped).containsExactly("foo", "@bar", "'baz'\\''qux'"); } @Test public void escapeJoinAllIntoAppendable() throws Exception { Appendable appendable = ShellEscaper.escapeJoinAll( new StringBuilder("initial"), Arrays.asList("foo", "$BAR")); - assertEquals("initialfoo '$BAR'", appendable.toString()); + assertThat(appendable.toString()).isEqualTo("initialfoo '$BAR'"); } @Test public void escapeJoinAllIntoAppendableWithCustomJoiner() throws Exception { Appendable appendable = ShellEscaper.escapeJoinAll( new StringBuilder("initial"), Arrays.asList("foo", "$BAR"), Joiner.on('|')); - assertEquals("initialfoo|'$BAR'", appendable.toString()); + assertThat(appendable.toString()).isEqualTo("initialfoo|'$BAR'"); } @Test public void escapeJoinAll() throws Exception { String actual = ShellEscaper.escapeJoinAll( Arrays.asList("foo", "@echo:-", "100", "$US", "a b", "\"qu'ot'es\"", "\"quot\"", "\\")); - assertEquals("foo @echo:- 100 '$US' 'a b' '\"qu'\\''ot'\\''es\"' '\"quot\"' '\\'", actual); + assertThat(actual) + .isEqualTo("foo @echo:- 100 '$US' 'a b' '\"qu'\\''ot'\\''es\"' '\"quot\"' '\\'"); } @Test @@ -78,6 +77,7 @@ public class ShellEscaperTest { String actual = ShellEscaper.escapeJoinAll( Arrays.asList("foo", "@echo:-", "100", "$US", "a b", "\"qu'ot'es\"", "\"quot\"", "\\"), Joiner.on('|')); - assertEquals("foo|@echo:-|100|'$US'|'a b'|'\"qu'\\''ot'\\''es\"'|'\"quot\"'|'\\'", actual); + assertThat(actual) + .isEqualTo("foo|@echo:-|100|'$US'|'a b'|'\"qu'\\''ot'\\''es\"'|'\"quot\"'|'\\'"); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/StringIndexerTest.java b/src/test/java/com/google/devtools/build/lib/util/StringIndexerTest.java index 9aeb907b72..01a6181fb1 100644 --- a/src/test/java/com/google/devtools/build/lib/util/StringIndexerTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/StringIndexerTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.util; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import com.google.common.base.Function; import com.google.common.base.Strings; @@ -112,7 +111,7 @@ public abstract class StringIndexerTest { } for (String key : keys) { // Validate mapping between keys and indices. - assertEquals(key, indexer.getStringForIndex(indexer.getIndex(key))); + assertThat(indexer.getStringForIndex(indexer.getIndex(key))).isEqualTo(key); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/StringUtilTest.java b/src/test/java/com/google/devtools/build/lib/util/StringUtilTest.java index 5331931b02..456e8276ac 100644 --- a/src/test/java/com/google/devtools/build/lib/util/StringUtilTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/StringUtilTest.java @@ -19,7 +19,6 @@ import static com.google.devtools.build.lib.util.StringUtil.indent; import static com.google.devtools.build.lib.util.StringUtil.joinEnglishList; import static com.google.devtools.build.lib.util.StringUtil.splitAndInternString; import static com.google.devtools.build.lib.util.StringUtil.stripSuffix; -import static org.junit.Assert.assertEquals; import com.google.common.collect.ImmutableList; import java.util.Arrays; @@ -35,20 +34,16 @@ public class StringUtilTest { @Test public void testJoinEnglishList() throws Exception { - assertEquals("nothing", - joinEnglishList(Collections.emptyList())); - assertEquals("one", - joinEnglishList(Arrays.asList("one"))); - assertEquals("one or two", - joinEnglishList(Arrays.asList("one", "two"))); - assertEquals("one and two", - joinEnglishList(Arrays.asList("one", "two"), "and")); - assertEquals("one, two or three", - joinEnglishList(Arrays.asList("one", "two", "three"))); - assertEquals("one, two and three", - joinEnglishList(Arrays.asList("one", "two", "three"), "and")); - assertEquals("'one', 'two' and 'three'", - joinEnglishList(Arrays.asList("one", "two", "three"), "and", "'")); + assertThat(joinEnglishList(Collections.emptyList())).isEqualTo("nothing"); + assertThat(joinEnglishList(Arrays.asList("one"))).isEqualTo("one"); + assertThat(joinEnglishList(Arrays.asList("one", "two"))).isEqualTo("one or two"); + assertThat(joinEnglishList(Arrays.asList("one", "two"), "and")).isEqualTo("one and two"); + assertThat(joinEnglishList(Arrays.asList("one", "two", "three"))) + .isEqualTo("one, two or three"); + assertThat(joinEnglishList(Arrays.asList("one", "two", "three"), "and")) + .isEqualTo("one, two and three"); + assertThat(joinEnglishList(Arrays.asList("one", "two", "three"), "and", "'")) + .isEqualTo("'one', 'two' and 'three'"); } @Test @@ -67,40 +62,47 @@ public class StringUtilTest { @Test public void listItemsWithLimit() throws Exception { - assertEquals("begin/a, b, c/end", StringUtil.listItemsWithLimit( - new StringBuilder("begin/"), 3, ImmutableList.of("a", "b", "c")).append("/end").toString()); + assertThat( + StringUtil.listItemsWithLimit( + new StringBuilder("begin/"), 3, ImmutableList.of("a", "b", "c")) + .append("/end") + .toString()) + .isEqualTo("begin/a, b, c/end"); - assertEquals("begin/a, b, c ...(omitting 2 more item(s))/end", StringUtil.listItemsWithLimit( - new StringBuilder("begin/"), 3, ImmutableList.of("a", "b", "c", "d", "e")) - .append("/end").toString()); + assertThat( + StringUtil.listItemsWithLimit( + new StringBuilder("begin/"), 3, ImmutableList.of("a", "b", "c", "d", "e")) + .append("/end") + .toString()) + .isEqualTo("begin/a, b, c ...(omitting 2 more item(s))/end"); } @Test public void testIndent() throws Exception { assertThat(indent("", 0)).isEmpty(); assertThat(indent("", 1)).isEmpty(); - assertEquals("a", indent("a", 1)); - assertEquals("\n a", indent("\na", 2)); - assertEquals("a\n b", indent("a\nb", 2)); - assertEquals("a\n b\n c\n d", indent("a\nb\nc\nd", 1)); - assertEquals("\n ", indent("\n", 1)); + assertThat(indent("a", 1)).isEqualTo("a"); + assertThat(indent("\na", 2)).isEqualTo("\n a"); + assertThat(indent("a\nb", 2)).isEqualTo("a\n b"); + assertThat(indent("a\nb\nc\nd", 1)).isEqualTo("a\n b\n c\n d"); + assertThat(indent("\n", 1)).isEqualTo("\n "); } @Test public void testStripSuffix() throws Exception { assertThat(stripSuffix("", "")).isEmpty(); assertThat(stripSuffix("", "a")).isNull(); - assertEquals("a", stripSuffix("a", "")); - assertEquals("a", stripSuffix("aa", "a")); + assertThat(stripSuffix("a", "")).isEqualTo("a"); + assertThat(stripSuffix("aa", "a")).isEqualTo("a"); assertThat(stripSuffix("ab", "c")).isNull(); } @Test public void testCapitalize() throws Exception { assertThat(capitalize("")).isEmpty(); - assertEquals("Joe", capitalize("joe")); - assertEquals("Joe", capitalize("Joe")); - assertEquals("O", capitalize("o")); - assertEquals("O", capitalize("O")); + assertThat(capitalize("joe")).isEqualTo("Joe"); + assertThat(capitalize("Joe")).isEqualTo("Joe"); + assertThat(capitalize("o")).isEqualTo("O"); + assertThat(capitalize("O")).isEqualTo("O"); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/StringUtilitiesTest.java b/src/test/java/com/google/devtools/build/lib/util/StringUtilitiesTest.java index c6ed9bff49..0b09fa6fca 100644 --- a/src/test/java/com/google/devtools/build/lib/util/StringUtilitiesTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/StringUtilitiesTest.java @@ -18,7 +18,6 @@ import static com.google.devtools.build.lib.util.StringUtilities.combineKeys; import static com.google.devtools.build.lib.util.StringUtilities.joinLines; import static com.google.devtools.build.lib.util.StringUtilities.layoutTable; import static com.google.devtools.build.lib.util.StringUtilities.prettyPrintBytes; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.common.collect.Maps; @@ -42,13 +41,13 @@ public class StringUtilitiesTest { @Test public void twoLinesGetjoinedNicely() { - assertEquals("line 1\nline 2", joinLines("line 1", "line 2")); + assertThat(joinLines("line 1", "line 2")).isEqualTo("line 1\nline 2"); } @Test public void aTrailingNewlineIsAvailableWhenYouNeedIt() { - assertEquals("two lines\nwith trailing newline\n", - joinLines("two lines", "with trailing newline", "")); + assertThat(joinLines("two lines", "with trailing newline", "")) + .isEqualTo("two lines\nwith trailing newline\n"); } // Tests of StringUtilities.combineKeys() @@ -56,7 +55,7 @@ public class StringUtilitiesTest { /** Simple sanity test of format */ @Test public void combineKeysFormat() { - assertEquals("<a><b!!c><!<d!>>", combineKeys("a", "b!c", "<d>")); + assertThat(combineKeys("a", "b!c", "<d>")).isEqualTo("<a><b!!c><!<d!>>"); } /** @@ -112,11 +111,9 @@ public class StringUtilitiesTest { @Test public void replaceAllLiteral() throws Exception { - assertEquals("ababab", - StringUtilities.replaceAllLiteral("bababa", "ba", "ab")); + assertThat(StringUtilities.replaceAllLiteral("bababa", "ba", "ab")).isEqualTo("ababab"); assertThat(StringUtilities.replaceAllLiteral("bababa", "ba", "")).isEmpty(); - assertEquals("bababa", - StringUtilities.replaceAllLiteral("bababa", "", "ab")); + assertThat(StringUtilities.replaceAllLiteral("bababa", "", "ab")).isEqualTo("bababa"); } @Test @@ -126,9 +123,8 @@ public class StringUtilitiesTest { data.put("bang", "baz"); data.put("lengthy key", "lengthy value"); - assertEquals(joinLines("bang: baz", - "foo: bar", - "lengthy key: lengthy value"), layoutTable(data)); + assertThat(layoutTable(data)) + .isEqualTo(joinLines("bang: baz", "foo: bar", "lengthy key: lengthy value")); } @Test @@ -151,17 +147,17 @@ public class StringUtilitiesTest { }; double x = 2.3456; for (int ii = 0; ii < expected.length; ++ii) { - assertEquals(expected[ii], prettyPrintBytes((long) x)); + assertThat(prettyPrintBytes((long) x)).isEqualTo(expected[ii]); x = x * 10.0; } } @Test public void sanitizeControlChars() { - assertEquals("<?>", StringUtilities.sanitizeControlChars("\000")); - assertEquals("<?>", StringUtilities.sanitizeControlChars("\001")); - assertEquals("\\r", StringUtilities.sanitizeControlChars("\r")); - assertEquals(" abc123", StringUtilities.sanitizeControlChars(" abc123")); + assertThat(StringUtilities.sanitizeControlChars("\000")).isEqualTo("<?>"); + assertThat(StringUtilities.sanitizeControlChars("\001")).isEqualTo("<?>"); + assertThat(StringUtilities.sanitizeControlChars("\r")).isEqualTo("\\r"); + assertThat(StringUtilities.sanitizeControlChars(" abc123")).isEqualTo(" abc123"); } @Test @@ -187,9 +183,9 @@ public class StringUtilitiesTest { @Test public void toPythonStyleFunctionName() { - assertEquals("a", StringUtilities.toPythonStyleFunctionName("a")); - assertEquals("a_b", StringUtilities.toPythonStyleFunctionName("aB")); - assertEquals("a_b_c", StringUtilities.toPythonStyleFunctionName("aBC")); - assertEquals("a_bc_d", StringUtilities.toPythonStyleFunctionName("aBcD")); + assertThat(StringUtilities.toPythonStyleFunctionName("a")).isEqualTo("a"); + assertThat(StringUtilities.toPythonStyleFunctionName("aB")).isEqualTo("a_b"); + assertThat(StringUtilities.toPythonStyleFunctionName("aBC")).isEqualTo("a_b_c"); + assertThat(StringUtilities.toPythonStyleFunctionName("aBcD")).isEqualTo("a_bc_d"); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/io/AnsiTerminalPrinterTest.java b/src/test/java/com/google/devtools/build/lib/util/io/AnsiTerminalPrinterTest.java index 886737ae81..56d871230d 100644 --- a/src/test/java/com/google/devtools/build/lib/util/io/AnsiTerminalPrinterTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/io/AnsiTerminalPrinterTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.util.io; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import com.google.devtools.build.lib.testutil.MoreAsserts; import com.google.devtools.build.lib.util.io.AnsiTerminalPrinter.Mode; @@ -43,7 +42,7 @@ public class AnsiTerminalPrinterTest { } private void assertString(String string) { - assertEquals(string, stream.toString()); + assertThat(stream.toString()).isEqualTo(string); } private void assertRegex(String regex) { @@ -79,7 +78,7 @@ public class AnsiTerminalPrinterTest { assertThat(codes).hasLength(8); for (int i = 0; i < 4; i++) { assertThat(codes[i]).isNotEmpty(); - assertEquals(codes[i], codes[i+4]); + assertThat(codes[i + 4]).isEqualTo(codes[i]); } assertThat(codes[0].equals(codes[1])).isFalse(); assertThat(codes[0].equals(codes[2])).isFalse(); diff --git a/src/test/java/com/google/devtools/build/lib/util/io/DelegatingOutErrTest.java b/src/test/java/com/google/devtools/build/lib/util/io/DelegatingOutErrTest.java index 84af87593c..738dadbc49 100644 --- a/src/test/java/com/google/devtools/build/lib/util/io/DelegatingOutErrTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/io/DelegatingOutErrTest.java @@ -13,8 +13,8 @@ // limitations under the License. package com.google.devtools.build.lib.util.io; +import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.util.StringUtilities.joinLines; -import static org.junit.Assert.assertEquals; import org.junit.After; import org.junit.Before; @@ -56,7 +56,7 @@ public class DelegatingOutErrTest { delegate.printOutLn("... and alone again ..."); delegate.addSink(sink); delegate.printOutLn("How are things?"); - assertEquals("Hello, sink.\nHow are things?\n", sink.outAsLatin1()); + assertThat(sink.outAsLatin1()).isEqualTo("Hello, sink.\nHow are things?\n"); } @Test @@ -74,9 +74,8 @@ public class DelegatingOutErrTest { delegate.addSink(left); delegate.addSink(right); delegate.printOutLn("left and right"); - assertEquals(joinLines("left only", "both", "left and right", ""), - left.outAsLatin1()); - assertEquals(joinLines("both", "right only", "left and right", ""), - right.outAsLatin1()); + assertThat(left.outAsLatin1()).isEqualTo(joinLines("left only", "both", "left and right", "")); + assertThat(right.outAsLatin1()) + .isEqualTo(joinLines("both", "right only", "left and right", "")); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/io/LinePrefixingOutputStreamTest.java b/src/test/java/com/google/devtools/build/lib/util/io/LinePrefixingOutputStreamTest.java index 543c16b00b..a77d120b1b 100644 --- a/src/test/java/com/google/devtools/build/lib/util/io/LinePrefixingOutputStreamTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/io/LinePrefixingOutputStreamTest.java @@ -15,15 +15,13 @@ package com.google.devtools.build.lib.util.io; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.Assert.assertEquals; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.io.ByteArrayOutputStream; -import java.io.IOException; - /** * Tests {@link LinePrefixingOutputStream}. */ @@ -52,22 +50,20 @@ public class LinePrefixingOutputStreamTest { public void testOutputIfFlushed() throws IOException { prefixOut.write(bytes("We'll flush after this line.")); prefixOut.flush(); - assertEquals("Prefix: We'll flush after this line.\n", - string(out.toByteArray())); + assertThat(string(out.toByteArray())).isEqualTo("Prefix: We'll flush after this line.\n"); } @Test public void testAutoflushUponNewline() throws IOException { prefixOut.write(bytes("Hello, newline.\n")); - assertEquals("Prefix: Hello, newline.\n", string(out.toByteArray())); + assertThat(string(out.toByteArray())).isEqualTo("Prefix: Hello, newline.\n"); } @Test public void testAutoflushUponEmbeddedNewLine() throws IOException { prefixOut.write(bytes("Hello line1.\nHello line2.\nHello line3.\n")); - assertEquals( - "Prefix: Hello line1.\nPrefix: Hello line2.\nPrefix: Hello line3.\n", - string(out.toByteArray())); + assertThat(string(out.toByteArray())) + .isEqualTo("Prefix: Hello line1.\nPrefix: Hello line2.\nPrefix: Hello line3.\n"); } @Test @@ -82,8 +78,7 @@ public class LinePrefixingOutputStreamTest { prefixOut.write(bytes(junk + junk)); prefixOut.write(bytes(junk + junk)); prefixOut.write(bytes("x")); - assertEquals("Prefix: " + junk + "\n" + "Prefix: " + junk + "\n" - + "Prefix: " + junk + "\n" + "Prefix: " + junk + "\n", - string(out.toByteArray())); + assertThat(string(out.toByteArray())).isEqualTo("Prefix: " + junk + "\nPrefix: " + junk + + "\nPrefix: " + junk + "\nPrefix: " + junk + "\n"); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/io/LineWrappingAnsiTerminalWriterTest.java b/src/test/java/com/google/devtools/build/lib/util/io/LineWrappingAnsiTerminalWriterTest.java index a7a39d2db0..0a2b5a64bb 100644 --- a/src/test/java/com/google/devtools/build/lib/util/io/LineWrappingAnsiTerminalWriterTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/io/LineWrappingAnsiTerminalWriterTest.java @@ -13,14 +13,13 @@ // limitations under the License. package com.google.devtools.build.lib.util.io; -import static org.junit.Assert.assertEquals; +import static com.google.common.truth.Truth.assertThat; +import java.io.IOException; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.io.IOException; - /** * Tests {@link LineWrappingAnsiTerminalWriter}. */ @@ -35,14 +34,14 @@ public class LineWrappingAnsiTerminalWriterTest { public void testSimpleLineWrapping() throws IOException { LoggingTerminalWriter terminal = new LoggingTerminalWriter(); (new LineWrappingAnsiTerminalWriter(terminal, 5, '+')).append("abcdefghij"); - assertEquals("abcd+" + NL + "efgh+" + NL + "ij", terminal.getTranscript()); + assertThat(terminal.getTranscript()).isEqualTo("abcd+" + NL + "efgh+" + NL + "ij"); } @Test public void testAlwaysWrap() throws IOException { LoggingTerminalWriter terminal = new LoggingTerminalWriter(); (new LineWrappingAnsiTerminalWriter(terminal, 5, '+')).append("12345").newline(); - assertEquals("1234+" + NL + "5" + NL, terminal.getTranscript()); + assertThat(terminal.getTranscript()).isEqualTo("1234+" + NL + "5" + NL); } @Test @@ -52,14 +51,14 @@ public class LineWrappingAnsiTerminalWriterTest { // Lines are only wrapped, once a character is written that cannot fit in the current line, and // not already once the last usable character of a line is used. Hence, in this example, we do // not want to see the continuation character. - assertEquals("1234", terminal.getTranscript()); + assertThat(terminal.getTranscript()).isEqualTo("1234"); } @Test public void testNewlineTranslated() throws IOException { LoggingTerminalWriter terminal = new LoggingTerminalWriter(); (new LineWrappingAnsiTerminalWriter(terminal, 80, '+')).append("foo\nbar\n"); - assertEquals("foo" + NL + "bar" + NL, terminal.getTranscript()); + assertThat(terminal.getTranscript()).isEqualTo("foo" + NL + "bar" + NL); } @Test @@ -72,7 +71,8 @@ public class LineWrappingAnsiTerminalWriterTest { .newline() .append("ABC\nABC") .newline(); - assertEquals("123" + NL + "abc" + NL + "ABC" + NL + "ABC" + NL, terminal.getTranscript()); + assertThat(terminal.getTranscript()) + .isEqualTo("123" + NL + "abc" + NL + "ABC" + NL + "ABC" + NL); } @Test @@ -85,6 +85,6 @@ public class LineWrappingAnsiTerminalWriterTest { .append("fail") .normal() .append("normal"); - assertEquals(OK + "ok" + FAIL + "fail" + NORMAL + "normal", terminal.getTranscript()); + assertThat(terminal.getTranscript()).isEqualTo(OK + "ok" + FAIL + "fail" + NORMAL + "normal"); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/io/OutErrTest.java b/src/test/java/com/google/devtools/build/lib/util/io/OutErrTest.java index 0afcb31dd3..d9f0e17771 100644 --- a/src/test/java/com/google/devtools/build/lib/util/io/OutErrTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/io/OutErrTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.util.io; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import java.io.ByteArrayOutputStream; import org.junit.Test; @@ -38,39 +37,39 @@ public class OutErrTest { @Test public void testPrintsToOut() { outErr.printOut("Hello, world."); - assertEquals("Hello, world.", new String(out.toByteArray())); + assertThat(new String(out.toByteArray())).isEqualTo("Hello, world."); } @Test public void testPrintsToErr() { outErr.printErr("Hello, moon."); - assertEquals("Hello, moon.", new String(err.toByteArray())); + assertThat(new String(err.toByteArray())).isEqualTo("Hello, moon."); } @Test public void testPrintsToOutWithANewline() { outErr.printOutLn("With a newline."); - assertEquals("With a newline.\n", new String(out.toByteArray())); + assertThat(new String(out.toByteArray())).isEqualTo("With a newline.\n"); } @Test - public void testPrintsToErrWithANewline(){ + public void testPrintsToErrWithANewline() { outErr.printErrLn("With a newline."); - assertEquals("With a newline.\n", new String(err.toByteArray())); + assertThat(new String(err.toByteArray())).isEqualTo("With a newline.\n"); } @Test public void testPrintsTwoLinesToOut() { outErr.printOutLn("line 1"); outErr.printOutLn("line 2"); - assertEquals("line 1\nline 2\n", new String(out.toByteArray())); + assertThat(new String(out.toByteArray())).isEqualTo("line 1\nline 2\n"); } @Test public void testPrintsTwoLinesToErr() { outErr.printErrLn("line 1"); outErr.printErrLn("line 2"); - assertEquals("line 1\nline 2\n", new String(err.toByteArray())); + assertThat(new String(err.toByteArray())).isEqualTo("line 1\nline 2\n"); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/io/PositionAwareAnsiTerminalWriterTest.java b/src/test/java/com/google/devtools/build/lib/util/io/PositionAwareAnsiTerminalWriterTest.java index 2aef6ff45e..6444a99162 100644 --- a/src/test/java/com/google/devtools/build/lib/util/io/PositionAwareAnsiTerminalWriterTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/io/PositionAwareAnsiTerminalWriterTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.util.io; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Test; @@ -39,7 +38,7 @@ public class PositionAwareAnsiTerminalWriterTest { terminalWriter.append(sample); assertThat(terminalWriter.getPosition()).isEqualTo(sample.length()); - assertEquals(sample, loggingTerminalWriter.getTranscript()); + assertThat(loggingTerminalWriter.getTranscript()).isEqualTo(sample); } @Test @@ -59,7 +58,7 @@ public class PositionAwareAnsiTerminalWriterTest { assertThat(terminalWriter.getPosition()).isEqualTo(secondLine.length()); terminalWriter.newline(); assertThat(terminalWriter.getPosition()).isEqualTo(0); - assertEquals(firstLine + NL + secondLine + NL, loggingTerminalWriter.getTranscript()); + assertThat(loggingTerminalWriter.getTranscript()).isEqualTo(firstLine + NL + secondLine + NL); } @Test @@ -75,7 +74,7 @@ public class PositionAwareAnsiTerminalWriterTest { assertThat(terminalWriter.getPosition()).isEqualTo(secondLine.length()); terminalWriter.append("\n"); assertThat(terminalWriter.getPosition()).isEqualTo(0); - assertEquals(firstLine + NL + secondLine + NL, loggingTerminalWriter.getTranscript()); + assertThat(loggingTerminalWriter.getTranscript()).isEqualTo(firstLine + NL + secondLine + NL); } @Test @@ -92,9 +91,8 @@ public class PositionAwareAnsiTerminalWriterTest { .append("fail") .normal() .append("normal"); - assertEquals( - "abc" + OK + "ok" + FAIL + "fail" + NORMAL + "normal", - loggingTerminalWriter.getTranscript()); + assertThat(loggingTerminalWriter.getTranscript()) + .isEqualTo("abc" + OK + "ok" + FAIL + "fail" + NORMAL + "normal"); } @Test @@ -109,6 +107,6 @@ public class PositionAwareAnsiTerminalWriterTest { assertThat(terminalWriter.getPosition()).isEqualTo(0); terminalWriter.append(sample); assertThat(terminalWriter.getPosition()).isEqualTo(sample.length()); - assertEquals(FAIL + sample, loggingTerminalWriter.getTranscript()); + assertThat(loggingTerminalWriter.getTranscript()).isEqualTo(FAIL + sample); } } diff --git a/src/test/java/com/google/devtools/build/lib/util/io/RecordingOutErrTest.java b/src/test/java/com/google/devtools/build/lib/util/io/RecordingOutErrTest.java index 435ffb5433..6fa127dfab 100644 --- a/src/test/java/com/google/devtools/build/lib/util/io/RecordingOutErrTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/io/RecordingOutErrTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.util.io; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import java.io.PrintWriter; import org.junit.Test; @@ -47,8 +46,8 @@ public class RecordingOutErrTest { writer.println("Testerr2"); writer.flush(); - assertEquals("Testout1\nTestout2\n", outErr.outAsLatin1()); - assertEquals("Testerr1\nTesterr2\n", outErr.errAsLatin1()); + assertThat(outErr.outAsLatin1()).isEqualTo("Testout1\nTestout2\n"); + assertThat(outErr.errAsLatin1()).isEqualTo("Testerr1\nTesterr2\n"); assertThat(outErr.hasRecordedOutput()).isTrue(); diff --git a/src/test/java/com/google/devtools/build/lib/util/io/StreamDemultiplexerTest.java b/src/test/java/com/google/devtools/build/lib/util/io/StreamDemultiplexerTest.java index ba06bb8917..81409f3277 100644 --- a/src/test/java/com/google/devtools/build/lib/util/io/StreamDemultiplexerTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/io/StreamDemultiplexerTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.util.io; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import java.io.ByteArrayOutputStream; import java.io.OutputStream; @@ -57,7 +56,7 @@ public class StreamDemultiplexerTest { try (final StreamDemultiplexer demux = new StreamDemultiplexer((byte) 1, out)) { demux.write(multiplexed); } - assertEquals("Hello, world.", out.toString("ISO-8859-1")); + assertThat(out.toString("ISO-8859-1")).isEqualTo("Hello, world."); } @Test @@ -66,9 +65,9 @@ public class StreamDemultiplexerTest { try (final StreamDemultiplexer demux = new StreamDemultiplexer((byte) 1, out, err, ctl)) { demux.write(multiplexed); } - assertEquals("out", toAnsi(out)); - assertEquals("err", toAnsi(err)); - assertEquals("ctl", toAnsi(ctl)); + assertThat(toAnsi(out)).isEqualTo("out"); + assertThat(toAnsi(err)).isEqualTo("err"); + assertThat(toAnsi(ctl)).isEqualTo("ctl"); } @Test @@ -77,7 +76,7 @@ public class StreamDemultiplexerTest { try (final StreamDemultiplexer demux = new StreamDemultiplexer((byte) 1, out)) { demux.write(multiplexed); } - assertEquals("just one line", out.toString("ISO-8859-1")); + assertThat(out.toString("ISO-8859-1")).isEqualTo("just one line"); } @Test @@ -87,7 +86,7 @@ public class StreamDemultiplexerTest { OutputStream out = mux.createStdout(); out.write(inAnsi("Hello, world.")); out.flush(); - assertEquals("Hello, world.", toAnsi(this.out)); + assertThat(toAnsi(this.out)).isEqualTo("Hello, world."); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/windows/PathWindowsTest.java b/src/test/java/com/google/devtools/build/lib/windows/PathWindowsTest.java index 47dfb23a84..fd787c4c9a 100644 --- a/src/test/java/com/google/devtools/build/lib/windows/PathWindowsTest.java +++ b/src/test/java/com/google/devtools/build/lib/windows/PathWindowsTest.java @@ -14,8 +14,6 @@ package com.google.devtools.build.lib.windows; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; import com.google.common.base.Function; import com.google.common.base.Predicate; @@ -77,14 +75,14 @@ public class PathWindowsTest { } private void assertAsFragmentWorks(String expected) { - assertEquals(PathFragment.create(expected), filesystem.getPath(expected).asFragment()); + assertThat(filesystem.getPath(expected).asFragment()).isEqualTo(PathFragment.create(expected)); } @Test public void testWindowsPath() { Path p = filesystem.getPath("C:/foo/bar"); - assertEquals("C:/foo/bar", p.getPathString()); - assertEquals("C:/foo/bar", p.toString()); + assertThat(p.getPathString()).isEqualTo("C:/foo/bar"); + assertThat(p.toString()).isEqualTo("C:/foo/bar"); } @Test @@ -99,29 +97,29 @@ public class PathWindowsTest { @Test public void testGetRelativeWithFragmentWindows() { Path dir = filesystem.getPath("C:/first/x"); - assertEquals("C:/first/x/y", dir.getRelative(PathFragment.create("y")).toString()); - assertEquals("C:/first/x/x", dir.getRelative(PathFragment.create("./x")).toString()); - assertEquals("C:/first/y", dir.getRelative(PathFragment.create("../y")).toString()); - assertEquals("C:/first/y", dir.getRelative(PathFragment.create("../y")).toString()); - assertEquals("C:/y", dir.getRelative(PathFragment.create("../../../y")).toString()); + assertThat(dir.getRelative(PathFragment.create("y")).toString()).isEqualTo("C:/first/x/y"); + assertThat(dir.getRelative(PathFragment.create("./x")).toString()).isEqualTo("C:/first/x/x"); + assertThat(dir.getRelative(PathFragment.create("../y")).toString()).isEqualTo("C:/first/y"); + assertThat(dir.getRelative(PathFragment.create("../y")).toString()).isEqualTo("C:/first/y"); + assertThat(dir.getRelative(PathFragment.create("../../../y")).toString()).isEqualTo("C:/y"); } @Test public void testGetRelativeWithAbsoluteFragmentWindows() { Path x = filesystem.getPath("C:/first/x"); - assertEquals("C:/x/y", x.getRelative(PathFragment.create("C:/x/y")).toString()); + assertThat(x.getRelative(PathFragment.create("C:/x/y")).toString()).isEqualTo("C:/x/y"); } @Test public void testGetRelativeWithAbsoluteStringWorksWindows() { Path x = filesystem.getPath("C:/first/x"); - assertEquals("C:/x/y", x.getRelative("C:/x/y").toString()); + assertThat(x.getRelative("C:/x/y").toString()).isEqualTo("C:/x/y"); } @Test public void testParentOfRootIsRootWindows() { - assertSame(root, root.getRelative("..")); - assertSame(root.getRelative("dots"), root.getRelative("broken/../../dots")); + assertThat(root).isSameAs(root.getRelative("..")); + assertThat(root.getRelative("dots")).isSameAs(root.getRelative("broken/../../dots")); } @Test diff --git a/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java b/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java index 697e2ac150..e510cbfacd 100644 --- a/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java +++ b/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java @@ -24,7 +24,6 @@ import static com.google.devtools.build.skyframe.GraphTester.CONCATENATE; import static com.google.devtools.build.skyframe.GraphTester.COPY; import static com.google.devtools.build.skyframe.GraphTester.NODE_TYPE; import static com.google.devtools.build.skyframe.GraphTester.skyKey; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.common.base.Predicates; @@ -1297,7 +1296,8 @@ public class MemoizingEvaluatorTest { } }); // Prime the graph with otherTop, so we can dirty it next build. - assertEquals(new StringValue("otherTop"), tester.evalAndGet(/*keepGoing=*/false, otherTop)); + assertThat(tester.evalAndGet(/*keepGoing=*/ false, otherTop)) + .isEqualTo(new StringValue("otherTop")); // Mark dep1 changed, so otherTop will be dirty and request re-evaluation of dep1. tester.getOrCreate(dep1, /*markAsModified=*/true); SkyKey topKey = GraphTester.toSkyKey("top"); @@ -1631,7 +1631,8 @@ public class MemoizingEvaluatorTest { SkyKey topKey = GraphTester.toSkyKey("top"); tester.set(topKey, new StringValue("initial")); // Put topKey into graph so it will be dirtied on next run. - assertEquals(new StringValue("initial"), tester.evalAndGet(/*keepGoing=*/false, topKey)); + assertThat(tester.evalAndGet(/*keepGoing=*/ false, topKey)) + .isEqualTo(new StringValue("initial")); CountDownLatch slowStart = new CountDownLatch(1); CountDownLatch errorFinish = new CountDownLatch(1); SkyKey errorKey = GraphTester.toSkyKey("error"); @@ -1750,7 +1751,7 @@ public class MemoizingEvaluatorTest { SkyKey leafKey = GraphTester.toSkyKey("leaf"); tester.set(leafKey, new StringValue("leaf")); // Prime the graph by putting leaf in beforehand. - assertEquals(new StringValue("leaf"), tester.evalAndGet(/*keepGoing=*/false, leafKey)); + assertThat(tester.evalAndGet(/*keepGoing=*/ false, leafKey)).isEqualTo(new StringValue("leaf")); SkyKey topKey = GraphTester.toSkyKey("top"); tester.getOrCreate(topKey).addDependency(leafKey).setHasError(true); // Build top -- it has an error. @@ -1799,8 +1800,8 @@ public class MemoizingEvaluatorTest { assertThat(result.get(midKey)).isNull(); assertThat(result.getError().getRootCauses()).containsExactly(errorKey); // In a keepGoing build, midKey should be re-evaluated. - assertEquals("recovered", - ((StringValue) tester.evalAndGet(/*keepGoing=*/true, parentKey)).getValue()); + assertThat(((StringValue) tester.evalAndGet(/*keepGoing=*/ true, parentKey)).getValue()) + .isEqualTo("recovered"); } /** @@ -2216,7 +2217,7 @@ public class MemoizingEvaluatorTest { }); // First build: assert we can evaluate "top". - assertEquals(topValue, tester.evalAndGet(/*keepGoing=*/false, topKey)); + assertThat(tester.evalAndGet(/*keepGoing=*/ false, topKey)).isEqualTo(topValue); // Second build: replace "leaf4" by "leaf5" in leaf2's value. Assert leaf4 is not requested. final SkyKey leaf5 = GraphTester.toSkyKey("leaf5"); @@ -2224,7 +2225,7 @@ public class MemoizingEvaluatorTest { tester.set(leaves.get(2), new StringValue("leaf5")); tester.invalidate(); shouldNotBuildLeaf4.set(true); - assertEquals(topValue, tester.evalAndGet(/*keepGoing=*/false, topKey)); + assertThat(tester.evalAndGet(/*keepGoing=*/ false, topKey)).isEqualTo(topValue); } @Test @@ -2596,7 +2597,8 @@ public class MemoizingEvaluatorTest { } } // Seed the graph. - assertEquals("node0", ((StringValue) tester.evalAndGet(/*keepGoing=*/false, key)).getValue()); + assertThat(((StringValue) tester.evalAndGet(/*keepGoing=*/ false, key)).getValue()) + .isEqualTo("node0"); // Start the dirtying process. tester.set("node0", new StringValue("new")); tester.invalidate(); @@ -2611,7 +2613,8 @@ public class MemoizingEvaluatorTest { // Now delete all the nodes. The node that was going to be dirtied is also deleted, which we // should handle. tester.evaluator.delete(Predicates.<SkyKey>alwaysTrue()); - assertEquals("new", ((StringValue) tester.evalAndGet(/*keepGoing=*/false, key)).getValue()); + assertThat(((StringValue) tester.evalAndGet(/*keepGoing=*/ false, key)).getValue()) + .isEqualTo("new"); } @Test @@ -3452,8 +3455,8 @@ public class MemoizingEvaluatorTest { tester.set(errorKey, new StringValue("biding time")); SkyKey absentParentKey = GraphTester.toSkyKey("absentParent"); tester.getOrCreate(absentParentKey).addDependency(errorKey).setComputedValue(CONCATENATE); - assertEquals(new StringValue("biding time"), - tester.evalAndGet(/*keepGoing=*/false, absentParentKey)); + assertThat(tester.evalAndGet(/*keepGoing=*/ false, absentParentKey)) + .isEqualTo(new StringValue("biding time")); tester.getOrCreate(errorKey, /*markAsModified=*/true).setHasError(true); SkyKey newParent = GraphTester.toSkyKey("newParent"); tester.getOrCreate(newParent).addDependency(errorKey).setComputedValue(CONCATENATE); |