Home | History | Annotate | Download | only in test
      1 // Copyright 2013 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 // Test that the #cgo CFLAGS directive works,
      6 // with and without platform filters.
      7 // See https://golang.org/issue/5224 for details.
      8 package cgotest
      9 
     10 /*
     11 #cgo CFLAGS: -DCOMMON_VALUE=123
     12 #cgo windows CFLAGS: -DIS_WINDOWS=1
     13 #cgo !windows CFLAGS: -DIS_WINDOWS=0
     14 int common = COMMON_VALUE;
     15 int is_windows = IS_WINDOWS;
     16 */
     17 import "C"
     18 
     19 import (
     20 	"runtime"
     21 	"testing"
     22 )
     23 
     24 func testCflags(t *testing.T) {
     25 	is_windows := C.is_windows == 1
     26 	if is_windows != (runtime.GOOS == "windows") {
     27 		t.Errorf("is_windows: %v, runtime.GOOS: %s", is_windows, runtime.GOOS)
     28 	}
     29 	if C.common != 123 {
     30 		t.Errorf("common: %v (expected 123)", C.common)
     31 	}
     32 }
     33