<commit_before>/*
 * Copyright 2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.nativeplatform.tasks

import org.gradle.nativeplatform.fixtures.AbstractInstalledToolChainIntegrationSpec
import org.gradle.nativeplatform.fixtures.NativeBinaryFixture
import org.gradle.nativeplatform.fixtures.RequiresInstalledToolChain
import org.gradle.nativeplatform.fixtures.ToolChainRequirement
import org.gradle.nativeplatform.fixtures.app.IncrementalCppStaleCompileOutputApp
import org.gradle.nativeplatform.fixtures.app.SourceElement
import org.gradle.util.Requires
import org.gradle.util.TestPrecondition

@Requires(TestPrecondition.NOT_UNKNOWN_OS)
@RequiresInstalledToolChain(ToolChainRequirement.GCC_COMPATIBLE)
class StripSymbolsIntegrationTest extends AbstractInstalledToolChainIntegrationSpec {
    def app = new IncrementalCppStaleCompileOutputApp()

    def setup() {
        settingsFile << "rootProject.name = 'app'"
        app.writeToProject(testDirectory)
        buildFile << """
            plugins {
                id 'cpp-application'
            }
            
            task stripSymbolsDebug(type: StripSymbols) { strip ->
                project.application.binaries.get { !it.optimized }.configure {
                    def linkDebug = linkTask.get()
                    strip.toolChain = linkDebug.toolChain
                    strip.targetPlatform = linkDebug.targetPlatform
                    strip.binaryFile.set linkDebug.binaryFile
                }
                outputFile.set file("build/stripped")
            }
        """
    }

    def "strips symbols from binary"() {
        when:
        succeeds ":stripSymbolsDebug"

        then:
        executedAndNotSkipped":stripSymbolsDebug"
        fixture("build/exe/main/debug/app").assertHasDebugSymbolsFor(withoutHeaders(app.original))
        fixture("build/stripped").assertDoesNotHaveDebugSymbolsFor(withoutHeaders(app.original))
    }

    def "strip is skipped when there are no changes"() {
        when:
        succeeds ":stripSymbolsDebug"

        then:
        executedAndNotSkipped":stripSymbolsDebug"

        when:
        succeeds ":stripSymbolsDebug"

        then:
        skipped":stripSymbolsDebug"
        fixture("build/stripped").assertDoesNotHaveDebugSymbolsFor(withoutHeaders(app.original))
    }

    def "strip is re-executed when changes are made"() {
        when:
        succeeds ":stripSymbolsDebug"

        then:
        executedAndNotSkipped":stripSymbolsDebug"

        when:
        app.applyChangesToProject(testDirectory)
        succeeds ":stripSymbolsDebug"

        then:
        executedAndNotSkipped":stripSymbolsDebug"
        fixture("build/stripped").assertDoesNotHaveDebugSymbolsFor(withoutHeaders(app.alternate))
    }

    NativeBinaryFixture fixture(String path) {
        return new NativeBinaryFixture(file(path), toolChain)
    }

    List<String> withoutHeaders(SourceElement sourceElement) {
        return sourceElement.sourceFileNames.findAll { !it.endsWith(".h") }
    }
}<commit_msg>Fixed int test to look for the correct binary file on Windows.<commit_after>/*
 * Copyright 2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.nativeplatform.tasks

import org.gradle.nativeplatform.fixtures.AbstractInstalledToolChainIntegrationSpec
import org.gradle.nativeplatform.fixtures.NativeBinaryFixture
import org.gradle.nativeplatform.fixtures.RequiresInstalledToolChain
import org.gradle.nativeplatform.fixtures.ToolChainRequirement
import org.gradle.nativeplatform.fixtures.app.IncrementalCppStaleCompileOutputApp
import org.gradle.nativeplatform.fixtures.app.SourceElement
import org.gradle.util.Requires
import org.gradle.util.TestPrecondition

@Requires(TestPrecondition.NOT_UNKNOWN_OS)
@RequiresInstalledToolChain(ToolChainRequirement.GCC_COMPATIBLE)
class StripSymbolsIntegrationTest extends AbstractInstalledToolChainIntegrationSpec {
    def app = new IncrementalCppStaleCompileOutputApp()

    def setup() {
        settingsFile << "rootProject.name = 'app'"
        app.writeToProject(testDirectory)
        buildFile << """
            plugins {
                id 'cpp-application'
            }
            
            task stripSymbolsDebug(type: StripSymbols) { strip ->
                project.application.binaries.get { !it.optimized }.configure {
                    def linkDebug = linkTask.get()
                    strip.toolChain = linkDebug.toolChain
                    strip.targetPlatform = linkDebug.targetPlatform
                    strip.binaryFile.set linkDebug.binaryFile
                }
                outputFile.set file("build/stripped")
            }
        """
    }

    def "strips symbols from binary"() {
        when:
        succeeds ":stripSymbolsDebug"

        then:
        executedAndNotSkipped":stripSymbolsDebug"
        executable("build/exe/main/debug/app").assertHasDebugSymbolsFor(withoutHeaders(app.original))
        binary("build/stripped").assertDoesNotHaveDebugSymbolsFor(withoutHeaders(app.original))
    }

    def "strip is skipped when there are no changes"() {
        when:
        succeeds ":stripSymbolsDebug"

        then:
        executedAndNotSkipped":stripSymbolsDebug"

        when:
        succeeds ":stripSymbolsDebug"

        then:
        skipped":stripSymbolsDebug"
        binary("build/stripped").assertDoesNotHaveDebugSymbolsFor(withoutHeaders(app.original))
    }

    def "strip is re-executed when changes are made"() {
        when:
        succeeds ":stripSymbolsDebug"

        then:
        executedAndNotSkipped":stripSymbolsDebug"

        when:
        app.applyChangesToProject(testDirectory)
        succeeds ":stripSymbolsDebug"

        then:
        executedAndNotSkipped":stripSymbolsDebug"
        binary("build/stripped").assertDoesNotHaveDebugSymbolsFor(withoutHeaders(app.alternate))
    }

    NativeBinaryFixture binary(String path) {
        return new NativeBinaryFixture(file(path), toolChain)
    }

    List<String> withoutHeaders(SourceElement sourceElement) {
        return sourceElement.sourceFileNames.findAll { !it.endsWith(".h") }
    }
}
{'fraction_non_alphanumeric': 0.08091286307053942, 'fraction_numerical': 0.0022130013831258644, 'mean_word_length': 3.055524397083567, 'pattern_counts': {'":': 20, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '382912', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1887, 'n_words': 425}