コード例 #1
0
func TestExternalIncludeReplacerPragmaToInclude(t *testing.T) {
	context := make(map[string]interface{})
	context[constants.CTX_GCC_MINUS_E_SOURCE] = sourceWithPragmas
	context[constants.CTX_INCLUDES] = []string{"/tmp/test184599776/sketch/config.h", "/tmp/test184599776/sketch/includes/de bug.h", "Bridge.h"}

	replacer := builder.ExternalIncludeReplacer{SourceKey: constants.CTX_GCC_MINUS_E_SOURCE, TargetKey: constants.CTX_GCC_MINUS_E_SOURCE, From: "#pragma ___MY_INCLUDE___ ", To: "#include "}
	err := replacer.Run(context)
	NoError(t, err)

	require.Nil(t, context[constants.CTX_SOURCE])
	require.Equal(t, sourceWithIncludes, context[constants.CTX_GCC_MINUS_E_SOURCE].(string))
}
コード例 #2
0
func TestExternalIncludeReplacerPragmaToInclude(t *testing.T) {
	ctx := &types.Context{}
	ctx.SourceGccMinusE = sourceWithPragmas
	ctx.Includes = []string{"/tmp/test184599776/sketch/config.h", "/tmp/test184599776/sketch/includes/de bug.h", "Bridge.h"}

	replacer := builder.ExternalIncludeReplacer{Source: &ctx.SourceGccMinusE, Target: &ctx.SourceGccMinusE, From: "#pragma ___MY_INCLUDE___ ", To: "#include "}
	err := replacer.Run(ctx)
	NoError(t, err)

	require.Empty(t, ctx.Source)
	require.Equal(t, sourceWithIncludes, ctx.SourceGccMinusE)
}