-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement hs-bin@repl test as go bazel test #1645
Merged
Merged
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e85240c
add asterius files into "all_files" filegroup
90e8800
add go_bazel_test for hs-bin repl test
ffcda3e
remove hs-bin repl test from RunTest.hs
b67992b
add creation .bazelrc file with host_platform for integration test
5ce3afa
Fix bazel lint
16e75b3
add integration_test rule, passing nixpgs flag to go_bazel_test to
6bd8095
use //tests:nix config setting instead of creating new one
c71057c
set BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 when running bazel on darwin
4acea62
add windows configuration in bazelrc
b9d4373
add go library for common functions for integration tests implemented as
06562d3
fix bazel linting
47832af
add patch for rules fixes go_bazel_test on Windows:
2113761
fix bazel linter
d13b654
* added macro invocation pulling bazel binaries for all platforms as …
ffd89cc
use bazel.Runfile from rules_go to extract path to bazel binary
3661a87
add BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN for macos-nixpkgs setup
1f5aa2a
add --incompatible_enable_cc_toolchain_resolution for macos nixpkgs
be7de93
add --incompatible_enable_cc_toolchain_resolution flag for all
271f7d8
add TMPDIR=/tmp in mkShell according to
e95934a
clarify a comment regarding picking $HOME value for test
4b598b9
Merge branch 'master' into hsbin-as-go-bazel-test
7aba166
fix bazel linting
2d617f8
update haskell compiler version in integration tests: 8.10.4 -> 8.10.7
9a668e9
apply gofmt to go files
f0c9206
more clear comment on $HOME direcotry choice
fcd70e1
add comment describing patch for rules_go
9003072
use bazel from nixpkgs for integration testing in nix configurations:
f4655fb
added comment on rules_go dependency
5160178
Merge branch 'master' into hsbin-as-go-bazel-test
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") | ||
|
||
def integration_test(name, **kwargs): | ||
test_src = name + ".go" | ||
size = kwargs.pop("size", "medium") | ||
|
||
native.config_setting( | ||
name = "nixpkgs", | ||
values = {"define": "nixpkgs=true"}, | ||
) | ||
|
||
go_bazel_test( | ||
name = name, | ||
srcs = [test_src], | ||
size = size, | ||
rule_files = ["//:distribution"], | ||
args = select({ | ||
":nixpkgs": ["nixpkgs=true"], | ||
"//conditions:default": ["nixpkgs=false"], | ||
}), | ||
**kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package hs_bin_repl_test | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
"github.com/bazelbuild/rules_go/go/tools/bazel_testing" | ||
) | ||
|
||
|
||
|
||
func Workspace() string { | ||
return ` | ||
-- WORKSPACE -- | ||
local_repository( | ||
name = "rules_haskell", | ||
path = "../rules_haskell", | ||
) | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
load("@rules_haskell//haskell:repositories.bzl", "rules_haskell_dependencies") | ||
|
||
rules_haskell_dependencies() | ||
|
||
load("@rules_haskell//haskell:nixpkgs.bzl", "haskell_register_ghc_nixpkgs") | ||
|
||
haskell_register_ghc_nixpkgs( | ||
attribute_path = "haskell.compiler.ghc8104", | ||
repository = "@rules_haskell//nixpkgs:default.nix", | ||
version = "8.10.4", | ||
) | ||
|
||
load("@rules_haskell//haskell:toolchain.bzl", "rules_haskell_toolchains") | ||
|
||
rules_haskell_toolchains(version = "8.10.4") | ||
|
||
load( | ||
"@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", | ||
"nixpkgs_cc_configure", | ||
"nixpkgs_python_configure", | ||
) | ||
|
||
nixpkgs_cc_configure( | ||
name = "nixpkgs_config_cc", | ||
repository = "@rules_haskell//nixpkgs:default.nix", | ||
) | ||
|
||
nixpkgs_python_configure( | ||
repository = "@rules_haskell//nixpkgs:default.nix", | ||
) | ||
|
||
-- BUILD.bazel -- | ||
load( | ||
"@rules_haskell//haskell:defs.bzl", | ||
"haskell_library", | ||
"haskell_test", | ||
) | ||
|
||
load( | ||
"@rules_haskell//haskell:defs.bzl", | ||
"haskell_toolchain_library", | ||
) | ||
|
||
[ | ||
haskell_toolchain_library(name = name) | ||
for name in [ | ||
"base", | ||
] | ||
] | ||
|
||
haskell_library( | ||
name = "QuuxLib", | ||
srcs = ["QuuxLib.hs"], | ||
deps = [":base"], | ||
) | ||
|
||
haskell_test( | ||
name = "hs-bin", | ||
srcs = ["Quux.hs"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
":QuuxLib", | ||
":base", | ||
], | ||
) | ||
|
||
-- Quux.hs -- | ||
module Main (main) where | ||
|
||
import QuuxLib (message) | ||
|
||
main :: IO () | ||
main = putStrLn message | ||
-- QuuxLib.hs -- | ||
module QuuxLib (message) where | ||
|
||
message :: String | ||
message = "Hello GHCi!" | ||
` | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
bazel_testing.TestMain(m, bazel_testing.Args{ | ||
Main: Workspace() + GenerateBazelrc(UseNixpkgs()), | ||
}) | ||
} | ||
|
||
func AssertOutput(t *testing.T, output []byte, expected string) { | ||
if string(output) != expected { | ||
t.Fatalf("output of bazel process is invalid.\nExpected: %v\n, Actual: %v\n", expected, string(output)) | ||
} | ||
} | ||
|
||
func UseNixpkgs() bool { | ||
for _, arg := range os.Args { | ||
if arg == "nixpkgs=true" { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func GenerateBazelrc(use_nixpkgs bool) string { | ||
if use_nixpkgs { | ||
return ` | ||
-- .bazelrc -- | ||
build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host | ||
` | ||
} else { | ||
return "" | ||
} | ||
} | ||
|
||
func BazelOutput(args ...string) ([]byte, error) { | ||
cmd := bazel_testing.BazelCmd(args...) | ||
// It's important value of $HOME to be invariant between different integration test runs | ||
// and to be writable directory for bazel test. Probably TEST_TMPDIR is a valid choice | ||
// but documentation is not clear about it's default value | ||
// cmd.Env = append(cmd.Env, fmt.Sprintf("HOME=%s", os.Getenv("TEST_TMPDIR"))) | ||
cmd.Env = append(cmd.Env, fmt.Sprintf("HOME=%s", os.TempDir())) | ||
stdout := &bytes.Buffer{} | ||
stderr := &bytes.Buffer{} | ||
cmd.Stdout = stdout | ||
cmd.Stderr = stderr | ||
err := cmd.Run() | ||
if eErr, ok := err.(*exec.ExitError); ok { | ||
eErr.Stderr = stderr.Bytes() | ||
err = &bazel_testing.StderrExitError{Err: eErr} | ||
} | ||
fmt.Fprintf(os.Stderr, string(stdout.Bytes())) | ||
fmt.Fprintf(os.Stderr, string(stderr.Bytes())) | ||
return stdout.Bytes(), err | ||
} | ||
|
||
func TestHsBinRepl(t *testing.T) { | ||
out, err := BazelOutput("run", "//:hs-bin@repl", "--", "-ignore-dot-ghci", "-e", ":main") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
AssertOutput(t, out, "Hello GHCi!\n") | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could reuse this
config_setting
based on thesupport_nix
platform constraint. Then you also don't need to introduce the--define=nixpkgs
above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Fixed