paizaでgo test
概要
paizaでgo testやってみた。
サンプルコード
import subprocess
import os
def go():
p_file = 'calc.go'
test_p = """
package main
func Add(l, r int) int {
return l + r
}
"""
with open(p_file, 'w') as f:
f.write(test_p)
c_file = 'calc_test.go'
test_c = """
package main
import "testing"
func TestAdd(t *testing.T) {
var result int
result = Add(1, 2)
if result != 3 {
t.Errorf("add failed. expect:%d, actual:%d", 3, result)
}
t.Logf("result is %d", result)
}
"""
with open(c_file, 'w') as f:
f.write(test_c)
os.system("ls")
os.system("go test calc_test.go calc.go")
if __name__ == '__main__':
go()
成果物
import subprocess
import os
def go():
p_file = 'calc.go'
test_p = """
package main
func Add(l, r int) int {
return l + r
}
"""
with open(p_file, 'w') as f:
f.write(test_p)
c_file = 'calc_test.go'
test_c = """
package main
import "testing"
func TestAdd(t *testing.T) {
var result int
result = Add(1, 2)
if result != 3 {
t.Errorf("add failed. expect:%d, actual:%d", 3, result)
}
t.Logf("result is %d", result)
}
"""
with open(c_file, 'w') as f:
f.write(test_c)
os.system("ls")
os.system("go test calc_test.go calc.go")
if __name__ == '__main__':
go()
以上。
Author And Source
この問題について(paizaでgo test), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/c613970f9f40f103a743著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .