Skip to content

Commit

Permalink
format test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-coding committed Jun 16, 2024
1 parent 5f94e2c commit e3e6346
Show file tree
Hide file tree
Showing 5 changed files with 739 additions and 644 deletions.
131 changes: 73 additions & 58 deletions run_backend_tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3

#
# author : Michael Brockus.  
# contact: <mailto:[email protected]>
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
# author : Michael Brockus.
# contact: <mailto:[email protected]>
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
#
# copyright 2020 The Meson-UI development team
#
Expand All @@ -26,54 +26,58 @@ class TestMesonBackend:
def test_kdevelop_backend(self):
#
# Setting up tmp test directory
source = Path(join_paths('test-cases', 'backends', '01-kdevelop')).resolve()
build = Path(join_paths('test-cases', 'backends', '01-kdevelop', 'builddir')).resolve()
source = Path(join_paths("test-cases", "backends", "01-kdevelop")).resolve()
build = Path(
join_paths("test-cases", "backends", "01-kdevelop", "builddir")
).resolve()

#
# Running Meson command
meson: Meson = Meson(sourcedir=source, builddir=build)

meson.setup(['--backend=ninja'])
meson.setup(["--backend=ninja"])
api = MesonAPI(sourcedir=source, builddir=build)
ide = KDevelopBackend(api)
ide.generator()

#
# Run asserts to check it is working
assert os.path.exists(join_paths(source, 'meson.build'))
assert os.path.exists(join_paths(build, 'build.ninja'))
assert os.path.exists(join_paths(build, 'meson-info', 'intro-projectinfo.json'))
assert os.path.exists(join_paths(build, 'compile_commands.json'))
assert os.path.exists(join_paths(build, 'basic.kdev4'))
assert os.path.exists(join_paths(source, "meson.build"))
assert os.path.exists(join_paths(build, "build.ninja"))
assert os.path.exists(join_paths(build, "meson-info", "intro-projectinfo.json"))
assert os.path.exists(join_paths(build, "compile_commands.json"))
assert os.path.exists(join_paths(build, "basic.kdev4"))

def test_codeblocks_backend(self):
#
# Setting up tmp test directory
source = Path(join_paths('test-cases', 'backends', '02-codeblocks')).resolve()
build = Path(join_paths('test-cases', 'backends', '02-codeblocks', 'builddir')).resolve()
source = Path(join_paths("test-cases", "backends", "02-codeblocks")).resolve()
build = Path(
join_paths("test-cases", "backends", "02-codeblocks", "builddir")
).resolve()

#
# Running Meson command
meson: Meson = Meson(sourcedir=source, builddir=build)

meson.setup(['--backend=ninja'])
meson.setup(["--backend=ninja"])
api = MesonAPI(sourcedir=source, builddir=build)
ide = CodeBlocksBackend(api)
ide.generator()

#
# Run asserts to check it is working
assert os.path.exists(join_paths(source, 'meson.build'))
assert os.path.exists(join_paths(build, 'build.ninja'))
assert os.path.exists(join_paths(build, 'meson-info', 'intro-projectinfo.json'))
assert os.path.exists(join_paths(build, 'compile_commands.json'))
assert os.path.exists(join_paths(build, 'basic.cbp'))
assert os.path.exists(join_paths(source, "meson.build"))
assert os.path.exists(join_paths(build, "build.ninja"))
assert os.path.exists(join_paths(build, "meson-info", "intro-projectinfo.json"))
assert os.path.exists(join_paths(build, "compile_commands.json"))
assert os.path.exists(join_paths(build, "basic.cbp"))

def test_qtcreator_backend(self):
#
# Setting up tmp test directory
source = Path(join_paths('test-cases', 'backends', '03-qtcreator'))
build = Path(join_paths('test-cases', 'backends', '03-qtcreator', 'builddir'))
source = Path(join_paths("test-cases", "backends", "03-qtcreator"))
build = Path(join_paths("test-cases", "backends", "03-qtcreator", "builddir"))

#
# Running Meson command
Expand All @@ -86,34 +90,36 @@ def test_qtcreator_backend(self):

#
# Run asserts to check it is working
assert os.path.exists(join_paths(source, 'meson.build'))
assert os.path.exists(join_paths(build, 'build.ninja'))
assert os.path.exists(join_paths(build, 'meson-info', 'intro-projectinfo.json'))
assert os.path.exists(join_paths(build, 'compile_commands.json'))
assert os.path.exists(join_paths(build, 'basic.creator'))
assert os.path.exists(join_paths(build, 'basic.includes'))
assert os.path.exists(join_paths(build, 'basic.files'))
assert os.path.exists(join_paths(source, "meson.build"))
assert os.path.exists(join_paths(build, "build.ninja"))
assert os.path.exists(join_paths(build, "meson-info", "intro-projectinfo.json"))
assert os.path.exists(join_paths(build, "compile_commands.json"))
assert os.path.exists(join_paths(build, "basic.creator"))
assert os.path.exists(join_paths(build, "basic.includes"))
assert os.path.exists(join_paths(build, "basic.files"))

def test_gnome_builder_backend(self):
#
# Setting up tmp test directory
source = Path(join_paths('test-cases', 'backends', '04-gnome')).resolve()
build = Path(join_paths('test-cases', 'backends', '04-gnome', 'builddir')).resolve()
source = Path(join_paths("test-cases", "backends", "04-gnome")).resolve()
build = Path(
join_paths("test-cases", "backends", "04-gnome", "builddir")
).resolve()

#
# Running Meson command
meson: Meson = Meson(sourcedir=source, builddir=build)

meson.setup(['--backend=ninja'])
meson.setup(["--backend=ninja"])
api = MesonAPI(sourcedir=source, builddir=build)
ide = GNOMEBuilderBackend(api)
ide.generator()

#
# Run asserts to check it is working
assert os.path.exists(join_paths(source, 'meson.build'))
assert os.path.exists(join_paths(build, 'build.ninja'))
assert os.path.exists(join_paths(build, 'compile_commands.json'))
assert os.path.exists(join_paths(source, "meson.build"))
assert os.path.exists(join_paths(build, "build.ninja"))
assert os.path.exists(join_paths(build, "compile_commands.json"))

def test_ninja_backend(self, tmpdir):
#
Expand All @@ -124,18 +130,21 @@ def test_ninja_backend(self, tmpdir):

#
# Running Meson command
meson: Meson = Meson(sourcedir=tmpdir, builddir=(tmpdir / 'builddir'))
meson: Meson = Meson(sourcedir=tmpdir, builddir=(tmpdir / "builddir"))

meson.init(['--language=c'])
meson.setup(['--backend=ninja'])
meson.init(["--language=c"])
meson.setup(["--backend=ninja"])

#
# Run asserts to check it is working
assert tmpdir.join('meson.build').ensure()
assert tmpdir.join('builddir', 'build.ninja').ensure()
assert tmpdir.join('builddir', 'compile_commands.json').ensure()

@pytest.mark.skipif(not OSUtility.is_osx(), reason='Skipping because Xcode backend only works on OSX systems')
assert tmpdir.join("meson.build").ensure()
assert tmpdir.join("builddir", "build.ninja").ensure()
assert tmpdir.join("builddir", "compile_commands.json").ensure()

@pytest.mark.skipif(
not OSUtility.is_osx(),
reason="Skipping because Xcode backend only works on OSX systems",
)
def test_xcode_backend(self, tmpdir):
#
# Setting up tmp test directory
Expand All @@ -145,21 +154,26 @@ def test_xcode_backend(self, tmpdir):

#
# Running Meson command
meson: Meson = Meson(sourcedir=tmpdir, builddir=(tmpdir / 'builddir'))
meson: Meson = Meson(sourcedir=tmpdir, builddir=(tmpdir / "builddir"))

meson.init(['--language=c', '--type=executable'])
meson.setup(['--backend=xcode'])
meson.init(["--language=c", "--type=executable"])
meson.setup(["--backend=xcode"])
meson.compile()
meson.test()

#
# Run asserts to check it is working
assert tmpdir.join('meson.build').ensure()
assert tmpdir.join('builddir', 'build.ninja').ensure()
assert tmpdir.join('builddir', 'compile_commands.json').ensure()
assert tmpdir.join('builddir', 'test-prog.xcodeproj', 'project.pbxproj').ensure()

@pytest.mark.skipif(not OSUtility.is_windows(), reason='Skipping because Visual Studio backend only works on Windows')
assert tmpdir.join("meson.build").ensure()
assert tmpdir.join("builddir", "build.ninja").ensure()
assert tmpdir.join("builddir", "compile_commands.json").ensure()
assert tmpdir.join(
"builddir", "test-prog.xcodeproj", "project.pbxproj"
).ensure()

@pytest.mark.skipif(
not OSUtility.is_windows(),
reason="Skipping because Visual Studio backend only works on Windows",
)
def test_vs_backend(self, tmpdir):
#
# Setting up tmp test directory
Expand All @@ -169,15 +183,16 @@ def test_vs_backend(self, tmpdir):

#
# Running Meson command
meson: Meson = Meson(sourcedir=tmpdir, builddir=(tmpdir / 'builddir'))
meson: Meson = Meson(sourcedir=tmpdir, builddir=(tmpdir / "builddir"))

meson.init(['--language=c'])
meson.setup(['--backend=vs'])
meson.init(["--language=c"])
meson.setup(["--backend=vs"])

#
# Run asserts to check it is working
assert tmpdir.join('meson.build').ensure()
assert tmpdir.join('builddir', 'build.ninja').ensure()
assert tmpdir.join('builddir', 'compile_commands.json').ensure()
assert tmpdir.join("meson.build").ensure()
assert tmpdir.join("builddir", "build.ninja").ensure()
assert tmpdir.join("builddir", "compile_commands.json").ensure()


#TestMesonBackend().test_codeblocks_backend()
# TestMesonBackend().test_codeblocks_backend()
42 changes: 23 additions & 19 deletions run_mesonui_tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3

#
# author : Michael Brockus.  
# contact: <mailto:[email protected]>
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
# author : Michael Brockus.
# contact: <mailto:[email protected]>
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
#
# copyright 2020 The Meson-UI development team
#
Expand Down Expand Up @@ -34,10 +34,10 @@ def test_enter_values(self, qtbot, tmpdir):
qtbot.keyClicks(activity.project_sourcedir, str(tmpdir))

activity.project_builddir.clear()
qtbot.keyClicks(activity.project_builddir, str((tmpdir / 'builddir')))
qtbot.keyClicks(activity.project_builddir, str((tmpdir / "builddir")))

assert activity.project_sourcedir.text() == str(tmpdir)
assert activity.project_builddir.text() == str(tmpdir / 'builddir')
assert activity.project_builddir.text() == str(tmpdir / "builddir")

def test_enter_clear(self, qtbot, tmpdir):
activity = MainActivity(MainModel())
Expand All @@ -47,15 +47,15 @@ def test_enter_clear(self, qtbot, tmpdir):
qtbot.keyClicks(activity.project_sourcedir, str(tmpdir))

activity.project_builddir.clear()
qtbot.keyClicks(activity.project_builddir, str((tmpdir / 'builddir')))
qtbot.keyClicks(activity.project_builddir, str((tmpdir / "builddir")))

assert activity.project_sourcedir.text() == str(tmpdir)
assert activity.project_builddir.text() == str(tmpdir / 'builddir')
assert activity.project_builddir.text() == str(tmpdir / "builddir")

qtbot.mouseClick(activity.control_push_clear_sourcedir, Qt.LeftButton)

assert activity.project_sourcedir.text() == ''
assert activity.project_builddir.text() == ''
assert activity.project_sourcedir.text() == ""
assert activity.project_builddir.text() == ""


class TestSetupActivity:
Expand All @@ -72,10 +72,12 @@ def test_do_setup_prog(self, qtbot, tmpdir):

model = MainModel()
model.buildsystem().meson().sourcedir = tmpdir
model.buildsystem().meson().builddir = (tmpdir / 'builddir')
model.buildsystem().meson().builddir = tmpdir / "builddir"
model.buildsystem().meson().init()

setup_view: SetupActivity = SetupActivity(OutputConsole(MainActivity(model)), model)
setup_view: SetupActivity = SetupActivity(
OutputConsole(MainActivity(model)), model
)
qtbot.addWidget(setup_view)

qtbot.mouseClick(setup_view.control_push_do_setup, Qt.LeftButton)
Expand All @@ -84,9 +86,9 @@ def test_do_setup_prog(self, qtbot, tmpdir):

#
# Run asserts to check it is working
assert tmpdir.join('meson.build').ensure()
assert tmpdir.join('builddir', 'build.ninja').ensure()
assert tmpdir.join('builddir', 'compile_commands.json').ensure()
assert tmpdir.join("meson.build").ensure()
assert tmpdir.join("builddir", "build.ninja").ensure()
assert tmpdir.join("builddir", "compile_commands.json").ensure()

def test_no_setup_prog(self, qtbot):
setup_view: SetupActivity = SetupActivity(None, MainModel())
Expand All @@ -109,19 +111,21 @@ def test_do_configure_prog(self, qtbot, tmpdir):

model = MainModel()
model.buildsystem().meson().sourcedir = tmpdir
model.buildsystem().meson().builddir = (tmpdir / 'builddir')
model.buildsystem().meson().builddir = tmpdir / "builddir"
model.buildsystem().meson().init()

setup_view: ConfigureActivity = ConfigureActivity(OutputConsole(MainActivity(MainModel())), model)
setup_view: ConfigureActivity = ConfigureActivity(
OutputConsole(MainActivity(MainModel())), model
)
qtbot.addWidget(setup_view)

qtbot.mouseClick(setup_view.control_push_do_setup, Qt.LeftButton)

#
# Run asserts to check it is working
assert tmpdir.join('meson.build').ensure()
assert tmpdir.join('builddir', 'build.ninja').ensure()
assert tmpdir.join('builddir', 'compile_commands.json').ensure()
assert tmpdir.join("meson.build").ensure()
assert tmpdir.join("builddir", "build.ninja").ensure()
assert tmpdir.join("builddir", "compile_commands.json").ensure()

def test_no_setup_prog(self, qtbot):
setup_view: ConfigureActivity = ConfigureActivity(None, MainModel())
Expand Down
Loading

0 comments on commit e3e6346

Please sign in to comment.